6 #ifndef MATERIALX_GENCONTEXT_H
7 #define MATERIALX_GENCONTEXT_H
54 _sourceCodeSearchPath.append(path);
60 _sourceCodeSearchPath.append(path);
66 return _sourceCodeSearchPath.find(filename);
73 _reservedWords.insert(names.begin(), names.end());
80 return _reservedWords;
94 void clearNodeImplementations();
99 _closureContexts.push_back(cct);
105 if (_closureContexts.size())
107 _closureContexts.pop_back();
114 return _closureContexts.size() ? _closureContexts.back() :
nullptr;
121 auto it = _userData.find(name);
122 if (it != _userData.end())
124 it->second.push_back(data);
128 _userData[
name] = { data };
135 auto it = _userData.find(name);
136 if (it != _userData.end())
138 it->second.pop_back();
143 void clearUserData();
150 auto it = _userData.find(name);
151 return it != _userData.end() && !it->second.empty() ? it->second.back()->asA<
T>() :
nullptr;
171 void addOutputSuffix(
const ShaderOutput* output,
const string& suffix);
180 void getOutputSuffix(
const ShaderOutput* output,
string& suffix)
const;
201 std::unordered_map<string, vector<GenUserDataPtr>>
_userData;
225 using Argument = std::pair<const TypeDesc*, string>;
241 _arguments[nodeType].push_back(arg);
247 auto it = _arguments.find(nodeType);
248 return it != _arguments.end() ? it->second : EMPTY_ARGUMENTS;
254 _suffix[nodeType] = suffix;
260 auto it = _suffix.find(nodeType);
269 _params[closure] =
params;
273 _params.erase(closure);
281 auto it = _params.find(closure);
282 return it != _params.end() ? it->second :
nullptr;
288 std::unordered_map<const TypeDesc*, string>
_suffix;
289 std::unordered_map<const ShaderNode*, const ClosureParams*>
_params;
331 #endif // MATERIALX_GENCONTEXT_H
FileSearchPath _sourceCodeSearchPath
GT_API const UT_StringHolder filename
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
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
GLenum GLenum GLenum input
void addReservedWords(const StringSet &names)
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
std::unordered_map< const ShaderInput *, string > _inputSuffix
GLuint const GLchar * name
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 >
const GenOptions & getOptions() const
Return shader generation options.
ShaderGenerator & getShaderGenerator()
Return shader generatior.
int getType() const
Return the identifier for this context.
std::unordered_map< string, ShaderNodeImplPtr > _nodeImpls
FilePath resolveSourceFile(const FilePath &filename) const
Resolve a file using the registered search paths.
std::shared_ptr< GenUserData > GenUserDataPtr
Shared pointer to a GenUserData.
std::pair< const TypeDesc *, string > Argument
GLuint const GLuint * names
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)
Add to the search path used for finding source code.
void popClosureContext()
Pop the current closure context.
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.
GenOptions & getOptions()
Return shader generation options.
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
std::unordered_map< const ShaderNode *, const ClosureParams * > _params
GLenum const GLfloat * params
std::set< string > StringSet
A set of strings.
#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)
Add to the search path used for finding source code.