HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShaderNodeImpl.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_SHADERNODEIMPL_H
7 #define MATERIALX_SHADERNODEIMPL_H
8 
9 /// @file
10 /// Base class for shader node implementations
11 
13 
15 #include <MaterialXCore/Util.h>
16 
18 
19 class InterfaceElement;
20 class Node;
22 
23 /// Shared pointer to a ShaderNodeImpl
24 using ShaderNodeImplPtr = shared_ptr<class ShaderNodeImpl>;
25 
26 /// @class ShaderNodeImpl
27 /// Class handling the shader generation implementation for a node.
28 /// Responsible for emitting the function definition and function call
29 /// that is the node implementation.
31 {
32  public:
33  virtual ~ShaderNodeImpl() { }
34 
35  /// Return an identifier for the target used by this implementation.
36  /// By default an empty string is returned, representing all targets.
37  /// Only override this method if your derived node implementation class
38  /// is for a specific target.
39  virtual const string& getTarget() const { return EMPTY_STRING; }
40 
41  /// Initialize with the given implementation element.
42  /// Initialization must set the name and hash for the implementation,
43  /// as well as any other data needed to emit code for the node.
44  virtual void initialize(const InterfaceElement& element, GenContext& context);
45 
46  /// Return the name of this implementation.
47  const string& getName() const
48  {
49  return _name;
50  }
51 
52  /// Return a hash for this implementation.
53  /// The hash should correspond to the function signature generated for the node,
54  /// and can be used to compare implementations, e.g. to query if an identical
55  /// function has already been emitted during shader generation.
56  size_t getHash() const
57  {
58  return _hash;
59  }
60 
61  /// Add additional inputs on a node.
62  virtual void addInputs(ShaderNode& node, GenContext& context) const;
63 
64  /// Set values for additional inputs on a node.
65  virtual void setValues(const Node& node, ShaderNode& shaderNode, GenContext& context) const;
66 
67  /// Add additional classifications on a node.
68  virtual void addClassification(ShaderNode& node) const;
69 
70  /// Create shader variables needed for the implementation of this node (e.g. uniforms, inputs and outputs).
71  /// Used if the node requires input data from the application.
72  virtual void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const;
73 
74  /// Emit function definition for the given node instance.
75  virtual void emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
76 
77  /// Emit the function call or inline source code for given node instance in the given context.
78  virtual void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
79 
80  /// Emit declaration and initialization of output variables to use in a function call.
81  virtual void emitOutputVariables(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
82 
83  /// Return a pointer to the graph if this implementation is using a graph,
84  /// or returns nullptr otherwise.
85  virtual ShaderGraph* getGraph() const;
86 
87  /// Returns true if an input is editable by users.
88  /// Editable inputs are allowed to be published as shader uniforms
89  /// and hence must be presentable in a user interface.
90  /// By default all inputs are considered to be editable.
91  virtual bool isEditable(const ShaderInput& /*input*/) const
92  {
93  return true;
94  }
95 
96  /// Returns true if a graph input is accessible by users.
97  /// Accessible inputs are allowed to be published as shader uniforms
98  /// and hence must be presentable in a user interface.
99  /// By default all graph inputs are considered to be acessible.
100  virtual bool isEditable(const ShaderGraphInputSocket& /*input*/) const
101  {
102  return true;
103  }
104 
105  protected:
106  /// Protected constructor
107  ShaderNodeImpl();
108 
109  protected:
110  string _name;
111  size_t _hash;
112 };
113 
114 /// A no operation node, to be used for organizational nodes that has no code to execute.
116 {
117  public:
118  static ShaderNodeImplPtr create();
119 };
120 
122 
123 #endif
virtual bool isEditable(const ShaderGraphInputSocket &) const
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
Definition: Node.h:52
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
#define MX_GENSHADER_API
Definition: Export.h:18
virtual bool isEditable(const ShaderInput &) const
A no operation node, to be used for organizational nodes that has no code to execute.
virtual ~ShaderNodeImpl()
size_t getHash() const
virtual const string & getTarget() const
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
const string & getName() const
Return the name of this implementation.
GLuint shader
Definition: glcorearb.h:785
Definition: Shader.h:32
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26