6#ifndef MATERIALX_TYPEDESC_H
7#define MATERIALX_TYPEDESC_H
17MATERIALX_NAMESPACE_BEGIN
66 _basetype(BASETYPE_NONE),
67 _semantic(SEMANTIC_NONE),
74 constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic = SEMANTIC_NONE, uint16_t size = 1, uint16_t structIndex = 0) noexcept :
75 _id(constexpr_hash(name)),
79 _structIndex(structIndex)
85 uint32_t
typeId()
const {
return _id; }
112 bool isFloat2()
const {
return _size == 2 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
115 bool isFloat3()
const {
return _size == 3 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
118 bool isFloat4()
const {
return _size == 4 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
121 bool isClosure()
const {
return (_semantic == SEMANTIC_CLOSURE || _semantic == SEMANTIC_SHADER || _semantic == SEMANTIC_MATERIAL); }
124 bool isStruct()
const {
return _basetype == BASETYPE_STRUCT; }
132 return _id == rhs._id;
138 return _id != rhs._id;
144 return _id < rhs._id;
150 size_t operator()(
const TypeDesc& t)
const
163 static const string NONE_TYPE_NAME;
171 constexpr uint32_t constexpr_hash(std::string_view str, uint32_t n = 0, uint32_t h = 2166136261)
173 return n == uint32_t(str.size()) ? h : constexpr_hash(str, n + 1, (h * 16777619) ^ (str[n]));
180 uint16_t _structIndex;
185class MX_GENSHADER_API TypeDescRegistry
188 TypeDescRegistry(
TypeDesc type,
const string& name);
192#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size) \
193 static constexpr TypeDesc T(name, basetype, semantic, size);
197#define TYPEDESC_REGISTER_TYPE(T, name) \
198 TypeDescRegistry register_##T(T, name);
210TYPEDESC_DEFINE_TYPE(INTEGERARRAY,
"integerarray", TypeDesc::BASETYPE_INTEGER, TypeDesc::SEMANTIC_NONE, 0)
211TYPEDESC_DEFINE_TYPE(FLOATARRAY,
"floatarray", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_NONE, 0)
217TYPEDESC_DEFINE_TYPE(MATRIX33,
"matrix33", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 9)
218TYPEDESC_DEFINE_TYPE(MATRIX44,
"matrix44", TypeDesc::BASETYPE_FLOAT, TypeDesc::SEMANTIC_MATRIX, 16)
220TYPEDESC_DEFINE_TYPE(FILENAME,
"filename", TypeDesc::BASETYPE_STRING, TypeDesc::SEMANTIC_FILENAME, 1)
224TYPEDESC_DEFINE_TYPE(SURFACESHADER,
"surfaceshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
225TYPEDESC_DEFINE_TYPE(VOLUMESHADER,
"volumeshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
226TYPEDESC_DEFINE_TYPE(DISPLACEMENTSHADER,
"displacementshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
227TYPEDESC_DEFINE_TYPE(LIGHTSHADER,
"lightshader", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_SHADER, 1)
228TYPEDESC_DEFINE_TYPE(MATERIAL,
"material", TypeDesc::BASETYPE_NONE, TypeDesc::SEMANTIC_MATERIAL, 1)
244 struct StructMemberTypeDesc
246 StructMemberTypeDesc(
string name,
TypeDesc typeDesc,
string defaultValueStr) :
247 _name(name), _typeDesc(typeDesc), _defaultValueStr(defaultValueStr)
252 string _defaultValueStr;
258 void addMember(
const string& name,
TypeDesc type,
const string& defaultValueStr);
259 void setTypeDesc(
TypeDesc typedesc) { _typedesc = typedesc; }
263 static vector<string> getStructTypeNames();
267 TypeDesc typeDesc()
const {
return _typedesc; }
269 const string& getName()
const;
271 const vector<StructMemberTypeDesc>& getMembers()
const;
275 vector<StructMemberTypeDesc> _members;
280class MX_GENSHADER_API StructTypeDescRegistry
283 StructTypeDescRegistry();
286MATERIALX_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:192
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition Value.h:30
StructTypeDesc() noexcept
Empty constructor.
Definition TypeDesc.h:256
static StructTypeDesc & get(unsigned int index)
Return a type description by index.
A type descriptor for MaterialX data types.
Definition TypeDesc.h:36
constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic=SEMANTIC_NONE, uint16_t size=1, uint16_t structIndex=0) noexcept
Constructor.
Definition TypeDesc.h:74
constexpr TypeDesc() noexcept
Empty constructor.
Definition TypeDesc.h:64
bool operator!=(TypeDesc rhs) const
Inequality operator.
Definition TypeDesc.h:136
bool operator==(TypeDesc rhs) const
Equality operator.
Definition TypeDesc.h:130
const string & getName() const
Return the name of the type.
bool isClosure() const
Return true if the type represents a closure.
Definition TypeDesc.h:121
static void remove(const string &name)
Remove a type description by name, if it exists.
bool isStruct() const
Return true if the type represents a struct.
Definition TypeDesc.h:124
bool operator<(TypeDesc rhs) const
Less-than operator.
Definition TypeDesc.h:142
bool isScalar() const
Return true if the type is a scalar type.
Definition TypeDesc.h:103
size_t getSize() const
Return the number of elements the type is composed of.
Definition TypeDesc.h:100
bool isFloat3() const
Return true if the type is an aggregate of 3 floats.
Definition TypeDesc.h:115
unsigned char getSemantic() const
Return the semantic for the type.
Definition TypeDesc.h:94
ValuePtr createValueFromStrings(const string &value) const
Create a Value from a string for a given typeDesc.
bool isAggregate() const
Return true if the type is an aggregate type.
Definition TypeDesc.h:106
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:112
uint16_t getStructIndex() const
Return the index for the struct member information in StructTypeDesc, the result is invalid if isStru...
Definition TypeDesc.h:127
bool isArray() const
Return true if the type is an array type.
Definition TypeDesc.h:109
uint32_t typeId() const
Return the unique id assigned to this type.
Definition TypeDesc.h:85
bool isFloat4() const
Return true if the type is an aggregate of 4 floats.
Definition TypeDesc.h:118
unsigned char getBaseType() const
Return the basetype for the type.
Definition TypeDesc.h:91
Hash operator.
Definition TypeDesc.h:149