public class Glsl100ShaderGenerator extends ShaderGenerator
Modifier and Type | Field and Description |
---|---|
protected ShaderNodeVariable |
inPosTmp |
assetManager, indent, NAME_SPACE_GLOBAL, NAME_SPACE_MAT_PARAM, NAME_SPACE_VERTEX_ATTRIBUTE, NAME_SPACE_WORLD_PARAM, techniqueDef
Constructor and Description |
---|
Glsl100ShaderGenerator(AssetManager assetManager)
creates a Glsl100ShaderGenerator
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendIndent(java.lang.StringBuilder source)
appends indentation.
|
protected void |
appendOutput(java.lang.StringBuilder source,
java.lang.String globalOutputName,
ShaderNodeVariable var)
Appends an output assignment to a shader globalOutputName =
nameSpace_varName;
|
protected void |
comment(java.lang.StringBuilder source,
ShaderNode shaderNode,
java.lang.String comment)
Appends a comment to the generated code
|
protected void |
declareAttribute(java.lang.StringBuilder source,
ShaderNodeVariable var)
Declares an attribute
|
protected void |
declareGlobalPosition(ShaderGenerationInfo info,
java.lang.StringBuilder source)
declare and assign the global position in the vertex shader.
|
protected void |
declareVariable(java.lang.StringBuilder source,
ShaderNodeVariable var)
declares a variable, embed in a conditional block if needed.
|
protected void |
declareVariable(java.lang.StringBuilder source,
ShaderNodeVariable var,
boolean appendNameSpace)
declares a variable, embed in a conditional block if needed
|
protected void |
declareVariable(java.lang.StringBuilder source,
ShaderNodeVariable var,
boolean appendNameSpace,
java.lang.String modifier)
declares a variable, embed in a conditional block if needed.
|
protected void |
declareVariable(java.lang.StringBuilder source,
ShaderNodeVariable var,
java.lang.String value)
declares a variable, embed in a conditional block if needed.
|
protected void |
declareVariable(java.lang.StringBuilder source,
ShaderNodeVariable var,
java.lang.String value,
boolean appendNameSpace,
java.lang.String modifier)
declares a variable, embed in a conditional block if needed.
|
protected void |
declareVarying(java.lang.StringBuilder source,
ShaderNodeVariable var,
boolean input)
Declares a varying
|
protected void |
endCondition(java.lang.String condition,
java.lang.StringBuilder source)
Ends a conditional block
|
protected void |
fixInPositionType(ShaderNodeVariable var)
makes sure inPosition attribute is of type vec3 or vec4
|
protected void |
generateAttributes(java.lang.StringBuilder source,
ShaderGenerationInfo info)
generates the attributes declaration for the vertex shader.
|
protected void |
generateDeclarativeSection(java.lang.StringBuilder source,
ShaderNode shaderNode,
java.lang.String nodeSource,
ShaderGenerationInfo info)
Appends the given shaderNode declarative part to the shader declarative
part.
|
protected void |
generateEndOfMainSection(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
Generates the end of the shader main section.
|
protected void |
generateNodeMainSection(java.lang.StringBuilder source,
ShaderNode shaderNode,
java.lang.String nodeSource,
ShaderGenerationInfo info)
Appends the given shaderNode main part to the shader declarative part.
|
protected void |
generateStartOfMainSection(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the start of the shader main section.
|
protected void |
generateUniforms(java.lang.StringBuilder source,
java.util.List<ShaderNodeVariable> uniforms)
declare a list of uniforms
|
protected void |
generateUniforms(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the uniforms declaration for a shader of the given type.
|
protected void |
generateVaryings(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the varyings for the given shader type shader.
|
protected java.lang.String |
getAppendableNameSpace(ShaderNodeVariable var)
returns the name space to append for a variable.
|
protected java.lang.String |
getLanguageAndVersion(Shader.ShaderType type)
returns the language + version of the shader should be something like
"GLSL100" for glsl 1.0 "GLSL150" for glsl 1.5.
|
protected void |
indent()
increase indentation with a check so that indentation is never over 10
|
protected boolean |
isVarying(ShaderGenerationInfo info,
ShaderNodeVariable v)
Finds if a variable is a varying
|
protected boolean |
isWorldOrMaterialParam(ShaderNodeVariable var)
Finds if a variable is a world or a material parameter
|
protected void |
map(VariableMapping mapping,
java.lang.StringBuilder source,
boolean declare)
Appends a mapping to the source, embed in a conditional block if needed,
with variables nameSpaces and swizzle.
|
protected java.lang.String |
replace(java.lang.String nodeSource,
ShaderNodeVariable var,
java.lang.String newName)
replaced a variable name in a source code with the given name
|
protected java.lang.String |
replaceVariableName(java.lang.String nodeSource,
ShaderNodeVariable var)
replaces a variable name in a shaderNode source code by prefixing it
with its nameSpace and "_" if needed.
|
protected void |
startCondition(java.lang.String condition,
java.lang.StringBuilder source)
Starts a conditional block
|
protected void |
unIndent()
Decrease indentation with a check so the indent is never negative.
|
protected java.lang.String |
updateDefinesName(java.lang.String nodeSource,
ShaderNode shaderNode)
transforms defines name is the shader node code.
|
appendNodeDeclarationAndMain, buildShader, findShaderIndexFromVersion, generateDeclarationAndMainBody, generateShader, initialize
protected ShaderNodeVariable inPosTmp
public Glsl100ShaderGenerator(AssetManager assetManager)
assetManager
- the assetManagerprotected void generateUniforms(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
ShaderGenerator
generateUniforms
in class ShaderGenerator
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the uniforms have to be generated for.protected void generateUniforms(java.lang.StringBuilder source, java.util.List<ShaderNodeVariable> uniforms)
source
- the source to append touniforms
- the list of uniformsprotected void generateAttributes(java.lang.StringBuilder source, ShaderGenerationInfo info)
generateAttributes
in class ShaderGenerator
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.protected void generateVaryings(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
ShaderGenerator
generateVaryings
in class ShaderGenerator
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the varyings have to be generated for.protected void generateDeclarativeSection(java.lang.StringBuilder source, ShaderNode shaderNode, java.lang.String nodeSource, ShaderGenerationInfo info)
generateDeclarativeSection
in class ShaderGenerator
source
- the StringBuilder to append generated code.shaderNode
- the shaderNode.nodeSource
- the declaration part of the nodeinfo
- the ShaderGenerationInfo.ShaderNode.getDefinition()
,
ShaderNodeDefinition.getType()
protected void generateStartOfMainSection(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
generateStartOfMainSection
in class ShaderGenerator
source
- the StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the section has to be generated for.protected void generateEndOfMainSection(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
generateEndOfMainSection
in class ShaderGenerator
source
- the StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the section has to be generated for.protected void appendOutput(java.lang.StringBuilder source, java.lang.String globalOutputName, ShaderNodeVariable var)
source
- the source StringBuilder to append the code.globalOutputName
- the name of the global output (can be gl_Position
or gl_FragColor etc...).var
- the variable to assign to the output.protected void generateNodeMainSection(java.lang.StringBuilder source, ShaderNode shaderNode, java.lang.String nodeSource, ShaderGenerationInfo info)
generateNodeMainSection
in class ShaderGenerator
source
- the StringBuilder to append generated code.shaderNode
- the shaderNode.nodeSource
- the declaration part of the loaded shaderNode source.info
- the ShaderGenerationInfo.ShaderNode.getDefinition()
,
ShaderNodeDefinition.getType()
protected void declareVariable(java.lang.StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace)
source
- the StringBuilder to usevar
- the variable to declareappendNameSpace
- true to append the nameSpace + "_"protected void declareVariable(java.lang.StringBuilder source, ShaderNodeVariable var)
source
- the StringBuilder to usevar
- the variable to declareprotected void declareVariable(java.lang.StringBuilder source, ShaderNodeVariable var, java.lang.String value)
source
- the StringBuilder to usevar
- the variable to declarevalue
- the initialization value to assign the variableprotected void declareVariable(java.lang.StringBuilder source, ShaderNodeVariable var, boolean appendNameSpace, java.lang.String modifier)
source
- the StringBuilder to usevar
- the variable to declareappendNameSpace
- true to append the nameSpace + "_"modifier
- the modifier of the variable (attribute, varying, in , out,...)protected void declareVariable(java.lang.StringBuilder source, ShaderNodeVariable var, java.lang.String value, boolean appendNameSpace, java.lang.String modifier)
source
- the StringBuilder to usevar
- the variable to declarevalue
- the initialization value to assign the variableappendNameSpace
- true to append the nameSpace + "_"modifier
- the modifier of the variable (attribute, varying, in , out,...)protected void startCondition(java.lang.String condition, java.lang.StringBuilder source)
condition
- the block conditionsource
- the StringBuilder to useprotected void endCondition(java.lang.String condition, java.lang.StringBuilder source)
condition
- the block conditionsource
- the StringBuilder to useprotected void map(VariableMapping mapping, java.lang.StringBuilder source, boolean declare)
mapping
- the VariableMapping to appendsource
- the StringBuilder to usedeclare
- true to declare the variable, false if already declaredprotected java.lang.String replaceVariableName(java.lang.String nodeSource, ShaderNodeVariable var)
nodeSource
- the source to modifyvar
- the variable to replaceprotected boolean isVarying(ShaderGenerationInfo info, ShaderNodeVariable v)
info
- the ShaderGenerationInfov
- the variableprotected void comment(java.lang.StringBuilder source, ShaderNode shaderNode, java.lang.String comment)
source
- the StringBuilder to useshaderNode
- the shader node being processed (to append its name)comment
- the comment to appendprotected java.lang.String getAppendableNameSpace(ShaderNodeVariable var)
var
- the variableprotected java.lang.String updateDefinesName(java.lang.String nodeSource, ShaderNode shaderNode)
nodeSource
- the shaderNode source codeshaderNode
- the ShaderNode being processedprotected java.lang.String replace(java.lang.String nodeSource, ShaderNodeVariable var, java.lang.String newName)
nodeSource
- the source to usevar
- the variablenewName
- the new name of the variableprotected boolean isWorldOrMaterialParam(ShaderNodeVariable var)
var
- the variableprotected java.lang.String getLanguageAndVersion(Shader.ShaderType type)
ShaderGenerator
getLanguageAndVersion
in class ShaderGenerator
type
- the shader type for which the version should be returned.protected void appendIndent(java.lang.StringBuilder source)
source
- the builder to append toprotected void declareAttribute(java.lang.StringBuilder source, ShaderNodeVariable var)
source
- the StringBuilder to usevar
- the variable to declare as an attributeprotected void declareVarying(java.lang.StringBuilder source, ShaderNodeVariable var, boolean input)
source
- the StringBuilder to usevar
- the variable to declare as a varyinginput
- a boolean set to true if the varying is an input.
This in not used in this implementation, but can be used in overriding
implementations.protected void unIndent()
protected void indent()
protected void fixInPositionType(ShaderNodeVariable var)
var
- the inPosition attributeprotected void declareGlobalPosition(ShaderGenerationInfo info, java.lang.StringBuilder source)
info
- the shader generation infosource
- the shader source being generated