Search in sources :

Example 21 with RenderPipelineBuffer

use of com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer in project gdx-graph by MarcinSc.

the class UIRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String stageId = data.getString("id", "");
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput<RenderPipeline> output = new DefaultFieldOutput<>(PipelineFieldType.RenderPipeline);
    result.put("output", output);
    return new SingleInputsPipelineNode(result) {

        private UIPluginPrivateData uiPluginData;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            uiPluginData = pipelineDataProvider.getPrivatePluginData(UIPluginPrivateData.class);
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            final FieldOutput<Vector2> screenSizeInput = (FieldOutput<Vector2>) inputs.get("size");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            Stage stage = uiPluginData.getStage(stageId);
            if (enabled && stage != null) {
                // Sadly need to switch off (and then on) the RenderContext
                pipelineRenderingContext.getRenderContext().end();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                int width = screenSizeInput != null ? MathUtils.round(screenSizeInput.getValue().x) : currentBuffer.getWidth();
                int height = screenSizeInput != null ? MathUtils.round(screenSizeInput.getValue().y) : currentBuffer.getHeight();
                int screenWidth = stage.getViewport().getScreenWidth();
                int screenHeight = stage.getViewport().getScreenHeight();
                if (screenWidth != width || screenHeight != height)
                    stage.getViewport().update(width, height, true);
                currentBuffer.beginColor();
                stage.draw();
                currentBuffer.endColor();
                pipelineRenderingContext.getRenderContext().begin();
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) Stage(com.badlogic.gdx.scenes.scene2d.Stage) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Aggregations

RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)21 ObjectMap (com.badlogic.gdx.utils.ObjectMap)14 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)13 PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)13 Camera (com.badlogic.gdx.graphics.Camera)8 FullScreenRender (com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender)8 Array (com.badlogic.gdx.utils.Array)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)4 Vector2 (com.badlogic.gdx.math.Vector2)4 JsonValue (com.badlogic.gdx.utils.JsonValue)4 OpenGLContext (com.gempukku.libgdx.graph.libgdx.context.OpenGLContext)4 ShaderContextImpl (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl)4 TimeProvider (com.gempukku.libgdx.graph.time.TimeProvider)4 Map (com.badlogic.gdx.maps.Map)3 MapRenderer (com.badlogic.gdx.maps.MapRenderer)3 MapsPluginPrivateData (com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData)3 RenderOrder (com.gempukku.libgdx.graph.pipeline.RenderOrder)2 Lighting3DEnvironment (com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment)2 GraphModelsImpl (com.gempukku.libgdx.graph.plugin.models.impl.GraphModelsImpl)2