public abstract class ShaderGenerator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected AssetManager |
assetManager
the asset manager
|
protected int |
indent
indentation value for generation
|
static java.lang.String |
NAME_SPACE_GLOBAL |
static java.lang.String |
NAME_SPACE_MAT_PARAM |
static java.lang.String |
NAME_SPACE_VERTEX_ATTRIBUTE |
static java.lang.String |
NAME_SPACE_WORLD_PARAM |
protected TechniqueDef |
techniqueDef
the technique def to use for the shader generation
|
Modifier | Constructor and Description |
---|---|
protected |
ShaderGenerator(AssetManager assetManager)
Build a shaderGenerator
|
Modifier and Type | Method and Description |
---|---|
protected void |
appendNodeDeclarationAndMain(java.lang.String loadedSource,
java.lang.StringBuilder sourceDeclaration,
java.lang.StringBuilder source,
ShaderNode shaderNode,
ShaderGenerationInfo info,
java.lang.String shaderPath)
Appends declaration and main part of a node to the shader declaration and
main part.
|
protected java.lang.String |
buildShader(java.util.List<ShaderNode> shaderNodes,
ShaderGenerationInfo info,
Shader.ShaderType type)
This method is responsible for the shader generation.
|
protected int |
findShaderIndexFromVersion(ShaderNode shaderNode,
Shader.ShaderType type)
Returns the shader-path index according to the version of the generator.
|
protected abstract void |
generateAttributes(java.lang.StringBuilder source,
ShaderGenerationInfo info)
generates the attributes declaration for the vertex shader.
|
protected void |
generateDeclarationAndMainBody(java.util.List<ShaderNode> shaderNodes,
java.lang.StringBuilder sourceDeclaration,
java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
iterates through shader nodes to load them and generate the shader
declaration part and main body extracted from the shader nodes, for the
given shader type
|
protected abstract void |
generateDeclarativeSection(java.lang.StringBuilder source,
ShaderNode shaderNode,
java.lang.String nodeDeclarationSource,
ShaderGenerationInfo info)
Appends the given shaderNode declarative part to the shader declarative
part.
|
protected abstract void |
generateEndOfMainSection(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
Generates the end of the shader main section.
|
protected abstract 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.
|
Shader |
generateShader(java.lang.String definesSourceCode)
Generate vertex and fragment shaders for the given technique
|
protected abstract void |
generateStartOfMainSection(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the start of the shader main section.
|
protected abstract void |
generateUniforms(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the uniforms declaration for a shader of the given type.
|
protected abstract void |
generateVaryings(java.lang.StringBuilder source,
ShaderGenerationInfo info,
Shader.ShaderType type)
generates the varyings for the given shader type shader.
|
protected abstract 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.
|
void |
initialize(TechniqueDef techniqueDef) |
public static final java.lang.String NAME_SPACE_GLOBAL
public static final java.lang.String NAME_SPACE_VERTEX_ATTRIBUTE
public static final java.lang.String NAME_SPACE_MAT_PARAM
public static final java.lang.String NAME_SPACE_WORLD_PARAM
protected AssetManager assetManager
protected int indent
protected TechniqueDef techniqueDef
protected ShaderGenerator(AssetManager assetManager)
assetManager
- for loading assets (alias created)public void initialize(TechniqueDef techniqueDef)
public Shader generateShader(java.lang.String definesSourceCode)
definesSourceCode
- (may be null)protected java.lang.String buildShader(java.util.List<ShaderNode> shaderNodes, ShaderGenerationInfo info, Shader.ShaderType type)
shaderNodes
- the list of shader nodesinfo
- the ShaderGenerationInfo filled during the Technique loadingtype
- the type of shader to generateprotected void generateDeclarationAndMainBody(java.util.List<ShaderNode> shaderNodes, java.lang.StringBuilder sourceDeclaration, java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
shaderNodes
- the list of shader nodessourceDeclaration
- the declaration part StringBuilder of the shader
to generatesource
- the main part StringBuilder of the shader to generateinfo
- the ShaderGenerationInfotype
- the Shader typeprotected void appendNodeDeclarationAndMain(java.lang.String loadedSource, java.lang.StringBuilder sourceDeclaration, java.lang.StringBuilder source, ShaderNode shaderNode, ShaderGenerationInfo info, java.lang.String shaderPath)
loadedSource
- the actual source code loaded for this node.shaderPath
- path to the shader filesourceDeclaration
- the Shader declaration part string builder.source
- the Shader main part StringBuilder.shaderNode
- the shader node.info
- the ShaderGenerationInfo.generateDeclarativeSection(java.lang.StringBuilder, com.jme3.shader.ShaderNode, java.lang.String, com.jme3.material.ShaderGenerationInfo)
,
generateNodeMainSection(java.lang.StringBuilder, com.jme3.shader.ShaderNode, java.lang.String, com.jme3.material.ShaderGenerationInfo)
protected abstract java.lang.String getLanguageAndVersion(Shader.ShaderType type)
type
- the shader type for which the version should be returned.protected abstract void generateUniforms(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the uniforms have to be generated for.protected abstract void generateAttributes(java.lang.StringBuilder source, ShaderGenerationInfo info)
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.protected abstract void generateVaryings(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
source
- the source StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the varyings have to be generated for.protected abstract void generateDeclarativeSection(java.lang.StringBuilder source, ShaderNode shaderNode, java.lang.String nodeDeclarationSource, ShaderGenerationInfo info)
nodeDeclarationSource
- the declaration part of the nodesource
- the StringBuilder to append generated code.shaderNode
- the shaderNode.info
- the ShaderGenerationInfo.ShaderNode.getDefinition()
,
ShaderNodeDefinition.getType()
protected abstract void generateStartOfMainSection(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
source
- the StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the section has to be generated for.protected abstract void generateEndOfMainSection(java.lang.StringBuilder source, ShaderGenerationInfo info, Shader.ShaderType type)
source
- the StringBuilder to append generated code.info
- the ShaderGenerationInfo.type
- the shader type the section has to be generated for.protected abstract void generateNodeMainSection(java.lang.StringBuilder source, ShaderNode shaderNode, java.lang.String nodeSource, ShaderGenerationInfo info)
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 int findShaderIndexFromVersion(ShaderNode shaderNode, Shader.ShaderType type) throws java.lang.NumberFormatException
shaderNode
- the shaderNode being processedtype
- the shaderTypejava.lang.NumberFormatException
- for an invalid version