Search in sources :

Example 1 with GraphShaderNodeBuilder

use of com.gempukku.libgdx.graph.shader.node.GraphShaderNodeBuilder in project gdx-graph by MarcinSc.

the class GraphShaderBuilder method buildNode.

private static ObjectMap<String, GraphShaderNodeBuilder.FieldOutput> buildNode(boolean designTime, boolean fragmentShader, Graph<? extends GraphNode, ? extends GraphConnection, ? extends GraphProperty> graph, GraphShaderContext context, GraphShader graphShader, String nodeId, ObjectMap<String, ObjectMap<String, GraphShaderNodeBuilder.FieldOutput>> nodeOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, GraphConfiguration... graphConfigurations) {
    ObjectMap<String, GraphShaderNodeBuilder.FieldOutput> nodeOutput = nodeOutputs.get(nodeId);
    if (nodeOutput == null) {
        GraphNode nodeInfo = graph.getNodeById(nodeId);
        String nodeInfoType = nodeInfo.getConfiguration().getType();
        GraphShaderNodeBuilder nodeBuilder = getNodeBuilder(nodeInfoType, graphConfigurations);
        if (nodeBuilder == null)
            throw new IllegalStateException("Unable to find graph shader node builder for type: " + nodeInfoType);
        ObjectMap<String, Array<GraphShaderNodeBuilder.FieldOutput>> inputFields = new ObjectMap<>();
        for (GraphNodeInput nodeInput : new ObjectMap.Values<>(nodeBuilder.getConfiguration(nodeInfo.getData()).getNodeInputs())) {
            String fieldId = nodeInput.getFieldId();
            Array<GraphConnection> vertexInfos = findInputVertices(graph, nodeId, fieldId);
            if (vertexInfos.size == 0 && nodeInput.isRequired())
                throw new IllegalStateException("Required input not provided");
            Array<String> fieldTypes = new Array<>();
            Array<GraphShaderNodeBuilder.FieldOutput> fieldOutputs = new Array<>();
            for (GraphConnection vertexInfo : vertexInfos) {
                ObjectMap<String, GraphShaderNodeBuilder.FieldOutput> output = buildNode(designTime, fragmentShader, graph, context, graphShader, vertexInfo.getNodeFrom(), nodeOutputs, vertexShaderBuilder, fragmentShaderBuilder, graphConfigurations);
                GraphShaderNodeBuilder.FieldOutput fieldOutput = output.get(vertexInfo.getFieldFrom());
                ShaderFieldType fieldType = fieldOutput.getFieldType();
                fieldTypes.add(fieldType.getName());
                fieldOutputs.add(fieldOutput);
            }
            if (!nodeInput.acceptsInputTypes(fieldTypes))
                throw new IllegalStateException("Producer produces a field of value not compatible with consumer");
            inputFields.put(fieldId, fieldOutputs);
        }
        ObjectSet<String> requiredOutputs = findRequiredOutputs(graph, nodeId);
        if (fragmentShader) {
            nodeOutput = (ObjectMap<String, GraphShaderNodeBuilder.FieldOutput>) nodeBuilder.buildFragmentNode(designTime, nodeId, nodeInfo.getData(), inputFields, requiredOutputs, vertexShaderBuilder, fragmentShaderBuilder, context, graphShader);
        } else {
            nodeOutput = (ObjectMap<String, GraphShaderNodeBuilder.FieldOutput>) nodeBuilder.buildVertexNode(designTime, nodeId, nodeInfo.getData(), inputFields, requiredOutputs, vertexShaderBuilder, context, graphShader);
        }
        nodeOutputs.put(nodeId, nodeOutput);
    }
    return nodeOutput;
}
Also used : Array(com.badlogic.gdx.utils.Array) GraphShaderNodeBuilder(com.gempukku.libgdx.graph.shader.node.GraphShaderNodeBuilder) ObjectMap(com.badlogic.gdx.utils.ObjectMap) ShaderFieldType(com.gempukku.libgdx.graph.shader.field.ShaderFieldType)

Aggregations

Array (com.badlogic.gdx.utils.Array)1 ObjectMap (com.badlogic.gdx.utils.ObjectMap)1 ShaderFieldType (com.gempukku.libgdx.graph.shader.field.ShaderFieldType)1 GraphShaderNodeBuilder (com.gempukku.libgdx.graph.shader.node.GraphShaderNodeBuilder)1