MaterialX 1.39.0
Loading...
Searching...
No Matches
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
11
13
16#include <MaterialXCore/Util.h>
17
18MATERIALX_NAMESPACE_BEGIN
19
21class Node;
23
25using ShaderNodeImplPtr = shared_ptr<class ShaderNodeImpl>;
26
31class MX_GENSHADER_API ShaderNodeImpl
32{
33 public:
34 virtual ~ShaderNodeImpl() { }
35
40 virtual const string& getTarget() const { return EMPTY_STRING; }
41
45 virtual void initialize(const InterfaceElement& element, GenContext& context);
46
48 const string& getName() const
49 {
50 return _name;
51 }
52
57 size_t getHash() const
58 {
59 return _hash;
60 }
61
63 virtual void addInputs(ShaderNode& node, GenContext& context) const;
64
66 virtual void setValues(const Node& node, ShaderNode& shaderNode, GenContext& context) const;
67
69 virtual void addClassification(ShaderNode& node) const;
70
73 virtual void createVariables(const ShaderNode& node, GenContext& context, Shader& shader) const;
74
76 virtual void emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
77
79 virtual void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
80
82 virtual void emitOutputVariables(const ShaderNode& node, GenContext& context, ShaderStage& stage) const;
83
86 virtual ShaderGraph* getGraph() const;
87
92 virtual bool isEditable(const ShaderInput& /*input*/) const
93 {
94 return true;
95 }
96
101 virtual bool isEditable(const ShaderGraphInputSocket& /*input*/) const
102 {
103 return true;
104 }
105
106 protected:
109
110 protected:
111 string _name;
112 size_t _hash;
113};
114
116class MX_GENSHADER_API NopNode : public ShaderNodeImpl
117{
118 public:
119 static ShaderNodeImplPtr create();
120};
121
122MATERIALX_NAMESPACE_END
123
124#endif
Utility methods.
Macros for declaring imported and exported symbols.
Library-wide includes and types.
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
shared_ptr< class ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: ShaderNodeImpl.h:25
Type descriptor for a MaterialX data type.
A context class for shader generation.
Definition: GenContext.h:31
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:286
A node element within a NodeGraph or Document.
Definition: Node.h:53
A no operation node, to be used for organizational nodes that has no code to execute.
Definition: ShaderNodeImpl.h:117
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:44
Class containing all data needed during shader generation.
Definition: Shader.h:33
An input on a ShaderNode.
Definition: ShaderNode.h:264
Class representing a node in the shader generation DAG.
Definition: ShaderNode.h:320
Class handling the shader generation implementation for a node.
Definition: ShaderNodeImpl.h:32
virtual void initialize(const InterfaceElement &element, GenContext &context)
Initialize with the given implementation element.
virtual bool isEditable(const ShaderInput &) const
Returns true if an input is editable by users.
Definition: ShaderNodeImpl.h:92
virtual void addInputs(ShaderNode &node, GenContext &context) const
Add additional inputs on a node.
virtual void createVariables(const ShaderNode &node, GenContext &context, Shader &shader) const
Create shader variables needed for the implementation of this node (e.g.
virtual bool isEditable(const ShaderGraphInputSocket &) const
Returns true if a graph input is accessible by users.
Definition: ShaderNodeImpl.h:101
const string & getName() const
Return the name of this implementation.
Definition: ShaderNodeImpl.h:48
virtual void emitOutputVariables(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Emit declaration and initialization of output variables to use in a function call.
virtual void setValues(const Node &node, ShaderNode &shaderNode, GenContext &context) const
Set values for additional inputs on a node.
virtual const string & getTarget() const
Return an identifier for the target used by this implementation.
Definition: ShaderNodeImpl.h:40
ShaderNodeImpl()
Protected constructor.
size_t getHash() const
Return a hash for this implementation.
Definition: ShaderNodeImpl.h:57
virtual void addClassification(ShaderNode &node) const
Add additional classifications on a node.
virtual void emitFunctionDefinition(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Emit function definition for the given node instance.
virtual void emitFunctionCall(const ShaderNode &node, GenContext &context, ShaderStage &stage) const
Emit the function call or inline source code for given node instance in the given context.
virtual ShaderGraph * getGraph() const
Return a pointer to the graph if this implementation is using a graph, or returns nullptr otherwise.
An output on a ShaderNode.
Definition: ShaderNode.h:295
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:139