MaterialX 1.38.2
TypeDesc.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_TYPEDESC_H
7#define MATERIALX_TYPEDESC_H
8
11
13
14namespace MaterialX
15{
16
17using ChannelMap = std::unordered_map<char, int>;
18
28class MX_GENSHADER_API TypeDesc
29{
30 public:
31 enum BaseType
32 {
33 BASETYPE_NONE,
34 BASETYPE_BOOLEAN,
35 BASETYPE_INTEGER,
36 BASETYPE_FLOAT,
37 BASETYPE_STRING,
38 BASETYPE_STRUCT,
39 BASETYPE_LAST
40 };
41
42 enum Semantic
43 {
44 SEMANTIC_NONE,
45 SEMANTIC_COLOR,
46 SEMANTIC_VECTOR,
47 SEMANTIC_MATRIX,
48 SEMANTIC_FILENAME,
49 SEMANTIC_CLOSURE,
50 SEMANTIC_SHADER,
51 SEMANTIC_MATERIAL,
52 SEMANTIC_ENUM,
53 SEMANTIC_LAST
54 };
55
58 static const TypeDesc* registerType(const string& name, unsigned char basetype, unsigned char semantic = SEMANTIC_NONE,
59 size_t size = 1, bool editable = true, const ChannelMap& channelMapping = ChannelMap());
60
63 static const TypeDesc* get(const string& name);
64
66 const string& getName() const { return _name; }
67
69 unsigned char getBaseType() const { return _basetype; }
70
73 int getChannelIndex(char channel) const;
74
76 unsigned char getSemantic() const { return _semantic; }
77
82 size_t getSize() const { return _size; }
83
87 bool isEditable() const { return _editable; }
88
90 bool isScalar() const { return _size == 1; }
91
93 bool isAggregate() const { return _size > 1; }
94
96 bool isArray() const { return _size == 0; }
97
99 bool isFloat2() const { return _size == 2 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
100
102 bool isFloat3() const { return _size == 3 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
103
105 bool isFloat4() const { return _size == 4 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
106
107 private:
108 TypeDesc(const string& name, unsigned char basetype, unsigned char semantic, size_t size,
109 bool editable, const ChannelMap& channelMapping);
110
111 const string _name;
112 const unsigned char _basetype;
113 const unsigned char _semantic;
114 const size_t _size;
115 const bool _editable;
116 const ChannelMap _channelMapping;
117};
118
119namespace Type
120{
126 extern MX_GENSHADER_API const TypeDesc* NONE;
127 extern MX_GENSHADER_API const TypeDesc* BOOLEAN;
128 extern MX_GENSHADER_API const TypeDesc* INTEGER;
129 extern MX_GENSHADER_API const TypeDesc* INTEGERARRAY;
130 extern MX_GENSHADER_API const TypeDesc* FLOAT;
131 extern MX_GENSHADER_API const TypeDesc* FLOATARRAY;
132 extern MX_GENSHADER_API const TypeDesc* VECTOR2;
133 extern MX_GENSHADER_API const TypeDesc* VECTOR3;
134 extern MX_GENSHADER_API const TypeDesc* VECTOR4;
135 extern MX_GENSHADER_API const TypeDesc* COLOR3;
136 extern MX_GENSHADER_API const TypeDesc* COLOR4;
137 extern MX_GENSHADER_API const TypeDesc* MATRIX33;
138 extern MX_GENSHADER_API const TypeDesc* MATRIX44;
139 extern MX_GENSHADER_API const TypeDesc* STRING;
140 extern MX_GENSHADER_API const TypeDesc* FILENAME;
141 extern MX_GENSHADER_API const TypeDesc* BSDF;
142 extern MX_GENSHADER_API const TypeDesc* EDF;
143 extern MX_GENSHADER_API const TypeDesc* VDF;
144 extern MX_GENSHADER_API const TypeDesc* SURFACESHADER;
145 extern MX_GENSHADER_API const TypeDesc* VOLUMESHADER;
146 extern MX_GENSHADER_API const TypeDesc* DISPLACEMENTSHADER;
147 extern MX_GENSHADER_API const TypeDesc* LIGHTSHADER;
148} // namespace Type
149
150} // namespace MaterialX
151
152#endif
Macros for declaring imported and exported symbols.
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:29
bool isEditable() const
Returns true if the type is editable by users.
Definition: TypeDesc.h:87
const string & getName() const
Return the name of the type.
Definition: TypeDesc.h:66
bool isScalar() const
Return true if the type is a scalar type.
Definition: TypeDesc.h:90
size_t getSize() const
Return the number of elements the type is composed of.
Definition: TypeDesc.h:82
bool isFloat3() const
Return true if the type is an aggregate of 3 floats.
Definition: TypeDesc.h:102
unsigned char getSemantic() const
Return the semantic for the type.
Definition: TypeDesc.h:76
bool isAggregate() const
Return true if the type is an aggregate type.
Definition: TypeDesc.h:93
bool isFloat2() const
Return true if the type is an aggregate of 2 floats.
Definition: TypeDesc.h:99
bool isArray() const
Return true if the type is an array type.
Definition: TypeDesc.h:96
bool isFloat4() const
Return true if the type is an aggregate of 4 floats.
Definition: TypeDesc.h:105
unsigned char getBaseType() const
Return the basetype for the type.
Definition: TypeDesc.h:69