com.gempukku.libgdx.graph.shader.common.math.arithmetic.AddShaderNodeBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libgdx-graph Show documentation
Show all versions of libgdx-graph Show documentation
libGDX-graph runtime library for pipeline rendering
The newest version!
package com.gempukku.libgdx.graph.shader.common.math.arithmetic;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.JsonValue;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.ObjectSet;
import com.gempukku.libgdx.graph.shader.GraphShader;
import com.gempukku.libgdx.graph.shader.GraphShaderContext;
import com.gempukku.libgdx.graph.shader.ShaderFieldType;
import com.gempukku.libgdx.graph.shader.builder.CommonShaderBuilder;
import com.gempukku.libgdx.graph.shader.builder.FragmentShaderBuilder;
import com.gempukku.libgdx.graph.shader.builder.VertexShaderBuilder;
import com.gempukku.libgdx.graph.shader.config.common.math.arithmetic.AddShaderNodeConfiguration;
import com.gempukku.libgdx.graph.shader.node.ConfigurationShaderNodeBuilder;
import com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput;
import com.gempukku.libgdx.graph.util.LibGDXCollections;
public class AddShaderNodeBuilder extends ConfigurationShaderNodeBuilder {
public AddShaderNodeBuilder() {
super(new AddShaderNodeConfiguration());
}
@Override
protected ObjectMap buildVertexNodeSingleInputs(boolean designTime, String nodeId, JsonValue data, ObjectMap inputs, ObjectSet producedOutputs, VertexShaderBuilder vertexShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
return null;
}
@Override
protected ObjectMap buildFragmentNodeSingleInputs(boolean designTime, String nodeId, JsonValue data, ObjectMap inputs, ObjectSet producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
return null;
}
@Override
public ObjectMap buildVertexNode(boolean designTime, String nodeId, JsonValue data, ObjectMap> inputs, ObjectSet producedOutputs, VertexShaderBuilder vertexShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
return buildAddCommonNode(designTime, nodeId, data, inputs, producedOutputs, vertexShaderBuilder, graphShaderContext, graphShader);
}
@Override
public ObjectMap buildFragmentNode(boolean designTime, String nodeId, JsonValue data, ObjectMap> inputs, ObjectSet producedOutputs, VertexShaderBuilder vertexShaderBuilder, FragmentShaderBuilder fragmentShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
return buildAddCommonNode(designTime, nodeId, data, inputs, producedOutputs, fragmentShaderBuilder, graphShaderContext, graphShader);
}
private ObjectMap buildAddCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap> inputArrays, ObjectSet producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
Array inputs = inputArrays.get("inputs");
ShaderFieldType resultType = determineOutputType(inputs);
commonShaderBuilder.addMainLine("// Add node");
String name = "result_" + nodeId;
StringBuilder additionText = new StringBuilder();
for (FieldOutput input : inputs) {
additionText.append(" + ");
additionText.append(input.getRepresentation());
}
additionText.replace(0, 3, "");
commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + additionText.toString() + ";");
return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
private ShaderFieldType determineOutputType(Array inputs) {
ShaderFieldType result = ShaderFieldType.Float;
for (FieldOutput input : inputs) {
ShaderFieldType fieldType = input.getFieldType();
if (fieldType != result && (result != ShaderFieldType.Float && fieldType != ShaderFieldType.Float))
throw new IllegalStateException("Invalid mix of input field types");
if (fieldType != ShaderFieldType.Float)
result = fieldType;
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy