Search in sources :

Example 1 with PipelineRenderingContext

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

the class Episode3Scene method loadPipelineRenderer.

private PipelineRenderer loadPipelineRenderer() {
    PipelineRenderer pipelineRenderer = PipelineLoader.loadPipelineRenderer(Gdx.files.local("episodes/episode3.json"), timeKeeper);
    pipelineRenderer.getPluginData(UIPluginPublicData.class).setStage("", stage);
    pipelineRenderer.getPluginData(RenderCallbackPublicData.class).setRenderCallback("Callback", new RenderCallback() {

        @Override
        public void renderCallback(RenderPipeline renderPipeline, PipelineDataProvider pipelineDataProvider, PipelineRenderingContext pipelineRenderingContext, PipelineNode.PipelineRequirementsCallback pipelineRequirementsCallback) {
            RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
            int width = currentBuffer.getWidth();
            int height = currentBuffer.getHeight();
            float viewportWidth = camera.viewportWidth;
            float viewportHeight = camera.viewportHeight;
            if (width != viewportWidth || height != viewportHeight) {
                camera.viewportWidth = width;
                camera.viewportHeight = height;
                camera.update();
            }
            currentBuffer.beginColor();
            modelBatch.begin(camera);
            modelBatch.render(renderableProviders, environment);
            modelBatch.end();
            currentBuffer.endColor();
        }
    });
    return pipelineRenderer;
}
Also used : UIPluginPublicData(com.gempukku.libgdx.graph.plugin.ui.UIPluginPublicData) PipelineDataProvider(com.gempukku.libgdx.graph.pipeline.producer.node.PipelineDataProvider) RenderCallbackPublicData(com.gempukku.libgdx.graph.plugin.callback.RenderCallbackPublicData) RenderCallback(com.gempukku.libgdx.graph.plugin.callback.RenderCallback) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) PipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.PipelineNode)

Example 2 with PipelineRenderingContext

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

the class Episode2Scene method loadPipelineRenderer.

private PipelineRenderer loadPipelineRenderer() {
    PipelineRenderer pipelineRenderer = PipelineLoader.loadPipelineRenderer(Gdx.files.local("episodes/episode2.json"), timeKeeper);
    pipelineRenderer.getPluginData(UIPluginPublicData.class).setStage("", stage);
    pipelineRenderer.getPluginData(RenderCallbackPublicData.class).setRenderCallback("Callback", new RenderCallback() {

        @Override
        public void renderCallback(RenderPipeline renderPipeline, PipelineDataProvider pipelineDataProvider, PipelineRenderingContext pipelineRenderingContext, PipelineNode.PipelineRequirementsCallback pipelineRequirementsCallback) {
            RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
            int width = currentBuffer.getWidth();
            int height = currentBuffer.getHeight();
            float viewportWidth = camera.viewportWidth;
            float viewportHeight = camera.viewportHeight;
            if (width != viewportWidth || height != viewportHeight) {
                camera.viewportWidth = width;
                camera.viewportHeight = height;
                camera.update();
            }
            currentBuffer.beginColor();
            modelBatch.begin(camera);
            modelBatch.render(renderableProviders, environment);
            modelBatch.end();
            currentBuffer.endColor();
        }
    });
    return pipelineRenderer;
}
Also used : UIPluginPublicData(com.gempukku.libgdx.graph.plugin.ui.UIPluginPublicData) PipelineDataProvider(com.gempukku.libgdx.graph.pipeline.producer.node.PipelineDataProvider) RenderCallbackPublicData(com.gempukku.libgdx.graph.plugin.callback.RenderCallbackPublicData) RenderCallback(com.gempukku.libgdx.graph.plugin.callback.RenderCallback) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) PipelineNode(com.gempukku.libgdx.graph.pipeline.producer.node.PipelineNode)

Example 3 with PipelineRenderingContext

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

