6#ifndef MATERIALX_SHADERGENERATOR_H
7#define MATERIALX_SHADERGENERATOR_H
23MATERIALX_NAMESPACE_BEGIN
135 bool assignValue =
true)
const;
144 bool assignValue =
true)
const;
170 _colorManagementSystem = colorManagementSystem;
176 return _colorManagementSystem;
182 _unitSystem = unitSystem;
200 return _tokenSubstitutions;
218 virtual const string& getLightDataTypevarString()
const {
return LIGHTDATA_TYPEVAR_STRING; }
241 static const string T_FILE_TRANSFORM_UV;
242 static const string LIGHTDATA_TYPEVAR_STRING;
244 TypeSystemPtr _typeSystem;
259 using Exception::Exception;
262MATERIALX_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:61
std::unordered_map< string, string > StringMap
An unordered map with strings as both keys and values.
Definition Library.h:63
Macros for declaring imported and exported symbols.
shared_ptr< ShaderStage > ShaderStagePtr
Shared pointer to a ShaderStage.
Definition Library.h:35
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition Library.h:33
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition Library.h:39
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:28
shared_ptr< class UnitSystem > UnitSystemPtr
A shared pointer to a UnitSystem.
Definition UnitSystem.h:26
An exception that is thrown when shader generation fails.
Definition ShaderGenerator.h:257
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:30
A node definition element within a Document.
Definition Definition.h:82
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:174
const StringMap & getTokenSubstitutions() const
Return the map of token substitutions used by the generator.
Definition ShaderGenerator.h:198
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:180
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.
ShaderGenerator(TypeSystemPtr typeSystem, SyntaxPtr syntax)
Protected constructor.
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.
TypeSystemPtr getTypeSystem() const
Returns the type system.
Definition ShaderGenerator.h:192
virtual void emitLineBegin(ShaderStage &stage) const
Start a new line.
void setColorManagementSystem(ColorManagementSystemPtr colorManagementSystem)
Sets the color management system.
Definition ShaderGenerator.h:168
const Syntax & getSyntax() const
Return the syntax object for the language used by the code generator.
Definition ShaderGenerator.h:153
virtual void emitLine(const string &str, ShaderStage &stage, bool semicolon=true) const
Add a single line of code, optionally appending a semicolon.
virtual bool nodeNeedsClosureData(const ShaderNode &) const
Return true if the node needs the additional ClosureData added.
Definition ShaderGenerator.h:147
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:228
virtual void registerTypeDefs(const DocumentPtr &doc)
Register type definitions from the document.
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:186
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.
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 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:141
void setFunctionName(const string &functionName)
Set stage function name.
Definition ShaderStage.h:289
void addValue(const T &value)
Add a value.
Definition ShaderStage.h:269
Base class for syntax objects used by shader generators to emit code with correct syntax for each lan...
Definition Syntax.h:44
Punctuation
Punctuation types.
Definition Syntax.h:48
A block of variables in a shader stage.
Definition ShaderStage.h:63