HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CustomNodeMdl.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_CUSTOMNODEMDL_H
7 #define MATERIALX_CUSTOMNODEMDL_H
8 
10 
12 
13 class MdlSyntax;
14 class NodeDef;
15 
16 /// Node to handle user defined implementations in external MDL files or using the inline `sourcecode` attribute.
18 {
19  public:
20  static ShaderNodeImplPtr create();
21  void initialize(const InterfaceElement& element, GenContext& context) override;
22  void emitFunctionDefinition(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
23 
24  /// Get the MDL qualified name of the externally references user module.
25  /// It's used for import statements and functions calls in the generated target code.
26  const string& getQualifiedModuleName() const;
27 
28  /// To avoid collisions with reserved names in MDL, input and output names are prefixed.
29  /// In the `sourcecode` case all inputs and outputs are prefixed so authors don't need knowledge about reserved words in MDL.
30  /// In the `file` and `function` case, only reserved names are prefixed to support existing MDL implementations without changes.
31  string modifyPortName(const string& name, const MdlSyntax& syntax) const;
32 
33  protected:
34  /// Initialize function for nodes that use the inline `sourcecode` attribute.
35  void initializeForInlineSourceCode(const InterfaceElement& element, GenContext& context);
36 
37  /// Initialize function for nodes that use the `file` and `function` attribute.
38  void initializeForExternalSourceCode(const InterfaceElement& element, GenContext& context);
39 
40  /// Computes the function call string with replacement markers use by base class.
41  void initializeFunctionCallTemplateString(const MdlSyntax& syntax, const NodeDef& node);
42 
43  /// Keep track of the default values needed for the inline `sourcecode` case.
44  void initializeOutputDefaults(const MdlSyntax& syntax, const NodeDef& node);
45 
46  std::vector<ValuePtr> _outputDefaults; ///< store default values of the node definition
47 
48  bool _useExternalSourceCode; // Indicates that `file` and `function` are used by this node implementation
49  string _inlineFunctionName; // Name of the functionDefinition to emit
50  string _inlineSourceCode; // The actual inline source code
51  string _qualifiedModuleName; // MDL qualified name derived from the `file` attribute
52 };
53 
55 
56 #endif
string _inlineFunctionName
Definition: CustomNodeMdl.h:49
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:39
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
#define MX_GENMDL_API
Definition: Export.h:18
static ShaderNodeImplPtr create()
string _qualifiedModuleName
Definition: CustomNodeMdl.h:51
void emitFunctionDefinition(const ShaderNode &, GenContext &, ShaderStage &) const override
Emit function definition for the given node instance.
void initialize(const InterfaceElement &element, GenContext &context) override
GLuint const GLchar * name
Definition: glcorearb.h:786
std::vector< ValuePtr > _outputDefaults
store default values of the node definition
Definition: CustomNodeMdl.h:46
string _inlineSourceCode
Definition: CustomNodeMdl.h:50
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
Node to handle user defined implementations in external MDL files or using the inline sourcecode attr...
Definition: CustomNodeMdl.h:17