6 #ifndef MATERIALX_GENCONTEXT_H
7 #define MATERIALX_GENCONTEXT_H
58 _sourceCodeSearchPath.append(path);
65 _sourceCodeSearchPath.append(path);
84 _reservedWords.insert(names.begin(), names.end());
91 return _reservedWords;
102 void getNodeImplementationNames(
StringSet& names);
105 void clearNodeImplementations();
110 _closureContexts.push_back(cct);
116 if (_closureContexts.size())
118 _closureContexts.pop_back();
125 return _closureContexts.size() ? _closureContexts.back() :
nullptr;
131 _parentNodes.push_back(node);
137 _parentNodes.pop_back();
150 auto it = _userData.find(name);
151 if (it != _userData.end())
153 it->second.push_back(data);
157 _userData[
name] = { data };
164 auto it = _userData.find(name);
165 if (it != _userData.end())
167 it->second.pop_back();
172 void clearUserData();
179 auto it = _userData.find(name);
180 return it != _userData.end() && !it->second.empty() ? it->second.back()->asA<
T>() :
nullptr;
186 void addInputSuffix(
const ShaderInput* input,
const string& suffix);
195 void getInputSuffix(
const ShaderInput* input,
string& suffix)
const;
200 void addOutputSuffix(
const ShaderOutput* output,
const string& suffix);
209 void getOutputSuffix(
const ShaderOutput* output,
string& suffix)
const;
214 _applicationVariableHandler = handler;
220 return _applicationVariableHandler;
232 std::unordered_map<string, vector<GenUserDataPtr>>
_userData;
253 using Argument = std::pair<const TypeDesc*, string>;
270 _arguments[nodeType].push_back(arg);
276 auto it = _arguments.find(nodeType);
277 return it != _arguments.end() ? it->second : EMPTY_ARGUMENTS;
283 _suffix[nodeType] = suffix;
289 auto it = _suffix.find(nodeType);
298 _params[closure] =
params;
302 _params.erase(closure);
310 auto it = _params.find(closure);
311 return it != _params.end() ? it->second :
nullptr;
317 std::unordered_map<const TypeDesc*, string>
_suffix;
318 std::unordered_map<const ShaderNode*, const ClosureParams*>
_params;
360 #endif // MATERIALX_GENCONTEXT_H
FileSearchPath _sourceCodeSearchPath
vector< ConstNodePtr > _parentNodes
GT_API const UT_StringHolder filename
FilePath getNormalized() const
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
const vector< ConstNodePtr > & getParentNodes()
Return the current stack of parent nodes.
static const Arguments EMPTY_ARGUMENTS
#define MATERIALX_NAMESPACE_BEGIN
const Arguments & getArguments(const TypeDesc *nodeType) const
Return a list of extra argument to be used for the given node in this context.
A RAII class for overriding port variable names.
const StringSet & getReservedWords() const
ClosureContext(int type=0)
Constructor.
GLsizei const GLchar *const * path
void addReservedWords(const StringSet &names)
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
std::unordered_map< const ShaderInput *, string > _inputSuffix
std::function< void(ShaderNode *, GenContext &)> ApplicationVariableHandler
A standard function to allow for handling of application variables for a given node.
void popUserData(const string &name)
Remove user data from the context.
vector< ClosureContext * > _closureContexts
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
GLenum const GLfloat * params
const GenOptions & getOptions() const
Return shader generation options.
bool isEmpty() const
Return true if the given path is empty.
ShaderGenerator & getShaderGenerator()
Return shader generatior.
int getType() const
Return the identifier for this context.
std::unordered_map< string, ShaderNodeImplPtr > _nodeImpls
ApplicationVariableHandler getApplicationVariableHandler() const
Get handler for application variables.
std::shared_ptr< GenUserData > GenUserDataPtr
Shared pointer to a GenUserData.
std::pair< const TypeDesc *, string > Argument
ApplicationVariableHandler _applicationVariableHandler
GLuint const GLchar * name
std::unordered_map< string, vector< GenUserDataPtr > > _userData
std::shared_ptr< T > getUserData(const string &name)
const ClosureParams * getClosureParams(const ShaderNode *closure) const
std::unordered_map< string, const ShaderInput * > ClosureParams
Extra parameters for closure evaluation.
void registerSourceCodeSearchPath(const FileSearchPath &path)
void popClosureContext()
Pop the current closure context.
void popParentNode()
Pop the current parent node from the stack.
void pushUserData(const string &name, GenUserDataPtr data)
const string & getSuffix(const TypeDesc *nodeType) const
Return the function name suffix to be used for the given node in this context.
ClosureContext * getClosureContext()
Return the current closure context.
void setApplicationVariableHandler(ApplicationVariableHandler handler)
Set handler for application variables.
void prepend(const FilePath &path)
Prepend the given path to the sequence.
GenOptions & getOptions()
Return shader generation options.
FilePath resolveSourceFile(const FilePath &filename, const FilePath &localPath) const
vector< Argument > Arguments
An array of arguments.
void addArgument(const TypeDesc *nodeType, const Argument &arg)
For the given node type add an extra argument to be used for the function in this context...
std::unordered_map< const TypeDesc *, string > _suffix
std::unordered_map< const ShaderOutput *, string > _outputSuffix
FilePath find(const FilePath &filename) const
std::unordered_map< const ShaderNode *, const ClosureParams * > _params
std::set< string > StringSet
A set of strings.
void pushParentNode(ConstNodePtr node)
Push a parent node onto the stack.
#define MATERIALX_NAMESPACE_END
void pushClosureContext(ClosureContext *cct)
Push a new closure context to use for closure evaluation.
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
void setClosureParams(const ShaderNode *closure, const ClosureParams *params)
Set extra parameters to use for evaluating a closure.
void setSuffix(const TypeDesc *nodeType, const string &suffix)
For the given node type set a function name suffix to be used for the function in this context...
std::unordered_map< const TypeDesc *, Arguments > _arguments
void registerSourceCodeSearchPath(const FilePath &path)