com.gempukku.libgdx.graph.shader.common.math.arithmetic.DivideShaderNodeBuilder 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.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.config.common.math.arithmetic.DivideShaderNodeConfiguration;
import com.gempukku.libgdx.graph.shader.node.ConfigurationCommonShaderNodeBuilder;
import com.gempukku.libgdx.graph.shader.node.DefaultFieldOutput;
import com.gempukku.libgdx.graph.util.LibGDXCollections;
public class DivideShaderNodeBuilder extends ConfigurationCommonShaderNodeBuilder {
public DivideShaderNodeBuilder() {
super(new DivideShaderNodeConfiguration());
}
@Override
protected ObjectMap buildCommonNode(boolean designTime, String nodeId, JsonValue data, ObjectMap inputs, ObjectSet producedOutputs, CommonShaderBuilder commonShaderBuilder, GraphShaderContext graphShaderContext, GraphShader graphShader) {
FieldOutput aValue = inputs.get("a");
FieldOutput bValue = inputs.get("b");
ShaderFieldType resultType = determineOutputType(aValue, bValue);
commonShaderBuilder.addMainLine("// Divide node");
String name = "result_" + nodeId;
commonShaderBuilder.addMainLine(resultType.getShaderType() + " " + name + " = " + aValue.getRepresentation() + " / " + bValue.getRepresentation() + ";");
return LibGDXCollections.singletonMap("output", new DefaultFieldOutput(resultType, name));
}
private ShaderFieldType determineOutputType(FieldOutput a, FieldOutput b) {
ShaderFieldType aType = a.getFieldType();
ShaderFieldType bType = b.getFieldType();
if (aType == ShaderFieldType.Float)
return bType;
if (bType == ShaderFieldType.Float)
return aType;
if (aType != bType)
throw new IllegalStateException("Invalid mix of input field types");
return aType;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy