6 #ifndef MATERIALX_SHADERSTAGE_H
7 #define MATERIALX_SHADERSTAGE_H
27 #define DEFINE_SHADER_STAGE(stage, name) if (stage.getName() == name)
30 #define BEGIN_SHADER_STAGE(stage, name) \
31 if (stage.getName() == name) \
33 #define END_SHADER_STAGE(stage, name) }
70 const string&
getName()
const {
return _name; }
79 void setInstance(
const string& instance) { _instance = instance; }
82 bool empty()
const {
return _variableOrder.empty(); }
85 size_t size()
const {
return _variableOrder.size(); }
131 std::unordered_map<string, ShaderPortPtr> _variableMap;
132 vector<ShaderPort*> _variableOrder;
155 const string&
getName()
const {
return _name; }
226 return _sourceDependencies;
233 void endScope(
bool semicolon =
false,
bool newline =
true);
239 void endLine(
bool semicolon =
true);
245 void addString(
const string& str);
248 void addLine(
const string& str,
bool semicolon =
true);
251 void addComment(
const string& str);
254 void addBlock(
const string& str,
const FilePath& sourceFilename,
GenContext& context);
260 void addSourceDependency(
const FilePath& file);
263 template <
typename T>
286 _functionName = functionName;
294 string _functionName;
303 vector<Scope> _scopes;
312 std::set<size_t> _definedFunctions;
342 return uniforms.
add(type, name);
350 bool shouldWiden =
false)
353 return inputs.
add(type, name, {}, shouldWiden);
361 bool shouldWiden =
false)
364 return outputs.
add(type, name, {}, shouldWiden);
369 const string& instance,
383 bool shouldWiden =
false)
void addStageConnectorBlock(const string &block, const string &instance, ShaderStage &from, ShaderStage &to)
Utility function for adding a connector block between stages.
ShaderPort * addStageInput(const string &block, const TypeDesc *type, const string &name, ShaderStage &stage, bool shouldWiden=false)
Utility function for adding a new shader port to an input block.
void addValue(const T &value)
Add a value.
#define MATERIALX_NAMESPACE_BEGIN
GLsizei const GLfloat * value
bool empty() const
Return true if the block has no variables.
ShaderPort * addStageUniform(const string &block, const TypeDesc *type, const string &name, ShaderStage &stage)
Utility function for adding a new shader port to a uniform block.
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
VariableBlockPtr createOutputBlock(const string &name, const string &instance=EMPTY_STRING)
Create a new output variable block.
shared_ptr< const Syntax > ConstSyntaxPtr
Shared pointer to a constant Syntax.
const VariableBlockMap & getOutputBlocks() const
Return a map of all output blocks.
const VariableBlockMap & getInputBlocks() const
Return a map of all input blocks.
const string & getName() const
Return the stage name.
void setSourceCode(const string &code)
Set the stage source code.
std::shared_ptr< VariableBlock > VariableBlockPtr
Shared pointer to a VariableBlock.
ShaderPort * addStageOutput(const string &block, const TypeDesc *type, const string &name, ShaderStage &stage, bool shouldWiden=false)
Utility function for adding a new shader port to an output block.
const string & getName() const
Get the name of this block.
std::function< bool(ShaderPort *)> ShaderPortPredicate
A standard function predicate taking an ShaderPort pointer and returning a boolean.
Scope(Syntax::Punctuation p)
std::unordered_map< string, VariableBlockPtr > VariableBlockMap
Shared pointer to a map between string identifiers and VariableBlocks.
VariableBlock & getInputBlock(const string &name)
Return the input variable block with given name.
void addStageConnector(const string &block, const TypeDesc *type, const string &name, ShaderStage &from, ShaderStage &to, bool shouldWiden=false)
Utility function for adding a variable to a stage connector block.
ShaderPort * add(const TypeDesc *type, const string &name, ValuePtr value=nullptr, bool shouldWiden=false)
ShaderPort * operator[](size_t index)
Return a variable by index.
const StringSet & getIncludes() const
Return a set of all include files.
GLuint const GLchar * name
void setFunctionName(const string &functionName)
Set stage function name.
MX_GENSHADER_API const string PIXEL
Syntax::Punctuation punctuation
const vector< ShaderPort * > & getVariableOrder() const
Return a const reference to our variable order vector.
std::set< FunctionCallId > functions
size_t size() const
Return the number of variables in this block.
void setInstance(const string &instance)
Set the instance name of this block.
shared_ptr< ShaderStage > ShaderStagePtr
Shared pointer to a ShaderStage.
Punctuation
Punctuation types.
const VariableBlockMap & getUniformBlocks() const
Return a map of all uniform blocks.
void setName(const string &name)
Set the name of this block.
shared_ptr< class ShaderPort > ShaderPortPtr
Shared pointer to a ShaderPort.
VariableBlock & getUniformBlock(const string &name)
Return the uniform variable block with given name.
const ShaderPort * operator[](size_t index) const
Return a variable by index.
std::set< string > StringSet
A set of strings.
#define MATERIALX_NAMESPACE_END
VariableBlock & getOutputBlock(const string &name)
Return the output variable block with given name.
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
const string & getFunctionName() const
Return the stage function name.
std::pair< const ShaderNode *, int > FunctionCallId
std::stringstream StringStream
A string stream.
const string & getInstance() const
Get the instance name of this block.
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
const StringSet & getSourceDependencies() const
Return a set of all source dependencies.
VariableBlockPtr createInputBlock(const string &name, const string &instance=EMPTY_STRING)
Create a new input variable block.
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
const string & getSourceCode() const
Return the stage source code.
VariableBlock(const string &name, const string &instance)