6#ifndef MATERIALX_SHADERGENERATOR_H
7#define MATERIALX_SHADERGENERATOR_H
23MATERIALX_NAMESPACE_BEGIN
132 bool assignValue =
true)
const;
141 bool assignValue =
true)
const;
167 _colorManagementSystem = colorManagementSystem;
173 return _colorManagementSystem;
179 _unitSystem = unitSystem;
191 return _tokenSubstitutions;
226 static const string T_FILE_TRANSFORM_UV;
242 using Exception::Exception;
245MATERIALX_NAMESPACE_END
Color management system classes.
shared_ptr< class ColorManagementSystem > ColorManagementSystemPtr
A shared pointer to a ColorManagementSystem.
Definition: ColorManagementSystem.h:25
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Class instantiator factory helper class.
Cross-platform support for file and search paths.
vector< string > StringVec
A vector of strings.
Definition: Library.h:55
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition: Library.h:57
Macros for declaring imported and exported symbols.
shared_ptr< ShaderStage > ShaderStagePtr
Shared pointer to a ShaderStage.
Definition: Library.h:36
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
shared_ptr< class ShaderGraph > ShaderGraphPtr
A shared pointer to a shader graph.
Definition: ShaderGraph.h:39
Class related to holding information for shader stages.
Base class for syntax handling for shader generators.
shared_ptr< Syntax > SyntaxPtr
Shared pointer to a Syntax.
Definition: Syntax.h:27
shared_ptr< class UnitSystem > UnitSystemPtr
A shared pointer to a UnitSystem.
Definition: UnitSystem.h:26
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition: Exception.h:22
An exception that is thrown when shader generation fails.
Definition: ShaderGenerator.h:240
Factory class for creating instances of classes given their type name.
Definition: Factory.h:19
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:27
A context class for shader generation.
Definition: GenContext.h:31
A node definition element within a Document.
Definition: Definition.h:82
Base class for shader generators All third-party shader generators should derive from this class.
Definition: ShaderGenerator.h:31
virtual void emitScopeBegin(ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const
Start a new scope using the given bracket type.
bool implementationRegistered(const string &name) const
Determine if a shader node implementation has been registered for a given implementation element name...
virtual void emitVariableDeclaration(const ShaderPort *variable, const string &qualifier, GenContext &context, ShaderStage &stage, bool assignValue=true) const
Emit definition of a single shader variable.
virtual void emitDependentFunctionCalls(const ShaderNode &node, GenContext &context, ShaderStage &stage, uint32_t classification=0u) const
Add function calls for nodes connected directly upstream from the given node.
virtual void emitBlock(const string &str, const FilePath &sourceFilename, GenContext &context, ShaderStage &stage) const
Add a block of code.
void createVariables(ShaderGraphPtr graph, GenContext &context, Shader &shader) const
Create shader variables (e.g.
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.
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 assignm...
virtual void emitComment(const string &str, ShaderStage &stage) const
Add a single line code comment.
virtual void emitString(const string &str, ShaderStage &stage) const
Add a string.
ColorManagementSystemPtr getColorManagementSystem() const
Returns the color management system.
Definition: ShaderGenerator.h:171
virtual void getClosureContexts(const ShaderNode &node, vector< ClosureContext * > &cct) const
Return the closure contexts defined for the given node.
const StringMap & getTokenSubstitutions() const
Return the map of token substitutions used by the generator.
Definition: ShaderGenerator.h:189
virtual string getUpstreamResult(const ShaderInput *input, GenContext &context) const
Return the result of an upstream connection or value for an input.
void registerImplementation(const StringVec &nameVec, CreatorFunction< ShaderNodeImpl > creator)
Register a shader node implementation for a given set of implementation element names.
virtual void emitFunctionBodyBegin(const ShaderNode &node, GenContext &context, ShaderStage &stage, Syntax::Punctuation punc=Syntax::CURLY_BRACKETS) const
Emit code for starting a new function body.
void setUnitSystem(UnitSystemPtr unitSystem)
Sets the unit system.
Definition: ShaderGenerator.h:177
virtual void emitFunctionBodyEnd(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Emit code for ending a function body.
void registerImplementation(const string &name, CreatorFunction< ShaderNodeImpl > creator)
Register a shader node implementation for a given implementation element name.
virtual void emitLibraryInclude(const FilePath &filename, GenContext &context, ShaderStage &stage) const
Add the contents of a standard library include file if not already present.
virtual void registerShaderMetadata(const DocumentPtr &doc, GenContext &context) const
Register metadata that should be exported to the generated shaders.
virtual void emitTypeDefinitions(GenContext &context, ShaderStage &stage) const
Emit type definitions for all data types that needs it.
void emitValue(const T &value, ShaderStage &stage) const
Add a value.
Definition: ShaderGenerator.h:83
void replaceTokens(const StringMap &substitutions, ShaderStage &stage) const
Replace tokens with identifiers according to the given substitutions map.
virtual const string & getTarget() const
Return the name of the target this generator is for.
Definition: ShaderGenerator.h:37
virtual void emitFunctionCalls(const ShaderGraph &graph, GenContext &context, ShaderStage &stage, uint32_t classification=0u) const
Add all function calls for a graph.
virtual ShaderNodeImplPtr getImplementation(const NodeDef &nodedef, GenContext &context) const
Return a registered shader node implementation for the given nodedef.
virtual ShaderStagePtr createStage(const string &name, Shader &shader) const
Create a new stage in a shader.
virtual void emitLineBegin(ShaderStage &stage) const
Start a new line.
void setColorManagementSystem(ColorManagementSystemPtr colorManagementSystem)
Sets the color management system.
Definition: ShaderGenerator.h:165
const Syntax & getSyntax() const
Return the syntax object for the language used by the code generator.
Definition: ShaderGenerator.h:150
virtual void emitLine(const string &str, ShaderStage &stage, bool semicolon=true) const
Add a single line of code, optionally appending a semicolon.
virtual ~ShaderGenerator()
Destructor.
Definition: ShaderGenerator.h:34
virtual void emitFunctionDefinitions(const ShaderGraph &graph, GenContext &context, ShaderStage &stage) const
Add all function definitions for a graph.
virtual void emitLineBreak(ShaderStage &stage) const
Add a line break.
virtual void emitFunctionDefinition(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Add the function definition for a single node.
void setFunctionName(const string &functionName, ShaderStage &stage) const
Set function name for a stage.
Definition: ShaderGenerator.h:213
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 emitLineEnd(ShaderStage &stage, bool semicolon=true) const
End the current line.
UnitSystemPtr getUnitSystem() const
Returns the unit system.
Definition: ShaderGenerator.h:183
virtual void emitFunctionCall(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Add the function call for a single node.
virtual void emitScopeEnd(ShaderStage &stage, bool semicolon=false, bool newline=true) const
End the current scope.
ShaderGenerator(SyntaxPtr syntax)
Protected constructor.
virtual ShaderPtr generate(const string &, ElementPtr, GenContext &) const
Generate a shader starting from the given element, translating the element and all dependencies upstr...
Definition: ShaderGenerator.h:44
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:44
Class containing all data needed during shader generation.
Definition: Shader.h:33
Class representing a node in the shader generation DAG.
Definition: ShaderNode.h:320
An output on a ShaderNode.
Definition: ShaderNode.h:295
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:139
void setFunctionName(const string &functionName)
Set stage function name.
Definition: ShaderStage.h:287
void addValue(const T &value)
Add a value.
Definition: ShaderStage.h:267
Base class for syntax objects used by shader generators to emit code with correct syntax for each lan...
Definition: Syntax.h:41
Punctuation
Punctuation types.
Definition: Syntax.h:45
A block of variables in a shader stage.
Definition: ShaderStage.h:61