6#ifndef MATERIALX_TYPEDESC_H
7#define MATERIALX_TYPEDESC_H
16MATERIALX_NAMESPACE_BEGIN
64 _id(0), _basetype(BASETYPE_NONE), _semantic(SEMANTIC_NONE), _size(0) { }
67 constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic = SEMANTIC_NONE, uint16_t size = 1) noexcept :
68 _id(constexpr_hash(name)),
77 uint32_t
typeId()
const {
return _id; }
104 bool isFloat2()
const {
return _size == 2 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
107 bool isFloat3()
const {
return _size == 3 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
110 bool isFloat4()
const {
return _size == 4 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
113 bool isClosure()
const {
return (_semantic == SEMANTIC_CLOSURE || _semantic == SEMANTIC_SHADER || _semantic == SEMANTIC_MATERIAL); }
118 return _id == rhs._id;
124 return _id != rhs._id;
130 return _id < rhs._id;
136 size_t operator()(
const TypeDesc& t)
const
146 static const string NONE_TYPE_NAME;
151 constexpr uint32_t constexpr_hash(std::string_view str, uint32_t n = 0, uint32_t h = 2166136261)
153 return n == uint32_t(str.size()) ? h : constexpr_hash(str, n + 1, (h * 16777619) ^ (str[n]));
171#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size) \
172 static constexpr TypeDesc T(name, basetype, semantic, size);
176#define TYPEDESC_REGISTER_TYPE(T, name) \
177 TypeDescRegistry register_##T(T, name);
189TYPEDESC_DEFINE_TYPE(INTEGERARRAY,
"integerarray", TypeDesc::BASETYPE_INTEGER, TypeDesc::SEMANTIC_NONE, 0)
190TYPEDESC_DEFINE_TYPE(FLOATARRAY,
"floatarray", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_NONE, 0)
196TYPEDESC_DEFINE_TYPE(MATRIX33,
"matrix33", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 9)
197TYPEDESC_DEFINE_TYPE(MATRIX44,
"matrix44", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 16)
199TYPEDESC_DEFINE_TYPE(FILENAME,
"filename", TypeDesc::BASETYPE_STRING, TypeDesc::SEMANTIC_FILENAME, 1)
203TYPEDESC_DEFINE_TYPE(SURFACESHADER,
"surfaceshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
204TYPEDESC_DEFINE_TYPE(VOLUMESHADER,
"volumeshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
205TYPEDESC_DEFINE_TYPE(DISPLACEMENTSHADER,
"displacementshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
206TYPEDESC_DEFINE_TYPE(LIGHTSHADER,
"lightshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
207TYPEDESC_DEFINE_TYPE(MATERIAL,
"material", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_MATERIAL, 1)
211MATERIALX_NAMESPACE_END
Macros for declaring imported and exported symbols.
#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size)
Macro to define global type descriptions for commonly used types.
Definition: TypeDesc.h:171
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:35
constexpr TypeDesc() noexcept
Empty constructor.
Definition: TypeDesc.h:63
bool operator!=(TypeDesc rhs) const
Inequality operator.
Definition: TypeDesc.h:122
bool operator==(TypeDesc rhs) const
Equality operator.
Definition: TypeDesc.h:116
const string & getName() const
Return the name of the type.
bool isClosure() const
Return true if the type represents a closure.
Definition: TypeDesc.h:113
bool operator<(TypeDesc rhs) const
Less-than operator.
Definition: TypeDesc.h:128
bool isScalar() const
Return true if the type is a scalar type.
Definition: TypeDesc.h:95
size_t getSize() const
Return the number of elements the type is composed of.
Definition: TypeDesc.h:92
bool isFloat3() const
Return true if the type is an aggregate of 3 floats.
Definition: TypeDesc.h:107
unsigned char getSemantic() const
Return the semantic for the type.
Definition: TypeDesc.h:86
constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic=SEMANTIC_NONE, uint16_t size=1) noexcept
Constructor.
Definition: TypeDesc.h:67
bool isAggregate() const
Return true if the type is an aggregate type.
Definition: TypeDesc.h:98
static TypeDesc get(const string &name)
Return a type description by name.
bool isFloat2() const
Return true if the type is an aggregate of 2 floats.
Definition: TypeDesc.h:104
bool isArray() const
Return true if the type is an array type.
Definition: TypeDesc.h:101
uint32_t typeId() const
Return the unique id assigned to this type.
Definition: TypeDesc.h:77
bool isFloat4() const
Return true if the type is an aggregate of 4 floats.
Definition: TypeDesc.h:110
unsigned char getBaseType() const
Return the basetype for the type.
Definition: TypeDesc.h:83
Helper class for type registration.
Definition: TypeDesc.h:165
Hash operator.
Definition: TypeDesc.h:135