6 #ifndef MATERIALX_TYPEDESC_H
7 #define MATERIALX_TYPEDESC_H
16 #include <string_view>
73 const string&
getName()
const {
return _name; }
86 _basetype(BASETYPE_NONE),
87 _semantic(SEMANTIC_NONE),
95 _id(constexpr_hash(
name)),
132 bool isFloat2()
const {
return _size == 2 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
135 bool isFloat3()
const {
return _size == 3 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
138 bool isFloat4()
const {
return _size == 4 && (_semantic == SEMANTIC_COLOR || _semantic == SEMANTIC_VECTOR); }
141 bool isClosure()
const {
return (_semantic == SEMANTIC_CLOSURE || _semantic == SEMANTIC_SHADER || _semantic == SEMANTIC_MATERIAL); }
144 bool isStruct()
const {
return _basetype == BASETYPE_STRUCT; }
153 return _id == rhs._id;
159 return _id != rhs._id;
165 return _id < rhs._id;
185 constexpr uint32_t constexpr_hash(
std::string_view str, uint32_t
n = 0, uint32_t
h = 2166136261)
187 return n == uint32_t(str.size()) ?
h : constexpr_hash(str,
n + 1, (
h * 16777619) ^ (str[
n]));
194 const DataBlock* _data;
205 _defaultValueStr(defaultValueStr)
210 const string&
getName()
const {
return _name; }
216 const string _defaultValueStr;
237 TypeDesc getType(
const string& name)
const;
252 vector<TypeDesc::DataBlockPtr> _dataBlocks;
256 #define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size) \
257 inline const TypeDesc::DataBlock* T##_data() { static const TypeDesc::DataBlock _data(name); return &_data; } \
258 static const TypeDesc T(name, basetype, semantic, size, T##_data());
static const string NONE_TYPE_NAME
bool operator<(TypeDesc rhs) const
Less-than operator.
shared_ptr< const StructMemberDescVec > StructMemberDescVecPtr
#define MATERIALX_NAMESPACE_BEGIN
GLsizei const GLfloat * value
unsigned char getSemantic() const
Return the semantic for the type.
vector< StructMemberDesc > StructMemberDescVec
const string & getDefaultValueStr() const
bool operator==(TypeDesc rhs) const
Equality operator.
shared_ptr< class TypeSystem > TypeSystemPtr
DataBlock(const string &name, const StructMemberDescVecPtr members=nullptr) noexcept
const string & getName() const
bool isStruct() const
Return true if the type represents a struct.
const string & getName() const
basic_string_view< char > string_view
GLint GLint GLsizei GLint GLenum GLenum type
size_t operator()(const TypeDesc &t) const
unsigned char getBaseType() const
Return the basetype for the type.
bool isClosure() const
Return true if the type represents a closure.
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
StructMemberDescVecPtr getStructMembers() const
bool isFloat2() const
Return true if the type is an aggregate of 2 floats.
std::unordered_map< string, TypeDesc > TypeDescMap
GLuint const GLchar * name
Data block holding large data needed by the type description.
const TypeDescVec & getTypes() const
Return all registered type descriptions.
StructMemberDesc(TypeDesc type, const string &name, const string &defaultValueStr)
#define TYPEDESC_DEFINE_TYPE(T, name, basetype, semantic, size)
Macro to define global type descriptions for commonly used types.
bool isAggregate() const
Return true if the type is an aggregate type.
constexpr TypeDesc() noexcept
Empty constructor.
GLfloat GLfloat GLfloat GLfloat h
vector< TypeDesc > TypeDescVec
std::shared_ptr< DataBlock > DataBlockPtr
bool operator!=(TypeDesc rhs) const
Inequality operator.
bool isFloat3() const
Return true if the type is an aggregate of 3 floats.
bool isScalar() const
Return true if the type is a scalar type.
#define MATERIALX_NAMESPACE_END
constexpr TypeDesc(std::string_view name, uint8_t basetype, uint8_t semantic, uint16_t size, const DataBlock *data) noexcept
Constructor.
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
bool isArray() const
Return true if the type is an array type.
bool isFloat4() const
Return true if the type is an aggregate of 4 floats.