Search in sources :

Example 1 with PropertyContainer

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

the class ParticlesShaderPreviewWidget method createShader.

private void createShader(final Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph) {
    try {
        timeKeeper = new DefaultTimeKeeper();
        graphShader = GraphShaderBuilder.buildParticlesShader("Test", WhitePixel.sharedInstance.texture, graph, true);
        frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
        createModel();
        shaderContext.setTimeProvider(timeKeeper);
        shaderContext.setGlobalPropertyContainer(new PropertyContainer() {

            @Override
            public Object getValue(String name) {
                for (GraphProperty property : graph.getProperties()) {
                    if (property.getName().equals(name) && property.getLocation() == PropertyLocation.Global_Uniform) {
                        ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                        return propertyType.convertFromJson(property.getData());
                    }
                }
                return null;
            }
        });
        shaderContext.setLocalPropertyContainer(new PropertyContainer() {

            @Override
            public Object getValue(String name) {
                for (GraphProperty property : graph.getProperties()) {
                    if (property.getName().equals(name) && property.getLocation() != PropertyLocation.Global_Uniform) {
                        ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                        Object value = propertyType.convertFromJson(property.getData());
                        if (propertyType.isTexture()) {
                            if (value != null) {
                                try {
                                    Texture texture = new Texture(Gdx.files.absolute((String) value));
                                    graphShader.addManagedResource(texture);
                                    return new TextureRegion(texture);
                                } catch (Exception exp) {
                                }
                            }
                            return WhitePixel.sharedInstance.textureRegion;
                        } else {
                            return value;
                        }
                    }
                }
                return null;
            }
        });
        shaderInitialized = true;
    } catch (Exception exp) {
        exp.printStackTrace();
        if (graphShader != null)
            graphShader.dispose();
    }
}
Also used : DefaultTimeKeeper(com.gempukku.libgdx.graph.util.DefaultTimeKeeper) PropertyContainer(com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.PropertyContainer) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GraphProperty(com.gempukku.libgdx.graph.data.GraphProperty) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Example 2 with PropertyContainer

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

the class ScreenShaderPreviewWidget method createShader.

private void createShader(final Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph) {
    try {
        timeKeeper = new DefaultTimeKeeper();
        graphShader = GraphShaderBuilder.buildScreenShader("Test", WhitePixel.sharedInstance.texture, graph, true);
        frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
        shaderContext.setTimeProvider(timeKeeper);
        shaderContext.setGlobalPropertyContainer(new PropertyContainer() {

            @Override
            public Object getValue(String name) {
                for (GraphProperty property : graph.getProperties()) {
                    if (property.getName().equals(name)) {
                        ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                        Object value = propertyType.convertFromJson(property.getData());
                        if (propertyType.isTexture()) {
                            if (value != null) {
                                try {
                                    Texture texture = new Texture(Gdx.files.absolute((String) value));
                                    graphShader.addManagedResource(texture);
                                    return new TextureRegion(texture);
                                } catch (Exception exp) {
                                }
                            }
                            return WhitePixel.sharedInstance.textureRegion;
                        } else {
                            return value;
                        }
                    }
                }
                return null;
            }
        });
        shaderInitialized = true;
    } catch (Exception exp) {
        exp.printStackTrace();
        if (graphShader != null)
            graphShader.dispose();
    }
}
Also used : DefaultTimeKeeper(com.gempukku.libgdx.graph.util.DefaultTimeKeeper) PropertyContainer(com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.PropertyContainer) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GraphProperty(com.gempukku.libgdx.graph.data.GraphProperty) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Aggregations

TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)2 GraphProperty (com.gempukku.libgdx.graph.data.GraphProperty)2 PropertyContainer (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.PropertyContainer)2 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)2 DefaultTimeKeeper (com.gempukku.libgdx.graph.util.DefaultTimeKeeper)2