MaterialX 1.38.2
Shader.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_SHADER_H
7#define MATERIALX_SHADER_H
8
11
13
17
18namespace MaterialX
19{
20
21class ShaderGenerator;
22class Shader;
23
33class MX_GENSHADER_API Shader
34{
35 public:
37 Shader(const string& name, ShaderGraphPtr graph);
38
40 virtual ~Shader() { }
41
43 const string& getName() const { return _name; }
44
46 size_t numStages() const { return _stages.size(); }
47
49 ShaderStage& getStage(size_t index);
50
52 const ShaderStage& getStage(size_t index) const;
53
55 bool hasStage(const string& name);
56
58 ShaderStage& getStage(const string& name);
59
61 const ShaderStage& getStage(const string& name) const;
62
64 bool hasAttribute(const string& attrib) const
65 {
66 return _attributeMap.count(attrib) != 0;
67 }
68
71 ValuePtr getAttribute(const string& attrib) const
72 {
73 auto it = _attributeMap.find(attrib);
74 return it != _attributeMap.end() ? it->second : nullptr;
75 }
76
78 void setAttribute(const string& attrib, ValuePtr value)
79 {
80 _attributeMap[attrib] = value;
81 }
82
84 void setAttribute(const string& attrib)
85 {
86 _attributeMap[attrib] = Value::createValue<bool>(true);
87 }
88
90 const ShaderGraph& getGraph() const { return *_graph; }
91
93 ShaderGraph& getGraph() { return *_graph; }
94
96 bool hasClassification(unsigned int c) const { return _graph->hasClassification(c); }
97
99 const string& getSourceCode(const string& stage = Stage::PIXEL) const { return getStage(stage).getSourceCode(); }
100
101 protected:
103 ShaderStagePtr createStage(const string& name, ConstSyntaxPtr syntax);
104
105 string _name;
106 ShaderGraphPtr _graph;
107 std::unordered_map<string, ShaderStagePtr> _stagesMap;
108 vector<ShaderStage*> _stages;
109 std::unordered_map<string, ValuePtr> _attributeMap;
110
111 friend class ShaderGenerator;
112};
113
114} // namespace MaterialX
115
116#endif
Shader generation options class.
Macros for declaring imported and exported symbols.
shared_ptr< ShaderStage > ShaderStagePtr
Shared pointer to a ShaderStage.
Definition: Library.h:36
Shader graph class.
shared_ptr< class ShaderGraph > ShaderGraphPtr
A shared pointer to a shader graph.
Definition: ShaderGraph.h:40
Class related to holding information for shader stages.
shared_ptr< const Syntax > ConstSyntaxPtr
Shared pointer to a constant Syntax.
Definition: Syntax.h:28
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:30
Base class for shader generators All third-party shader generators should derive from this class.
Definition: ShaderGenerator.h:30
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:45
Class containing all data needed during shader generation.
Definition: Shader.h:34
void setAttribute(const string &attrib)
Set a flag attribute on the shader.
Definition: Shader.h:84
const ShaderGraph & getGraph() const
Return the shader graph.
Definition: Shader.h:90
size_t numStages() const
Return the number of shader stages for this shader.
Definition: Shader.h:46
bool hasClassification(unsigned int c) const
Return true if this shader matches the given classification.
Definition: Shader.h:96
const string & getName() const
Return the shader name.
Definition: Shader.h:43
virtual ~Shader()
Destructor.
Definition: Shader.h:40
void setAttribute(const string &attrib, ValuePtr value)
Set a value attribute on the shader.
Definition: Shader.h:78
const string & getSourceCode(const string &stage=Stage::PIXEL) const
Return the final shader source code for a given shader stage.
Definition: Shader.h:99
ShaderGraph & getGraph()
Return the shader graph.
Definition: Shader.h:93
ValuePtr getAttribute(const string &attrib) const
Return the value for a named attribute, or nullptr if no such attribute is found.
Definition: Shader.h:71
bool hasAttribute(const string &attrib) const
Return true if the shader has a given named attribute.
Definition: Shader.h:64
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:124