MaterialX 1.39.4
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(TypeSystemPtr typeSystem);
29
30 static SyntaxPtr create(TypeSystemPtr typeSystem) { return std::make_shared<MdlSyntax>(typeSystem); }
31
32 StructTypeSyntaxPtr createStructSyntax(const string& structTypeName, const string& defaultValue,
33 const string& uniformDefaultValue, const string& typeAlias,
34 const string& typeDefinition) const override;
35
36 const string& getConstantQualifier() const override { return CONST_QUALIFIER; };
37 const string& getUniformQualifier() const override { return UNIFORM_QUALIFIER; };
38 const string& getSourceFileExtension() const override { return SOURCE_FILE_EXTENSION; };
39
41 string getArrayTypeSuffix(TypeDesc type, const Value& value) const override;
42
44 string getArrayVariableSuffix(TypeDesc, const Value&) const override { return EMPTY_STRING; };
45
46 static const string CONST_QUALIFIER;
47 static const string UNIFORM_QUALIFIER;
48 static const string SOURCE_FILE_EXTENSION;
49 static const StringVec VECTOR2_MEMBERS;
50 static const StringVec VECTOR3_MEMBERS;
51 static const StringVec VECTOR4_MEMBERS;
52 static const StringVec COLOR3_MEMBERS;
53 static const StringVec COLOR4_MEMBERS;
54 static const StringVec ADDRESSMODE_MEMBERS;
55 static const StringVec COORDINATESPACE_MEMBERS;
56 static const StringVec FILTERLOOKUPMODE_MEMBERS;
57 static const StringVec FILTERTYPE_MEMBERS;
58 static const StringVec DISTRIBUTIONTYPE_MEMBERS;
59 static const StringVec SCATTER_MODE_MEMBERS;
60 static const StringVec SHEEN_MODE_MEMBERS;
61 static const string PORT_NAME_PREFIX; // Applied to input and output names to avoid collisions with reserved words in MDL
62
64 TypeDesc getEnumeratedType(const string& value) const;
65
68 bool remapEnumeration(const string& value, TypeDesc type, const string& enumNames, std::pair<TypeDesc, ValuePtr>& result) const override;
69
71 void makeValidName(string& name) const override;
72
74 string modifyPortName(const string& word) const;
75
78 string replaceSourceCodeMarkers(const string& nodeName, const string& soureCode, std::function<string(const string&)> lambda) const;
79
81 const string& getMdlVersionSuffixMarker() const;
82};
83
86class MX_GENMDL_API MdlStructTypeSyntax : public StructTypeSyntax
87{
88 public:
89 using StructTypeSyntax::StructTypeSyntax;
90
91 string getValue(const Value& value, bool uniform) const override;
92};
93
94namespace Type
95{
96
97TYPEDESC_DEFINE_TYPE(MDL_COORDINATESPACE, "coordinatespace", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
98TYPEDESC_DEFINE_TYPE(MDL_ADDRESSMODE, "addressmode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
99TYPEDESC_DEFINE_TYPE(MDL_FILTERLOOKUPMODE, "filterlookup", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
100TYPEDESC_DEFINE_TYPE(MDL_FILTERTYPE, "filtertype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
101TYPEDESC_DEFINE_TYPE(MDL_DISTRIBUTIONTYPE, "distributiontype", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
102TYPEDESC_DEFINE_TYPE(MDL_SCATTER_MODE, "scatter_mode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
103TYPEDESC_DEFINE_TYPE(MDL_SHEEN_MODE, "mode", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_ENUM, 0)
104
105} // namespace Type
106
107MATERIALX_NAMESPACE_END
108
109#endif
vector< string > StringVec
A vector of strings.
Definition Library.h:61
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< StructTypeSyntax > StructTypeSyntaxPtr
Shared pointer to a StructTypeSyntax.
Definition Syntax.h:34
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:256
Specialization of TypeSyntax for aggregate types.
Definition MdlSyntax.h:87
string getValue(const Value &value, bool uniform) const override
Returns a value formatted according to this type syntax.
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:36
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:37
const string & getSourceFileExtension() const override
Return the file extension used for source code files in this language.
Definition MdlSyntax.h:38
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:44
TypeDesc getEnumeratedType(const string &value) const
Get an type description for an enumeration based on member value.
Syntax(TypeSystemPtr typeSystem)
Protected constructor.
A type descriptor for MaterialX data types.
Definition TypeDesc.h:40
A generic, discriminated value, whose type may be queried dynamically.
Definition Value.h:46