MaterialX 1.39.2
Loading...
Searching...
No Matches
MdlSyntax.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_MDLSYNTAX_H
7#define MATERIALX_MDLSYNTAX_H
8
11
13
15
16MATERIALX_NAMESPACE_BEGIN
17
18class MdlSyntax;
19
21using MdlSyntaxPtr = shared_ptr<MdlSyntax>;
22
25class MX_GENMDL_API MdlSyntax : public Syntax
26{
27 public:
28 MdlSyntax();
29
30 static SyntaxPtr create() { return std::make_shared<MdlSyntax>(); }
31
32 const string& getConstantQualifier() const override { return CONST_QUALIFIER; };
33 const string& getUniformQualifier() const override { return UNIFORM_QUALIFIER; };
34 const string& getSourceFileExtension() const override { return SOURCE_FILE_EXTENSION; };
35
37 string getArrayTypeSuffix(TypeDesc type, const Value& value) const override;
38
40 string getArrayVariableSuffix(TypeDesc, const Value&) const override { return EMPTY_STRING; };
41
42 static const string CONST_QUALIFIER;
43 static const string UNIFORM_QUALIFIER;
44 static const string SOURCE_FILE_EXTENSION;
45 static const StringVec VECTOR2_MEMBERS;
46 static const StringVec VECTOR3_MEMBERS;
47 static const StringVec VECTOR4_MEMBERS;
48 static const StringVec COLOR3_MEMBERS;
49 static const StringVec COLOR4_MEMBERS;
50 static const StringVec ADDRESSMODE_MEMBERS;
51 static const StringVec COORDINATESPACE_MEMBERS;
52 static const StringVec FILTERLOOKUPMODE_MEMBERS;
53 static const StringVec FILTERTYPE_MEMBERS;
54 static const StringVec DISTRIBUTIONTYPE_MEMBERS;
55 static const StringVec SCATTER_MODE_MEMBERS;
56 static const string PORT_NAME_PREFIX; // Applied to input and output names to avoid collisions with reserved words in MDL
57
59 TypeDesc getEnumeratedType(const string& value) const;
60
63 bool remapEnumeration(const string& value, TypeDesc type, const string& enumNames, std::pair<TypeDesc, ValuePtr>& result) const override;
64
66 void makeValidName(string& name) const override;
67
69 string modifyPortName(const string& word) const;
70
73 string replaceSourceCodeMarkers(const string& nodeName, const string& soureCode, std::function<string(const string&)> lambda) const;
74
76 const string& getMdlVersionSuffixMarker() const;
77};
78
79namespace Type
80{
81
82TYPEDESC_DEFINE_TYPE(MDL_COORDINATESPACE, "coordinatespace", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
83TYPEDESC_DEFINE_TYPE(MDL_ADDRESSMODE, "addressmode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
84TYPEDESC_DEFINE_TYPE(MDL_FILTERLOOKUPMODE, "filterlookup", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
85TYPEDESC_DEFINE_TYPE(MDL_FILTERTYPE, "filtertype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
86TYPEDESC_DEFINE_TYPE(MDL_DISTRIBUTIONTYPE, "distributiontype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
87TYPEDESC_DEFINE_TYPE(MDL_SCATTER_MODE, "scatter_mode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
88
89} // namespace Type
90
91MATERIALX_NAMESPACE_END
92
93#endif
vector< string > StringVec
A vector of strings.
Definition Library.h:60
Macros for declaring imported and exported symbols.
shared_ptr< MdlSyntax > MdlSyntaxPtr
Shared pointer to an MdlSyntax.
Definition MdlSyntax.h:21
Base class for syntax handling for shader generators.
shared_ptr< Syntax > SyntaxPtr
Shared pointer to a Syntax.
Definition Syntax.h:28
#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size)
Macro to define global type descriptions for commonly used types.
Definition TypeDesc.h:192
Syntax class for MDL (Material Definition Language)
Definition MdlSyntax.h:26
string replaceSourceCodeMarkers(const string &nodeName, const string &soureCode, std::function< string(const string &)> lambda) const
Replaces all markers in a source code string indicated by {{...}}.
const string & getMdlVersionSuffixMarker() const
Get the MDL language versing marker: {{MDL_VERSION_SUFFIX}}.
bool remapEnumeration(const string &value, TypeDesc type, const string &enumNames, std::pair< TypeDesc, ValuePtr > &result) const override
Given an input specification attempt to remap this to an enumeration which is accepted by the shader ...
const string & getConstantQualifier() const override
Get the qualifier used when declaring constant variables.
Definition MdlSyntax.h:32
string modifyPortName(const string &word) const
To avoid collisions with reserved names in MDL, input and output names are prefixed.
const string & getUniformQualifier() const override
Get the qualifier used when declaring uniform variables.
Definition MdlSyntax.h:33
const string & getSourceFileExtension() const override
Return the file extension used for source code files in this language.
Definition MdlSyntax.h:34
string getArrayTypeSuffix(TypeDesc type, const Value &value) const override
Override to return array type suffix.
void makeValidName(string &name) const override
Modify the given name string to remove any invalid characters or tokens.
string getArrayVariableSuffix(TypeDesc, const Value &) const override
Override to indicate array variables have no array suffix.
Definition MdlSyntax.h:40
TypeDesc getEnumeratedType(const string &value) const
Get an type description for an enumeration based on member value.
Syntax()
Protected constructor.
A type descriptor for MaterialX data types.
Definition TypeDesc.h:36
A generic, discriminated value, whose type may be queried dynamically.
Definition Value.h:46