6#ifndef MATERIALX_TYPEDESC_H
7#define MATERIALX_TYPEDESC_H
16MATERIALX_NAMESPACE_BEGIN
63 constexpr TypeDesc() noexcept : _id(0), _basetype(BASETYPE_NONE), _semantic(SEMANTIC_NONE), _size(0) {}
66 constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic = SEMANTIC_NONE, uint16_t size = 1) noexcept :
67 _id(constexpr_hash(name)),
75 uint32_t
typeId()
const {
return _id; }
99 bool isArray()
const {
return _size == 0; }
102 bool isFloat2()
const {
return _size == 2 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
105 bool isFloat3()
const {
return _size == 3 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
108 bool isFloat4()
const {
return _size == 4 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
111 bool isClosure()
const {
return (_semantic == SEMANTIC_CLOSURE || _semantic == SEMANTIC_SHADER || _semantic == SEMANTIC_MATERIAL); }
116 return _id == rhs._id;
122 return _id != rhs._id;
128 return _id < rhs._id;
134 size_t operator()(
const TypeDesc& t)
const
144 static const string NONE_TYPE_NAME;
149 constexpr uint32_t constexpr_hash(std::string_view str, uint32_t n = 0, uint32_t h = 2166136261)
151 return n == uint32_t(str.size()) ? h : constexpr_hash(str, n + 1, (h * 16777619) ^ (str[n]));
169#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size) \
170 static constexpr TypeDesc T(name, basetype, semantic, size);
174#define TYPEDESC_REGISTER_TYPE(T, name) \
175 TypeDescRegistry register_##T(T, name);
187TYPEDESC_DEFINE_TYPE(INTEGERARRAY,
"integerarray", TypeDesc::BASETYPE_INTEGER, TypeDesc::SEMANTIC_NONE, 0)
188TYPEDESC_DEFINE_TYPE(FLOATARRAY,
"floatarray", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_NONE, 0)
194TYPEDESC_DEFINE_TYPE(MATRIX33,
"matrix33", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 9)
195TYPEDESC_DEFINE_TYPE(MATRIX44,
"matrix44", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 16)
197TYPEDESC_DEFINE_TYPE(FILENAME,
"filename", TypeDesc::BASETYPE_STRING, TypeDesc::SEMANTIC_FILENAME, 1)
201TYPEDESC_DEFINE_TYPE(SURFACESHADER,
"surfaceshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
202TYPEDESC_DEFINE_TYPE(VOLUMESHADER,
"volumeshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
203TYPEDESC_DEFINE_TYPE(DISPLACEMENTSHADER,
"displacementshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
204TYPEDESC_DEFINE_TYPE(LIGHTSHADER,
"lightshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
205TYPEDESC_DEFINE_TYPE(MATERIAL,
"material", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_MATERIAL, 1)
209MATERIALX_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:169
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:120
bool operator==(TypeDesc rhs) const
Equality operator.
Definition: TypeDesc.h:114
const string & getName() const
Return the name of the type.
bool isClosure() const
Return true if the type represents a closure.
Definition: TypeDesc.h:111
bool operator<(TypeDesc rhs) const
Less-than operator.
Definition: TypeDesc.h:126
bool isScalar() const
Return true if the type is a scalar type.
Definition: TypeDesc.h:93
size_t getSize() const
Return the number of elements the type is composed of.
Definition: TypeDesc.h:90
bool isFloat3() const
Return true if the type is an aggregate of 3 floats.
Definition: TypeDesc.h:105
unsigned char getSemantic() const
Return the semantic for the type.
Definition: TypeDesc.h:84
constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic=SEMANTIC_NONE, uint16_t size=1) noexcept
Constructor.
Definition: TypeDesc.h:66
bool isAggregate() const
Return true if the type is an aggregate type.
Definition: TypeDesc.h:96
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:102
bool isArray() const
Return true if the type is an array type.
Definition: TypeDesc.h:99
uint32_t typeId() const
Return the unique id assigned to this type.
Definition: TypeDesc.h:75
bool isFloat4() const
Return true if the type is an aggregate of 4 floats.
Definition: TypeDesc.h:108
unsigned char getBaseType() const
Return the basetype for the type.
Definition: TypeDesc.h:81
Helper class for type registration.
Definition: TypeDesc.h:163
Hash operator.
Definition: TypeDesc.h:133