Search in sources :

Example 26 with PipelineRenderingContext

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

the class AddPipelineNodeProducer method createNode.

@Override
public PipelineNode createNode(JsonValue data, ObjectMap<String, Array<String>> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = outputTypes.get("output");
    final Object resultValue = createDefaultValue(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put("output", resultOutput);
    return new AbstractPipelineNode(result) {

        private Array<FieldOutput<?>> inputs;

        @Override
        public void setInputs(ObjectMap<String, Array<FieldOutput<?>>> inputs) {
            this.inputs = inputs.get("inputs");
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            Object returnValue = resetDefaultValue(resultType, resultValue);
            for (FieldOutput<?> input : inputs) {
                Object value = input.getValue();
                returnValue = add(returnValue, value);
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : Array(com.badlogic.gdx.utils.Array) AbstractPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.AbstractPipelineNode) ObjectMap(com.badlogic.gdx.utils.ObjectMap) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 27 with PipelineRenderingContext

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

the class TwoParamMathFunctionPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String resultType = inputTypes.get(param1);
    final Object resultValue = createResult(resultType);
    final ObjectMap<String, PipelineNode.FieldOutput<?>> result = new ObjectMap<>();
    final DefaultFieldOutput resultOutput = new DefaultFieldOutput(resultType);
    result.put(outputName, resultOutput);
    return new SingleInputsPipelineNode(result) {

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            FieldOutput<?> aFunction = inputs.get(param1);
            FieldOutput<?> bFunction = inputs.get(param2);
            Object a = aFunction.getValue();
            Object b = bFunction.getValue();
            Object returnValue;
            if (resultType.equals(PipelineFieldType.Float)) {
                returnValue = executeFunction(a, b, 0);
            } else if (resultType.equals(PipelineFieldType.Vector2)) {
                returnValue = ((Vector2) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1));
            } else if (resultType.equals(PipelineFieldType.Vector3)) {
                returnValue = ((Vector3) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2));
            } else {
                returnValue = ((Color) resultValue).set(executeFunction(a, b, 0), executeFunction(a, b, 1), executeFunction(a, b, 2), executeFunction(a, b, 3));
            }
            resultOutput.setValue(returnValue);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Vector2(com.badlogic.gdx.math.Vector2) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput) SingleInputsPipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) DefaultFieldOutput(com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)

Example 28 with PipelineRenderingContext

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

the class ScreenShaderRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderContextImpl shaderContext = new ShaderContextImpl(pluginPrivateDataSource);
    final Array<ScreenGraphShader> shaderArray = new Array<>();
    final JsonValue shaderDefinitions = data.get("shaders");
    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 TimeProvider timeProvider;

        private FullScreenRender fullScreenRender;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            fullScreenRender = pipelineDataProvider.getFullScreenRender();
            timeProvider = pipelineDataProvider.getTimeProvider();
            GraphScreenShadersImpl graphScreenShaders = pipelineDataProvider.getPrivatePluginData(GraphScreenShadersImpl.class);
            for (JsonValue shaderDefinition : shaderDefinitions) {
                JsonValue shaderGraph = shaderDefinition.get("shader");
                String tag = shaderDefinition.getString("tag");
                Gdx.app.debug("Shader", "Building shader with tag: " + tag);
                final ScreenGraphShader shader = GraphLoader.loadGraph(shaderGraph, new ScreenShaderLoaderCallback(tag, pipelineDataProvider.getWhitePixel().texture, configurations), PropertyLocation.Global_Uniform);
                shaderArray.add(shader);
            }
            for (ScreenGraphShader shader : shaderArray) {
                graphScreenShaders.registerTag(shader.getTag(), shader);
            }
        }

        private boolean needsDepth() {
            for (ScreenGraphShader shader : shaderArray) {
                if (shader.isUsingDepthTexture())
                    return true;
            }
            return false;
        }

        private boolean isRequiringSceneColor() {
            for (ScreenGraphShader shader : shaderArray) {
                if (shader.isUsingColorTexture())
                    return true;
            }
            return false;
        }

        @Override
        public void processPipelineRequirements(PipelineRequirements pipelineRequirements) {
            if (needsDepth())
                pipelineRequirements.setRequiringDepthTexture();
        }

        @Override
        public void executeNode(PipelineRenderingContext pipelineRenderingContext, PipelineRequirementsCallback pipelineRequirementsCallback) {
            final PipelineNode.FieldOutput<Boolean> processorEnabled = (PipelineNode.FieldOutput<Boolean>) inputs.get("enabled");
            final PipelineNode.FieldOutput<Camera> cameraInput = (PipelineNode.FieldOutput<Camera>) inputs.get("camera");
            final PipelineNode.FieldOutput<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            if (enabled) {
                boolean usesDepth = needsDepth();
                boolean needsSceneColor = isRequiringSceneColor();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                if (usesDepth) {
                    renderPipeline.enrichWithDepthBuffer(currentBuffer);
                }
                if (cameraInput != null) {
                    Camera camera = cameraInput.getValue();
                    shaderContext.setCamera(camera);
                }
                shaderContext.setTimeProvider(timeProvider);
                shaderContext.setRenderWidth(currentBuffer.getWidth());
                shaderContext.setRenderHeight(currentBuffer.getHeight());
                RenderPipelineBuffer sceneColorBuffer = null;
                if (needsSceneColor) {
                    sceneColorBuffer = setupColorTexture(renderPipeline, currentBuffer, pipelineRenderingContext);
                }
                currentBuffer.beginColor();
                for (ScreenGraphShader shader : shaderArray) {
                    shaderContext.setGlobalPropertyContainer(shader.getPropertyContainer());
                    shader.begin(shaderContext, pipelineRenderingContext.getRenderContext());
                    shader.render(shaderContext, fullScreenRender);
                    shader.end();
                }
                currentBuffer.endColor();
                if (sceneColorBuffer != null)
                    renderPipeline.returnFrameBuffer(sceneColorBuffer);
            }
            output.setValue(renderPipeline);
        }

        private RenderPipelineBuffer setupColorTexture(final RenderPipeline renderPipeline, final RenderPipelineBuffer currentBuffer, PipelineRenderingContext pipelineRenderingContext) {
            RenderPipelineBuffer sceneColorBuffer = renderPipeline.getNewFrameBuffer(currentBuffer, Color.BLACK);
            shaderContext.setColorTexture(sceneColorBuffer.getColorBufferTexture());
            renderPipeline.drawTexture(currentBuffer, sceneColorBuffer, pipelineRenderingContext, fullScreenRender);
            return sceneColorBuffer;
        }

        @Override
        public void dispose() {
            for (ScreenGraphShader shader : shaderArray) {
                shader.dispose();
            }
        }
    };
}
Also used : ShaderContextImpl(com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl) FullScreenRender(com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Camera(com.badlogic.gdx.graphics.Camera) TimeProvider(com.gempukku.libgdx.graph.time.TimeProvider) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) JsonValue(com.badlogic.gdx.utils.JsonValue) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) Array(com.badlogic.gdx.utils.Array) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 29 with PipelineRenderingContext

use of com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext 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

PipelineRenderingContext (com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext)29 ObjectMap (com.badlogic.gdx.utils.ObjectMap)26 RenderPipeline (com.gempukku.libgdx.graph.pipeline.RenderPipeline)14 RenderPipelineBuffer (com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer)13 Vector2 (com.badlogic.gdx.math.Vector2)12 DefaultFieldOutput (com.gempukku.libgdx.graph.pipeline.producer.node.DefaultFieldOutput)12 SingleInputsPipelineNode (com.gempukku.libgdx.graph.pipeline.producer.node.SingleInputsPipelineNode)10 Camera (com.badlogic.gdx.graphics.Camera)8 FullScreenRender (com.gempukku.libgdx.graph.pipeline.producer.FullScreenRender)8 Vector3 (com.badlogic.gdx.math.Vector3)6 Array (com.badlogic.gdx.utils.Array)6 Color (com.badlogic.gdx.graphics.Color)5 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)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 RenderCallback (com.gempukku.libgdx.graph.plugin.callback.RenderCallback)4 TimeProvider (com.gempukku.libgdx.graph.time.TimeProvider)4 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)3 Map (com.badlogic.gdx.maps.Map)3