public class ShaderNodeLoaderDelegate
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
ShaderNodeLoaderDelegate.DeclaredVariable |
Modifier and Type | Field and Description |
---|---|
protected AssetManager |
assetManager |
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> |
attributes |
protected ConditionParser |
conditionParser |
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> |
fragmentDeclaredUniforms |
protected MaterialDef |
materialDef |
protected java.util.Map<java.lang.String,ShaderNodeDefinition> |
nodeDefinitions |
protected java.util.Map<java.lang.String,ShaderNode> |
nodes |
protected java.util.List<java.lang.String> |
nulledConditions |
protected java.lang.String |
shaderLanguage |
protected java.lang.String |
shaderName |
protected ShaderNode |
shaderNode |
protected ShaderNodeDefinition |
shaderNodeDefinition |
protected TechniqueDef |
techniqueDef |
protected java.util.Set<java.lang.String> |
varNames |
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> |
varyings |
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> |
vertexDeclaredUniforms |
Constructor and Description |
---|
ShaderNodeLoaderDelegate() |
Modifier and Type | Method and Description |
---|---|
void |
addDefine(java.lang.String paramName,
VarType paramType)
Adds a define to the technique def
|
protected void |
checkMappingFormat(java.lang.String[] vars,
Statement statement)
Checks if once a mapping expression is split by "=" the resulting array
have 2 elements.
|
protected void |
checkTypes(VariableMapping mapping,
Statement statement1)
check the types of a mapping, left type must match right type take the
swizzle into account
|
void |
clear() |
void |
extractCondition(java.lang.String condition,
Statement statement)
Extracts and checks a condition expression.
|
ShaderNodeDefinition |
findDefinition(Statement statement)
Find the definition from this statement (loads it if necessary)
|
protected MatParam |
findMatParam(java.lang.String varName)
Finds a
MatParam in the MaterialDef from the given name. |
ShaderNodeVariable |
findNodeOutput(java.util.List<ShaderNodeVariable> vars,
java.lang.String rightVarName)
Finds a variable with the given name from the list of variable.
|
protected UniformBinding |
findWorldParam(java.lang.String varName)
finds an UniformBinding representing a WorldParam from the techniqueDef
|
java.lang.String |
fixSamplerType(java.lang.String leftType,
java.lang.String rightType)
retrieve the leftType corresponding sampler type from the rightType
|
java.lang.String |
mergeConditions(java.lang.String condition1,
java.lang.String condition2,
java.lang.String operator)
Merges 2 conditions with the given operator
|
protected VariableMapping |
parseMapping(Statement statement,
boolean[] hasNameSpace)
Reads a mapping statement.
|
void |
readFragmentShaderNodes(java.util.List<Statement> statements)
reads the FragmentShaderNodes{} block
|
VariableMapping |
readInputMapping(Statement statement)
Reads an input mapping.
|
void |
readNodes(java.util.List<Statement> statements)
Reads a list of ShaderNodes
|
void |
readNodesDefinitions(java.util.List<Statement> statements)
Read the ShaderNodesDefinitions block and internally stores a map of
ShaderNodesDefinition This method is used by the j3m loader.
|
java.util.List<ShaderNodeDefinition> |
readNodesDefinitions(java.util.List<Statement> statements,
ShaderNodeDefinitionKey key)
Read the ShaderNodesDefinitions block and returns a list of
ShaderNodesDefinition This method is used by the j3sn loader
note that the order of the definitions in the list is not guaranteed.
|
VariableMapping |
readOutputMapping(Statement statement)
Reads an output mapping.
|
protected void |
readShaderNode(java.util.List<Statement> statements)
reads a list of ShaderNode{} blocks
|
protected void |
readShaderNodeDefinition(java.util.List<Statement> statements,
ShaderNodeDefinitionKey key)
effectively reads the ShaderNodesDefinitions block
|
protected void |
readShaderStatement(Statement statement)
Reads a Shader statement of the form TYPE LANG : SOURCE
|
protected ShaderNodeVariable |
readVariable(Statement statement)
reads a variable declaration statement <glslType> <varName>
|
void |
readVertexShaderNodes(java.util.List<Statement> statements)
reads the VertexShaderNodes{} block
|
void |
setAssetManager(AssetManager assetManager)
sets the assetManager
|
void |
setMaterialDef(MaterialDef materialDef)
sets the material def currently being loaded
|
void |
setTechniqueDef(TechniqueDef techniqueDef)
Sets the technique definition currently being loaded
|
void |
storeAttribute(ShaderNodeVariable var)
Stores an attribute.
|
void |
storeFragmentUniform(ShaderNodeVariable var)
store a fragment uniform
|
void |
storeGlobal(ShaderNodeVariable var,
Statement varStatement)
Stores a global output.
|
void |
storeVariable(ShaderNodeVariable variable,
java.util.List<ShaderNodeVariable> varList)
Searches a variable in a list from its name and merges the conditions of the
variables.
|
void |
storeVaryings(ShaderNode node,
ShaderNodeVariable variable)
store a varying
|
void |
storeVertexUniform(ShaderNodeVariable var)
Stores a vertex uniform.
|
boolean |
updateRightFromUniforms(MatParam param,
VariableMapping mapping,
java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> map,
Statement statement)
Updates the right variable of the given mapping from a
MatParam (a
WorldParam) it checks if the uniform hasn't already been loaded, add it
to the maps if not. |
protected boolean |
updateRightFromUniforms(UniformBinding param,
VariableMapping mapping,
java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> map)
updates the right variable of the given mapping from a UniformBinding (a
WorldParam) it checks if the uniform hasn't already been loaded, add it
to the maps if not.
|
protected void |
updateRightTypeFromLeftType(VariableMapping mapping)
Updates the type of the right variable of a mapping from the type of the
left variable.
|
void |
updateVarFromAttributes(ShaderNodeVariable right,
VariableMapping mapping)
Updates a variable from the attribute list.
|
protected boolean |
updateVariableFromList(ShaderNodeVariable var,
java.util.List<ShaderNodeVariable> list)
Searches a variable in the given list and updates its type and namespace.
|
protected java.util.Map<java.lang.String,ShaderNodeDefinition> nodeDefinitions
protected java.util.Map<java.lang.String,ShaderNode> nodes
protected ShaderNodeDefinition shaderNodeDefinition
protected ShaderNode shaderNode
protected TechniqueDef techniqueDef
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> attributes
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> vertexDeclaredUniforms
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> fragmentDeclaredUniforms
protected java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> varyings
protected MaterialDef materialDef
protected java.lang.String shaderLanguage
protected java.lang.String shaderName
protected java.util.Set<java.lang.String> varNames
protected AssetManager assetManager
protected ConditionParser conditionParser
protected java.util.List<java.lang.String> nulledConditions
public java.util.List<ShaderNodeDefinition> readNodesDefinitions(java.util.List<Statement> statements, ShaderNodeDefinitionKey key) throws java.io.IOException
statements
- the list statements to parsekey
- the ShaderNodeDefinitionKeyjava.io.IOException
public void readNodesDefinitions(java.util.List<Statement> statements) throws java.io.IOException
statements
- the list of statements to parsejava.io.IOException
protected void readShaderNodeDefinition(java.util.List<Statement> statements, ShaderNodeDefinitionKey key) throws java.io.IOException
statements
- the list of statements to parsekey
- the ShaderNodeDefinitionKeyjava.io.IOException
protected ShaderNodeVariable readVariable(Statement statement) throws java.io.IOException
statement
- the statement to parsejava.io.IOException
public void readVertexShaderNodes(java.util.List<Statement> statements) throws java.io.IOException
statements
- the list of statements to parsejava.io.IOException
protected void readShaderNode(java.util.List<Statement> statements) throws java.io.IOException
statements
- the list of statements to parsejava.io.IOException
protected VariableMapping parseMapping(Statement statement, boolean[] hasNameSpace) throws MatParseException
Format variable to variable: <nameSpace>.<varName>[.<swizzling>] = <nameSpace>.<varName>[.<swizzling>][:Condition] Format expression to variable: <nameSpace>.<varName>[.<swizzling>] = %% expression %% [:Condition]
statement
- the statement to read.MatParseException
- if the statement isn't valid.public void readFragmentShaderNodes(java.util.List<Statement> statements) throws java.io.IOException
statements
- the list of statements to parsejava.io.IOException
protected void readShaderStatement(Statement statement) throws java.io.IOException
statement
- java.io.IOException
public void setTechniqueDef(TechniqueDef techniqueDef)
techniqueDef
- the technique defpublic void setMaterialDef(MaterialDef materialDef)
materialDef
- protected boolean updateVariableFromList(ShaderNodeVariable var, java.util.List<ShaderNodeVariable> list)
var
- the variable to update.list
- the variables list.protected void updateRightTypeFromLeftType(VariableMapping mapping)
mapping
- the mapping to consider.protected void checkMappingFormat(java.lang.String[] vars, Statement statement) throws MatParseException
vars
- the array.statement
- the statement.MatParseException
- if the array isn't correct.protected MatParam findMatParam(java.lang.String varName)
MatParam
in the MaterialDef
from the given name.varName
- the material param name.MatParam
or null.protected UniformBinding findWorldParam(java.lang.String varName)
varName
- the name of the WorldParamprotected boolean updateRightFromUniforms(UniformBinding param, VariableMapping mapping, java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> map)
param
- the WorldParam UniformBindingmapping
- the mappingmap
- the map of uniforms to search intopublic boolean updateRightFromUniforms(MatParam param, VariableMapping mapping, java.util.Map<java.lang.String,ShaderNodeLoaderDelegate.DeclaredVariable> map, Statement statement) throws MatParseException
MatParam
(a
WorldParam) it checks if the uniform hasn't already been loaded, add it
to the maps if not.param
- the mat param.mapping
- the mapping.map
- the map of uniforms to search into.MatParseException
public void updateVarFromAttributes(ShaderNodeVariable right, VariableMapping mapping)
right
- the variablemapping
- the mappingpublic void addDefine(java.lang.String paramName, VarType paramType)
paramName
- public ShaderNodeVariable findNodeOutput(java.util.List<ShaderNodeVariable> vars, java.lang.String rightVarName)
vars
- the list of shader node variables.rightVarName
- the variable name to search for.public void extractCondition(java.lang.String condition, Statement statement) throws MatParseException
condition
- the condition expression.statement
- the statement being read.MatParseException
- if the condition isn't valid.public VariableMapping readInputMapping(Statement statement) throws MatParseException
statement
- the statement being read.MatParseException
- if we have a problem with parsing input mapping statement.public VariableMapping readOutputMapping(Statement statement) throws MatParseException
statement
- the statement being read.MatParseException
- if we have a problem with parsing the statement.public void readNodes(java.util.List<Statement> statements) throws java.io.IOException
statements
- the list of statements to readjava.io.IOException
public java.lang.String fixSamplerType(java.lang.String leftType, java.lang.String rightType)
leftType
- the left samplerTyperightType
- the right sampler type (can be multiple types separated
by "|"public void storeGlobal(ShaderNodeVariable var, Statement varStatement) throws MatParseException
var
- the variable to store.varStatement
- the statement being read.MatParseException
- if we have duplicates of a global vertex output variable.public void storeAttribute(ShaderNodeVariable var)
var
- the variable to store.public void storeVertexUniform(ShaderNodeVariable var)
var
- the variable to store.public void storeFragmentUniform(ShaderNodeVariable var)
var
- the variable to storepublic void setAssetManager(AssetManager assetManager)
assetManager
- public ShaderNodeDefinition findDefinition(Statement statement) throws java.io.IOException
statement
- the statement being readjava.io.IOException
public void storeVaryings(ShaderNode node, ShaderNodeVariable variable)
node
- the shaderNodevariable
- the variable to storepublic java.lang.String mergeConditions(java.lang.String condition1, java.lang.String condition2, java.lang.String operator)
condition1
- the first conditioncondition2
- the second conditionoperator
- the operator ("&&" or "||&)public void storeVariable(ShaderNodeVariable variable, java.util.List<ShaderNodeVariable> varList)
variable
- the variable.varList
- the variable list.protected void checkTypes(VariableMapping mapping, Statement statement1) throws MatParseException
mapping
- the mappingstatement1
- the statement being readMatParseException
public void clear()