MaterialX 1.38.2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
EsslShaderGenerator Class Reference

An ESSL (OpenGL ES Shading Language) shader generator
More...

#include <EsslShaderGenerator.h>

Inheritance diagram for EsslShaderGenerator:
GlslShaderGenerator HwShaderGenerator ShaderGenerator

Public Member Functions

const string & getTarget () const override
 Return a unique identifier for the target this generator is for. More...
 
const string & getVersion () const override
 Return the version string for the ESSL version this generator is for. More...
 
const string getVertexDataPrefix (const VariableBlock &vertexData) const override
 Determine the prefix of vertex data variables. More...
 
- Public Member Functions inherited from GlslShaderGenerator
ShaderPtr generate (const string &name, ElementPtr element, GenContext &context) const override
 Generate a shader starting from the given element, translating the element and all dependencies upstream into shader code. More...
 
const string & getTarget () const override
 Return a unique identifier for the target this generator is for. More...
 
virtual const string & getVersion () const
 Return the version string for the GLSL version this generator is for. More...
 
void emitFunctionDefinitions (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const override
 Emit function definitions for all nodes. More...
 
void emitFunctionCalls (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const override
 Emit all function calls constructing the shader body. More...
 
void emitVariableDeclaration (const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const override
 Emit a shader variable. More...
 
virtual const string getVertexDataPrefix (const VariableBlock &vertexData) const
 Determine the prefix of vertex data variables. More...
 
- Public Member Functions inherited from HwShaderGenerator
void emitFunctionCall (const ShaderNode &node, GenContext &context, ShaderStage &stage, bool checkScope=true) const override
 Add the function call for a single node. More...
 
virtual void emitTextureNodes (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 Emit code for all texturing nodes.
 
virtual void emitBsdfNodes (const ShaderGraph &graph, const ShaderNode &shaderNode, HwClosureContextPtr ccx, GenContext &context, ShaderStage &stage, string &bsdf) const
 Emit code for calculating BSDF response for a shader, given the incident and outgoing light directions. More...
 
virtual void emitEdfNodes (const ShaderGraph &graph, const ShaderNode &shaderNode, HwClosureContextPtr ccx, GenContext &context, ShaderStage &stage, string &edf) const
 Emit code for calculating emission for a surface or light shader, given the normal direction of the EDF and the evaluation direction. More...
 
virtual void addStageLightingUniforms (GenContext &context, ShaderStage &stage) const
 Emit code for active light count definitions and uniforms.
 
void getNodeClosureContexts (const ShaderNode &node, vector< HwClosureContextPtr > &ccx) const
 Return the closure contexts defined for the given node.
 
- Public Member Functions inherited from ShaderGenerator
virtual ~ShaderGenerator ()
 Destructor.
 
virtual const string & getTarget () const =0
 Return the name of the target this generator is for. More...
 
virtual ShaderPtr generate (const string &name, ElementPtr element, GenContext &context) const =0
 Generate a shader starting from the given element, translating the element and all dependencies upstream into shader code. More...
 
virtual void emitScopeBegin (ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const
 Start a new scope using the given bracket type.
 
virtual void emitScopeEnd (ShaderStage &stage, bool semicolon=false, bool newline=true) const
 End the current scope.
 
virtual void emitLineBegin (ShaderStage &stage) const
 Start a new line.
 
virtual void emitLineEnd (ShaderStage &stage, bool semicolon=true) const
 End the current line.
 
virtual void emitLineBreak (ShaderStage &stage) const
 Add a line break.
 
virtual void emitString (const string &str, ShaderStage &stage) const
 Add a string.
 
virtual void emitLine (const string &str, ShaderStage &stage, bool semicolon=true) const
 Add a single line of code, optionally appending a semicolon.
 
virtual void emitComment (const string &str, ShaderStage &stage) const
 Add a single line code comment.
 
virtual void emitBlock (const string &str, GenContext &context, ShaderStage &stage) const
 Add a block of code.
 
virtual void emitInclude (const string &file, GenContext &context, ShaderStage &stage) const
 Add the contents of an include file. More...
 
template<typename T >
void emitValue (const T &value, ShaderStage &stage) const
 Add a value.
 
virtual void emitFunctionDefinition (const ShaderNode &node, GenContext &context, ShaderStage &stage) const
 Add the function definition for a single node.
 
virtual void emitFunctionCall (const ShaderNode &node, GenContext &context, ShaderStage &stage, bool checkScope=true) const
 Add the function call for a single node. More...
 
virtual void emitFunctionDefinitions (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 Add all function definitions for a graph. More...
 
virtual void emitFunctionCalls (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 Add all function calls for a graph. More...
 
virtual void emitTypeDefinitions (GenContext &context, ShaderStage &stage) const
 Emit type definitions for all data types that needs it.
 
virtual void emitInput (const ShaderInput *input, GenContext &context, ShaderStage &stage) const
 Emit the connected variable name for an input, or constant value if the port is not connected.
 
virtual void emitOutput (const ShaderOutput *output, bool includeType, bool assignValue, GenContext &context, ShaderStage &stage) const
 Emit the output variable name for an output, optionally including it's type and default value assignment.
 
virtual void emitVariableDeclarations (const VariableBlock &block, const string &qualifier, const string &separator, GenContext &context, ShaderStage &stage, bool assignValue=true) const
 Emit definitions for all shader variables in a block. More...
 
virtual void emitVariableDeclaration (const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const
 Emit definition of a single shader variable. More...
 
virtual string getUpstreamResult (const ShaderInput *input, GenContext &context) const
 Return the result of an upstream connection or value for an input. More...
 
const SyntaxgetSyntax () const
 Return the syntax object for the language used by the code generator.
 
void registerImplementation (const string &name, CreatorFunction< ShaderNodeImpl > creator)
 Register a shader node implementation for a given implementation element name.
 
bool implementationRegistered (const string &name) const
 Determine if a shader node implementation has been registered for a given implementation element name.
 
void setColorManagementSystem (ColorManagementSystemPtr colorManagementSystem)
 Sets the color management system.
 
ColorManagementSystemPtr getColorManagementSystem () const
 Returns the color management system.
 
void setUnitSystem (UnitSystemPtr unitSystem)
 Sets the unit system.
 
UnitSystemPtr getUnitSystem () const
 Returns the unit system.
 
ShaderNodeImplPtr getImplementation (const InterfaceElement &element, GenContext &context) const
 Return a registered shader node implementation given an implementation element. More...
 
const StringMapgetTokenSubstitutions () const
 Return the map of token substitutions used by the generator.
 
virtual void registerShaderMetadata (const DocumentPtr &doc, GenContext &context) const
 Register metadata that should be exported to the generated shaders. More...
 

Static Public Member Functions

static ShaderGeneratorPtr create ()
 
- Static Public Member Functions inherited from GlslShaderGenerator
static ShaderGeneratorPtr create ()
 
- Static Public Member Functions inherited from HwShaderGenerator
static void bindLightShader (const NodeDef &nodeDef, unsigned int lightTypeId, GenContext &context)
 Bind a light shader to a light type id, for usage in surface shaders created by the generator. More...
 
static void unbindLightShader (unsigned int lightTypeId, GenContext &context)
 Unbind a light shader previously bound to the given light type id.
 
static void unbindLightShaders (GenContext &context)
 Unbind all light shaders previously bound.
 

Static Public Attributes

static const string TARGET = "essl"
 Unique identifier for this generator target.
 
static const string VERSION = "300 es"
 
- Static Public Attributes inherited from GlslShaderGenerator
static const string TARGET = "genglsl"
 Unique identifier for this generator target.
 
static const string VERSION = "400"
 Version string for the generator target.
 
- Static Public Attributes inherited from HwShaderGenerator
static const string CLOSURE_CONTEXT_SUFFIX_REFLECTION
 String constants for closure context suffixes.
 
static const string CLOSURE_CONTEXT_SUFFIX_TRANSMISSIION
 
static const string CLOSURE_CONTEXT_SUFFIX_INDIRECT
 

Protected Member Functions

void emitDirectives (GenContext &context, ShaderStage &stage) const override
 
void emitUniforms (GenContext &context, ShaderStage &stage) const override
 
void emitInputs (GenContext &context, ShaderStage &stage) const override
 
void emitOutputs (GenContext &context, ShaderStage &stage) const override
 
HwResourceBindingContextPtr getResourceBindingContext (GenContext &context) const override
 
- Protected Member Functions inherited from GlslShaderGenerator
virtual void emitVertexStage (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 
virtual void emitPixelStage (const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
 
virtual void emitDirectives (GenContext &context, ShaderStage &stage) const
 
virtual void emitConstants (GenContext &context, ShaderStage &stage) const
 
virtual void emitUniforms (GenContext &context, ShaderStage &stage) const
 
virtual void emitLightData (GenContext &context, ShaderStage &stage) const
 
virtual void emitInputs (GenContext &context, ShaderStage &stage) const
 
virtual void emitOutputs (GenContext &context, ShaderStage &stage) const
 
virtual HwResourceBindingContextPtr getResourceBindingContext (GenContext &context) const
 
virtual bool requiresLighting (const ShaderGraph &graph) const
 Logic to indicate whether code to support direct lighting should be emitted. More...
 
virtual void emitSpecularEnvironment (GenContext &context, ShaderStage &stage) const
 Emit specular environment lookup code.
 
ShaderNodeImplPtr createCompoundImplementation (const NodeGraph &impl) const override
 Override the compound implementation creator in order to handle light compounds. More...
 
- Protected Member Functions inherited from HwShaderGenerator
 HwShaderGenerator (SyntaxPtr syntax)
 
virtual ShaderPtr createShader (const string &name, ElementPtr element, GenContext &context) const
 Create and initialize a new HW shader for shader generation.
 
ShaderNodeImplPtr createSourceCodeImplementation (const Implementation &impl) const override
 Override the source code implementation creator. More...
 
ShaderNodeImplPtr createCompoundImplementation (const NodeGraph &impl) const override
 Override the compound implementation creator. More...
 
- Protected Member Functions inherited from ShaderGenerator
 ShaderGenerator (SyntaxPtr syntax)
 Protected constructor.
 
virtual ShaderStagePtr createStage (const string &name, Shader &shader) const
 Create a new stage in a shader.
 
virtual ShaderNodeImplPtr createSourceCodeImplementation (const Implementation &impl) const
 Create a source code implementation which is the implementation class to use for nodes that has no specific C++ implementation registered for it. More...
 
virtual ShaderNodeImplPtr createCompoundImplementation (const NodeGraph &impl) const
 Create a compound implementation which is the implementation class to use for nodes using a nodegraph as their implementation. More...
 
virtual void finalizeShaderGraph (ShaderGraph &graph)
 Method called on all created shader graphs. More...
 
void setFunctionName (const string &functionName, ShaderStage &stage) const
 Set function name for a stage.
 
void replaceTokens (const StringMap &substitutions, ShaderStage &stage) const
 Replace tokens with identifiers according to the given substitutions map.
 

Additional Inherited Members

- Static Protected Member Functions inherited from GlslShaderGenerator
static void toVec4 (const TypeDesc *type, string &variable)
 
- Protected Attributes inherited from GlslShaderGenerator
vector< ShaderNodePtr_lightSamplingNodes
 Nodes used internally for light sampling.
 
- Protected Attributes inherited from HwShaderGenerator
HwClosureContextPtr _defReflection
 Closure contexts for defining closure functions.
 
HwClosureContextPtr _defTransmission
 
HwClosureContextPtr _defIndirect
 
HwClosureContextPtr _defEmission
 
- Protected Attributes inherited from ShaderGenerator
SyntaxPtr _syntax
 
Factory< ShaderNodeImpl_implFactory
 
ColorManagementSystemPtr _colorManagementSystem
 
UnitSystemPtr _unitSystem
 
StringMap _tokenSubstitutions
 
friend ShaderGraph
 
- Static Protected Attributes inherited from ShaderGenerator
static const string T_FILE_TRANSFORM_UV = "$fileTransformUv"
 

Detailed Description

An ESSL (OpenGL ES Shading Language) shader generator

Member Function Documentation

◆ emitDirectives()

void emitDirectives ( GenContext context,
ShaderStage stage 
) const
overrideprotectedvirtual

Reimplemented from GlslShaderGenerator.

◆ emitInputs()

void emitInputs ( GenContext context,
ShaderStage stage 
) const
overrideprotectedvirtual

Reimplemented from GlslShaderGenerator.

◆ emitOutputs()

void emitOutputs ( GenContext context,
ShaderStage stage 
) const
overrideprotectedvirtual

Reimplemented from GlslShaderGenerator.

◆ emitUniforms()

void emitUniforms ( GenContext context,
ShaderStage stage 
) const
overrideprotectedvirtual

Reimplemented from GlslShaderGenerator.

◆ getResourceBindingContext()

HwResourceBindingContextPtr getResourceBindingContext ( GenContext context) const
overrideprotectedvirtual

Reimplemented from GlslShaderGenerator.

◆ getTarget()

const string & getTarget ( ) const
inlineoverridevirtual

Return a unique identifier for the target this generator is for.

Implements ShaderGenerator.

◆ getVersion()

const string & getVersion ( ) const
inlineoverridevirtual

Return the version string for the ESSL version this generator is for.

Reimplemented from GlslShaderGenerator.

◆ getVertexDataPrefix()

const string getVertexDataPrefix ( const VariableBlock vertexData) const
overridevirtual

Determine the prefix of vertex data variables.

Reimplemented from GlslShaderGenerator.


The documentation for this class was generated from the following files: