/** * {@inheritDoc} */ @Override public ShaderGenerator getShaderGenerator(EnumSet<Caps> caps) { if (shaderGenerator == null) { if(caps.contains(Caps.GLSL150)){ shaderGenerator = new Glsl150ShaderGenerator(this); }else{ shaderGenerator = new Glsl100ShaderGenerator(this); } } return shaderGenerator; }
/** * {@inheritDoc} * * Fragment shader outputs are declared before the "void main(){" with the * "out" keyword. * * after the "void main(){", the vertex output are declared and initialized * and the fragment outputs are declared */ @Override protected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { source.append("\n"); if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { declareVariable(source, global, null, true, "out"); } } source.append("\n"); appendIndent(source); source.append("void main(){\n"); indent(); if (type == Shader.ShaderType.Vertex) { declareGlobalPosition(info, source); } else if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { initVariable(source, global, "vec4(1.0)"); } } }
/** * {@inheritDoc} * * only vertex shader output are mapped here, since fragment shader outputs * must have been mapped in the main section. */ @Override protected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { if (type == Shader.ShaderType.Vertex) { appendOutput(source, "gl_Position", info.getVertexGlobal()); } unIndent(); appendIndent(source); source.append("}\n"); }
/** * {@inheritDoc} in glsl 1.5 attributes are prefixed with the "in" keyword * and not the "attribute" keyword */ @Override protected void declareAttribute(StringBuilder source, ShaderNodeVariable var) { declareVariable(source, var, false, "in"); }
@Override protected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { generateCompatibilityDefines(source, type); super.generateUniforms(source, info, type); }
/** * Append a variable initialization to the code * * @param source the StringBuilder to use * @param var the variable to initialize * @param initValue the init value to assign to the variable */ protected void initVariable(StringBuilder source, ShaderNodeVariable var, String initValue) { appendIndent(source); source.append(var.getNameSpace()); source.append("_"); source.append(var.getName()); source.append(" = "); source.append(initValue); source.append(";\n"); } }
/** * {@inheritDoc} in glsl 1.5 varying are prefixed with the "in" or "out" * keyword and not the "varying" keyword. * * "in" is used for Fragment shader (maybe Geometry shader later) "out" is * used for Vertex shader (maybe Geometry shader later) */ @Override protected void declareVarying(StringBuilder source, ShaderNodeVariable var, boolean input) { declareVariable(source, var, true, input ? "in" : "out"); }
@Override protected void generateUniforms(StringBuilder source, ShaderGenerationInfo info, ShaderType type) { generateCompatibilityDefines(source, type); super.generateUniforms(source, info, type); }
/** * Append a variable initialization to the code * * @param source the StringBuilder to use * @param var the variable to initialize * @param initValue the init value to assign to the variable */ protected void initVariable(StringBuilder source, ShaderNodeVariable var, String initValue) { appendIndent(source); source.append(var.getNameSpace()); source.append("_"); source.append(var.getName()); source.append(" = "); source.append(initValue); source.append(";\n"); } }
/** * {@inheritDoc} * * Fragment shader outputs are declared before the "void main(){" with the * "out" keyword. * * after the "void main(){", the vertex output are declared and initialized * and the fragment outputs are declared */ @Override protected void generateStartOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { source.append("\n"); if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { declareVariable(source, global, null, true, "out"); } } source.append("\n"); appendIndent(source); source.append("void main(){\n"); indent(); if (type == Shader.ShaderType.Vertex) { declareGlobalPosition(info, source); } else if (type == Shader.ShaderType.Fragment) { for (ShaderNodeVariable global : info.getFragmentGlobals()) { initVariable(source, global, "vec4(1.0)"); } } }
/** * {@inheritDoc} * * only vertex shader output are mapped here, since fragment shader outputs * must have been mapped in the main section. */ @Override protected void generateEndOfMainSection(StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type) { if (type == Shader.ShaderType.Vertex) { appendOutput(source, "gl_Position", info.getVertexGlobal()); } unIndent(); appendIndent(source); source.append("}\n"); }
/** * {@inheritDoc} in glsl 1.5 attributes are prefixed with the "in" keyword * and not the "attribute" keyword */ @Override protected void declareAttribute(StringBuilder source, ShaderNodeVariable var) { declareVariable(source, var, false, "in"); }
/** * {@inheritDoc} */ @Override public ShaderGenerator getShaderGenerator(EnumSet<Caps> caps) { if (shaderGenerator == null) { if(caps.contains(Caps.GLSL150)){ shaderGenerator = new Glsl150ShaderGenerator(this); }else{ shaderGenerator = new Glsl100ShaderGenerator(this); } } return shaderGenerator; }
/** * {@inheritDoc} in glsl 1.5 varying are prefixed with the "in" or "out" * keyword and not the "varying" keyword. * * "in" is used for Fragment shader (maybe Geometry shader later) "out" is * used for Vertex shader (maybe Geometry shader later) */ @Override protected void declareVarying(StringBuilder source, ShaderNodeVariable var, boolean input) { declareVariable(source, var, true, input ? "in" : "out"); }