6#ifndef MATERIALX_GENCONTEXT_H
7#define MATERIALX_GENCONTEXT_H
21MATERIALX_NAMESPACE_BEGIN
56 return _sg->getTypeSystem()->getType(name);
63 _sourceCodeSearchPath.append(path);
70 _sourceCodeSearchPath.append(path);
89 _reservedWords.insert(names.begin(), names.end());
96 return _reservedWords;
115 _parentNodes.push_back(node);
121 _parentNodes.pop_back();
134 auto it = _userData.find(name);
135 if (it != _userData.end())
137 it->second.push_back(data);
141 _userData[name] = { data };
148 auto it = _userData.find(name);
149 if (it != _userData.end())
151 it->second.pop_back();
163 auto it = _userData.find(name);
164 return it != _userData.end() && !it->second.empty() ? it->second.back()->asA<T>() :
nullptr;
198 _applicationVariableHandler = handler;
204 return _applicationVariableHandler;
215 std::unordered_map<string, ShaderNodeImplPtr> _nodeImpls;
216 std::unordered_map<string, vector<GenUserDataPtr>> _userData;
217 std::unordered_map<const ShaderInput*, string> _inputSuffix;
218 std::unordered_map<const ShaderOutput*, string> _outputSuffix;
220 vector<ConstNodePtr> _parentNodes;
240MATERIALX_NAMESPACE_END
Cross-platform support for file and search paths.
std::function< void(ShaderNode *, GenContext &)> ApplicationVariableHandler
A standard function to allow for handling of application variables for a given node.
Definition GenContext.h:24
Shader generation options class.
User data base class for shader generation.
std::shared_ptr< GenUserData > GenUserDataPtr
Shared pointer to a GenUserData.
Definition GenUserData.h:19
std::set< string > StringSet
A set of strings.
Definition Library.h:64
Macros for declaring imported and exported symbols.
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition Library.h:39
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition Library.h:37
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition Node.h:26
Base shader generator class.
Classes for nodes created during shader generation.
A generic file path, supporting both syntactic and file system operations.
Definition File.h:27
bool isEmpty() const
Return true if the given path is empty.
Definition File.h:92
FilePath getNormalized() const
Return a normalized version of the given path, collapsing current path and parent path references so ...
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition File.h:219
void prepend(const FilePath &path)
Prepend the given path to the sequence.
Definition File.h:274
FilePath find(const FilePath &filename) const
Given an input filename, iterate through each path in this sequence, returning the first combined pat...
Definition File.h:313
A context class for shader generation.
Definition GenContext.h:30
void registerSourceCodeSearchPath(const FilePath &path)
Register a user search path for finding source code during code generation.
Definition GenContext.h:61
void popParentNode()
Pop the current parent node from the stack.
Definition GenContext.h:119
GenOptions & getOptions()
Return shader generation options.
Definition GenContext.h:42
const vector< ConstNodePtr > & getParentNodes()
Return the current stack of parent nodes.
Definition GenContext.h:125
void setApplicationVariableHandler(ApplicationVariableHandler handler)
Set handler for application variables.
Definition GenContext.h:196
ShaderGenerator & getShaderGenerator()
Return shader generatior.
Definition GenContext.h:36
void getInputSuffix(const ShaderInput *input, string &suffix) const
Get an input suffix to be used for the input in this context.
void clearUserData()
Clear all user data from the context.
void clearNodeImplementations()
Clear all cached shader node implementation.
void popUserData(const string &name)
Remove user data from the context.
Definition GenContext.h:146
ShaderNodeImplPtr findNodeImplementation(const string &name) const
Find and return a cached shader node implementation, or return nullptr if no implementation is found.
void removeInputSuffix(const ShaderInput *input)
Remove an input suffix to be used for the input in this context.
void getNodeImplementationNames(StringSet &names)
Get the names of all cached node implementations.
void addInputSuffix(const ShaderInput *input, const string &suffix)
Add an input suffix to be used for the input in this context.
void addOutputSuffix(const ShaderOutput *output, const string &suffix)
Add an output suffix to be used for the output in this context.
void removeOutputSuffix(const ShaderOutput *output)
Remove an output suffix to be used for the output in this context.
void addNodeImplementation(const string &name, ShaderNodeImplPtr impl)
Cache a shader node implementation.
TypeDesc getTypeDesc(const string &name) const
Return a TypeDesc for the given type name.
Definition GenContext.h:54
void addReservedWords(const StringSet &names)
Add reserved words that should not be used as identifiers during code generation.
Definition GenContext.h:87
void pushUserData(const string &name, GenUserDataPtr data)
Add user data to the context to make it available during shader generator.
Definition GenContext.h:132
GenContext(ShaderGeneratorPtr sg)
Constructor.
void registerSourceCodeSearchPath(const FileSearchPath &path)
Register a user search path for finding source code during code generation.
Definition GenContext.h:68
FilePath resolveSourceFile(const FilePath &filename, const FilePath &localPath) const
Resolve a source code filename, first checking the given local path then checking any file paths regi...
Definition GenContext.h:75
ApplicationVariableHandler getApplicationVariableHandler() const
Get handler for application variables.
Definition GenContext.h:202
void pushParentNode(ConstNodePtr node)
Push a parent node onto the stack.
Definition GenContext.h:113
const GenOptions & getOptions() const
Return shader generation options.
Definition GenContext.h:48
void getOutputSuffix(const ShaderOutput *output, string &suffix) const
Get an output suffix to be used for the output in this context.
std::shared_ptr< T > getUserData(const string &name)
Return user data with given name, or nullptr if no data is found.
Definition GenContext.h:161
const StringSet & getReservedWords() const
Return the set of reserved words that should not be used as identifiers during code generation.
Definition GenContext.h:94
Class holding options to configure shader generation.
Definition GenOptions.h:76
~ScopedSetVariableName()
Destructor restoring the original variable name.
ScopedSetVariableName(const string &name, ShaderPort *port)
Constructor for setting a new variable name for a port.
Base class for shader generators All third-party shader generators should derive from this class.
Definition ShaderGenerator.h:31
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 type descriptor for MaterialX data types.
Definition TypeDesc.h:40