Search in sources :

Example 6 with GraphProperty

use of com.gempukku.libgdx.graph.data.GraphProperty in project gdx-graph by MarcinSc.

the class ModelShaderPreviewWidget method createShader.

private void createShader(final Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph) {
    try {
        timeKeeper = new DefaultTimeKeeper();
        graphShader = GraphShaderBuilder.buildModelShader("Test", WhitePixel.sharedInstance.texture, graph, true);
        frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width, height, false);
        createModel();
        MapWritablePropertyContainer globalPropertyContainer = new MapWritablePropertyContainer();
        for (GraphProperty property : graph.getProperties()) {
            if (property.getLocation() == PropertyLocation.Global_Uniform) {
                ShaderFieldType propertyType = ShaderFieldTypeRegistry.findShaderFieldType(property.getType());
                globalPropertyContainer.setValue(property.getName(), propertyType.convertFromJson(property.getData()));
            }
        }
        shaderContext.setGlobalPropertyContainer(globalPropertyContainer);
        localPropertyContainer = new MapWritablePropertyContainer();
        for (GraphProperty property : graph.getProperties()) {
            if (property.getLocation() == PropertyLocation.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);
                            localPropertyContainer.setValue(property.getName(), new TextureRegion(texture));
                        } catch (Exception exp) {
                            localPropertyContainer.setValue(property.getName(), WhitePixel.sharedInstance.textureRegion);
                        }
                    } else {
                        localPropertyContainer.setValue(property.getName(), WhitePixel.sharedInstance.textureRegion);
                    }
                }
            }
        }
        shaderContext.setTimeProvider(timeKeeper);
        shaderInitialized = true;
    } catch (Exception exp) {
        exp.printStackTrace();
        if (graphShader != null)
            graphShader.dispose();
    }
}
Also used : DefaultTimeKeeper(com.gempukku.libgdx.graph.util.DefaultTimeKeeper) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) GraphProperty(com.gempukku.libgdx.graph.data.GraphProperty) FrameBuffer(com.badlogic.gdx.graphics.glutils.FrameBuffer) MapWritablePropertyContainer(com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Example 7 with GraphProperty

use of com.gempukku.libgdx.graph.data.GraphProperty in project gdx-graph by MarcinSc.

the class EndScreenShaderBoxProducer method createPipelineGraphBox.

@Override
public GraphBox createPipelineGraphBox(Skin skin, String id, JsonValue data) {
    final ScreenShaderPreviewBoxPart previewBoxPart = new ScreenShaderPreviewBoxPart();
    previewBoxPart.initialize(data);
    GraphBoxImpl result = new GraphBoxImpl(id, getConfiguration()) {

        @Override
        public void graphChanged(GraphChangedEvent event, boolean hasErrors, Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph) {
            if (event.isData() || event.isStructure()) {
                previewBoxPart.graphChanged(hasErrors, graph);
            }
        }
    };
    addConfigurationInputsAndOutputs(result);
    result.addGraphBoxPart(new SectionBoxPart("Rendering config"));
    BlendingBoxPart blendingBox = new BlendingBoxPart();
    blendingBox.initialize(data);
    result.addGraphBoxPart(blendingBox);
    result.addGraphBoxPart(new SectionBoxPart("Preview"));
    result.addGraphBoxPart(previewBoxPart);
    return result;
}
Also used : GraphProperty(com.gempukku.libgdx.graph.data.GraphProperty) GraphBoxImpl(com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl) Graph(com.gempukku.libgdx.graph.data.Graph) GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) ScreenShaderPreviewBoxPart(com.gempukku.libgdx.graph.plugin.screen.design.ScreenShaderPreviewBoxPart) GraphConnection(com.gempukku.libgdx.graph.data.GraphConnection) BlendingBoxPart(com.gempukku.libgdx.graph.ui.part.BlendingBoxPart) SectionBoxPart(com.gempukku.libgdx.graph.ui.part.SectionBoxPart) GraphNode(com.gempukku.libgdx.graph.data.GraphNode)

Aggregations

GraphProperty (com.gempukku.libgdx.graph.data.GraphProperty)7 Graph (com.gempukku.libgdx.graph.data.Graph)4 GraphConnection (com.gempukku.libgdx.graph.data.GraphConnection)4 GraphNode (com.gempukku.libgdx.graph.data.GraphNode)4 GraphBoxImpl (com.gempukku.libgdx.graph.ui.graph.GraphBoxImpl)4 GraphChangedEvent (com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)3 FrameBuffer (com.badlogic.gdx.graphics.glutils.FrameBuffer)3 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)3 DefaultTimeKeeper (com.gempukku.libgdx.graph.util.DefaultTimeKeeper)3 PropertyContainer (com.gempukku.libgdx.graph.pipeline.producer.rendering.producer.PropertyContainer)2 ModelShaderPreviewBoxPart (com.gempukku.libgdx.graph.plugin.models.design.producer.ModelShaderPreviewBoxPart)1 ScreenShaderPreviewBoxPart (com.gempukku.libgdx.graph.plugin.screen.design.ScreenShaderPreviewBoxPart)1 MapWritablePropertyContainer (com.gempukku.libgdx.graph.shader.property.MapWritablePropertyContainer)1 BlendingBoxPart (com.gempukku.libgdx.graph.ui.part.BlendingBoxPart)1 CheckboxBoxPart (com.gempukku.libgdx.graph.ui.part.CheckboxBoxPart)1 EnumSelectBoxPart (com.gempukku.libgdx.graph.ui.part.EnumSelectBoxPart)1 SectionBoxPart (com.gempukku.libgdx.graph.ui.part.SectionBoxPart)1 SelectBoxPart (com.gempukku.libgdx.graph.ui.part.SelectBoxPart)1 Validators (com.kotcrab.vis.ui.util.Validators)1