the class ShadowShaderRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final ShaderContextImpl shaderContext = new ShaderContextImpl(pluginPrivateDataSource);
    final ObjectMap<String, GraphShader> shaders = new ObjectMap<>();
    final Array<String> allShaderTags = new Array<>();
    final JsonValue shaderDefinitions = data.get("shaders");
    RenderOrder renderOrder = RenderOrder.valueOf(data.getString("renderOrder", "Shader_Unordered"));
    final ModelRenderingStrategy renderingStrategy = createRenderingStrategy(renderOrder);
    final String environmentId = data.getString("id", "");
    final RenderingStrategyCallback depthStrategyCallback = new RenderingStrategyCallback(shaderContext, new Function<String, GraphShader>() {

        @Override
        public GraphShader apply(String s) {
            return shaders.get(s);
        }
    });
    final Array<RenderPipelineBuffer> createdPipelineBuffers = new Array<>();
    final Array<Directional3DLight> shadowDirectionalLights = new Array<>();
    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 Lighting3DPrivateData lighting;

        private TimeProvider timeProvider;

        private GraphModelsImpl models;

        private RenderPipeline pipeline;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            lighting = pipelineDataProvider.getPrivatePluginData(Lighting3DPrivateData.class);
            timeProvider = pipelineDataProvider.getTimeProvider();
            models = pipelineDataProvider.getPrivatePluginData(GraphModelsImpl.class);
            for (JsonValue shaderDefinition : shaderDefinitions) {
                GraphShader depthGraphShader = ShadowShaderRendererPipelineNodeProducer.createDepthShader(shaderDefinition, pipelineDataProvider.getWhitePixel().texture);
                allShaderTags.add(depthGraphShader.getTag());
                shaders.put(depthGraphShader.getTag(), depthGraphShader);
            }
            for (ObjectMap.Entry<String, GraphShader> shaderEntry : shaders.entries()) {
                models.registerTag(shaderEntry.key, shaderEntry.value);
            }
        }

        private boolean needsDepth() {
            for (GraphShader shader : shaders.values()) {
                if (shader.isUsingDepthTexture() && models.hasModelWithTag(shader.getTag()))
                    return true;
            }
            return false;
        }

        private boolean isRequiringSceneColor() {
            for (GraphShader shader : shaders.values()) {
                if (shader.isUsingColorTexture() && models.hasModelWithTag(shader.getTag()))
                    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<RenderPipeline> renderPipelineInput = (PipelineNode.FieldOutput<RenderPipeline>) inputs.get("input");
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            boolean usesDepth = enabled && needsDepth();
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            this.pipeline = renderPipeline;
            if (enabled) {
                boolean needsDrawing = false;
                Lighting3DEnvironment environment = lighting.getEnvironment(environmentId);
                // Initialize directional light cameras and textures
                for (Directional3DLight directionalLight : environment.getDirectionalLights()) {
                    if (directionalLight.isShadowsEnabled()) {
                        needsDrawing = true;
                        directionalLight.updateCamera(environment.getSceneCenter(), environment.getSceneDiameter());
                        if (directionalLight.getShadowFrameBuffer() == null) {
                            RenderPipelineBuffer shadowFrameBuffer = renderPipeline.getNewFrameBuffer(directionalLight.getShadowBufferSize(), directionalLight.getShadowBufferSize(), Pixmap.Format.RGB888, Color.WHITE);
                            directionalLight.setShadowFrameBuffer(shadowFrameBuffer);
                            createdPipelineBuffers.add(shadowFrameBuffer);
                            shadowDirectionalLights.add(directionalLight);
                        }
                    }
                }
                if (needsDrawing) {
                    boolean needsSceneColor = isRequiringSceneColor();
                    RenderPipelineBuffer drawBuffer = renderPipeline.getDefaultBuffer();
                    for (Directional3DLight directionalLight : environment.getDirectionalLights()) {
                        if (directionalLight.isShadowsEnabled()) {
                            RenderPipelineBuffer shadowBuffer = directionalLight.getShadowFrameBuffer();
                            Camera camera = directionalLight.getShadowCamera();
                            shaderContext.setCamera(camera);
                            shaderContext.setTimeProvider(timeProvider);
                            shaderContext.setRenderWidth(shadowBuffer.getWidth());
                            shaderContext.setRenderHeight(shadowBuffer.getHeight());
                            if (usesDepth) {
                                renderPipeline.enrichWithDepthBuffer(drawBuffer);
                                shaderContext.setDepthTexture(drawBuffer.getDepthBufferTexture());
                            }
                            if (needsSceneColor)
                                shaderContext.setColorTexture(drawBuffer.getColorBufferTexture());
                            // Drawing models on color buffer
                            depthStrategyCallback.prepare(pipelineRenderingContext, models);
                            shadowBuffer.beginColor();
                            renderingStrategy.processModels(models, allShaderTags, camera, depthStrategyCallback);
                            shadowBuffer.endColor();
                        }
                    }
                }
            }
            output.setValue(renderPipeline);
        }

        @Override
        public void endFrame() {
            for (RenderPipelineBuffer createdPipelineBuffer : createdPipelineBuffers) {
                pipeline.returnFrameBuffer(createdPipelineBuffer);
            }
            createdPipelineBuffers.clear();
            for (Directional3DLight shadowDirectionalLight : shadowDirectionalLights) {
                shadowDirectionalLight.setShadowFrameBuffer(null);
            }
            shadowDirectionalLights.clear();
        }

        @Override
        public void dispose() {
            for (GraphShader shader : shaders.values()) {
                shader.dispose();
            }
        }
    };
}
Also used : ShaderContextImpl(com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.ShaderContextImpl) Directional3DLight(com.gempukku.libgdx.graph.plugin.lighting3d.Directional3DLight) GraphModelsImpl(com.gempukku.libgdx.graph.plugin.models.impl.GraphModelsImpl) ObjectMap(com.badlogic.gdx.utils.ObjectMap) GraphShader(com.gempukku.libgdx.graph.shader.GraphShader) 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) Lighting3DPrivateData(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DPrivateData) Array(com.badlogic.gdx.utils.Array) Lighting3DEnvironment(com.gempukku.libgdx.graph.plugin.lighting3d.Lighting3DEnvironment) RenderOrder(com.gempukku.libgdx.graph.pipeline.RenderOrder) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 4 with PipelineRenderingContext

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

the class MapsLayerIdsRendererPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(final JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String mapId = data.getString("id");
    final String[] layerIds = data.getString("layers").split(",");
    final int[] ids = new int[layerIds.length];
    for (int i = 0; i < layerIds.length; i++) {
        ids[i] = Integer.parseInt(layerIds[i]);
    }
    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 MapsPluginPrivateData mapsPluginData;

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

        @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");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            Camera camera = cameraInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            Map map = mapsPluginData.getMap(mapId);
            MapRenderer mapRenderer = mapsPluginData.getMapRenderer(mapId);
            if (enabled && map != null) {
                // Sadly need to switch off (and then on) the RenderContext
                pipelineRenderingContext.getRenderContext().end();
                RenderPipelineBuffer currentBuffer = renderPipeline.getDefaultBuffer();
                currentBuffer.beginColor();
                mapRenderer.setView((OrthographicCamera) camera);
                mapRenderer.render(ids);
                currentBuffer.endColor();
                pipelineRenderingContext.getRenderContext().begin();
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : ObjectMap(com.badlogic.gdx.utils.ObjectMap) Camera(com.badlogic.gdx.graphics.Camera) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) MapsPluginPrivateData(com.gempukku.libgdx.graph.plugin.maps.MapsPluginPrivateData) RenderPipelineBuffer(com.gempukku.libgdx.graph.pipeline.RenderPipelineBuffer) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) MapRenderer(com.badlogic.gdx.maps.MapRenderer) ObjectMap(com.badlogic.gdx.utils.ObjectMap) Map(com.badlogic.gdx.maps.Map) RenderPipeline(com.gempukku.libgdx.graph.pipeline.RenderPipeline)

Example 5 with PipelineRenderingContext

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

the class RenderCallbackPipelineNodeProducer method createNodeForSingleInputs.

@Override
public PipelineNode createNodeForSingleInputs(JsonValue data, ObjectMap<String, String> inputTypes, ObjectMap<String, String> outputTypes) {
    final String callbackId = data.getString("callbackId", null);
    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 PipelineDataProvider pipelineDataProvider;

        private RenderCallbackPrivateData renderCallbackData;

        @Override
        public void initializePipeline(PipelineDataProvider pipelineDataProvider) {
            renderCallbackData = pipelineDataProvider.getPrivatePluginData(RenderCallbackPrivateData.class);
            this.pipelineDataProvider = pipelineDataProvider;
        }

        @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");
            RenderPipeline renderPipeline = renderPipelineInput.getValue();
            boolean enabled = processorEnabled == null || processorEnabled.getValue();
            if (enabled) {
                RenderCallback callback = renderCallbackData.getRenderCallback(callbackId);
                callback.renderCallback(renderPipeline, pipelineDataProvider, pipelineRenderingContext, pipelineRequirementsCallback);
            }
            output.setValue(renderPipeline);
        }
    };
}
Also used : RenderCallbackPrivateData(com.gempukku.libgdx.graph.plugin.callback.RenderCallbackPrivateData) PipelineRenderingContext(com.gempukku.libgdx.graph.pipeline.producer.PipelineRenderingContext) RenderCallback(com.gempukku.libgdx.graph.plugin.callback.RenderCallback) ObjectMap(com.badlogic.gdx.utils.ObjectMap) 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