MaterialX 1.39.1
Loading...
Searching...
No Matches
TypeDesc Class Reference

A type descriptor for MaterialX data types. More...

#include <TypeDesc.h>

Classes

struct  Hasher
 Hash operator. More...
 

Public Types

enum  BaseType {
  BASETYPE_NONE , BASETYPE_BOOLEAN , BASETYPE_INTEGER , BASETYPE_FLOAT ,
  BASETYPE_STRING , BASETYPE_STRUCT , BASETYPE_LAST
}
 
enum  Semantic {
  SEMANTIC_NONE , SEMANTIC_COLOR , SEMANTIC_VECTOR , SEMANTIC_MATRIX ,
  SEMANTIC_FILENAME , SEMANTIC_CLOSURE , SEMANTIC_SHADER , SEMANTIC_MATERIAL ,
  SEMANTIC_ENUM , SEMANTIC_LAST
}
 

Public Member Functions

constexpr TypeDesc () noexcept
 Empty constructor.
 
constexpr TypeDesc (std::string_view name, uint8_t basetype, uint8_t semantic=SEMANTIC_NONE, uint16_t size=1) noexcept
 Constructor.
 
uint32_t typeId () const
 Return the unique id assigned to this type. More...
 
const string & getName () const
 Return the name of the type.
 
unsigned char getBaseType () const
 Return the basetype for the type.
 
unsigned char getSemantic () const
 Return the semantic for the type.
 
size_t getSize () const
 Return the number of elements the type is composed of. More...
 
bool isScalar () const
 Return true if the type is a scalar type.
 
bool isAggregate () const
 Return true if the type is an aggregate type.
 
bool isArray () const
 Return true if the type is an array type.
 
bool isFloat2 () const
 Return true if the type is an aggregate of 2 floats.
 
bool isFloat3 () const
 Return true if the type is an aggregate of 3 floats.
 
bool isFloat4 () const
 Return true if the type is an aggregate of 4 floats.
 
bool isClosure () const
 Return true if the type represents a closure.
 
bool operator== (TypeDesc rhs) const
 Equality operator.
 
bool operator!= (TypeDesc rhs) const
 Inequality operator.
 
bool operator< (TypeDesc rhs) const
 Less-than operator.
 

Static Public Member Functions

static TypeDesc get (const string &name)
 Return a type description by name. More...
 

Static Public Attributes

static const string NONE_TYPE_NAME
 

Detailed Description

A type descriptor for MaterialX data types.

All types need to have a type descriptor registered in order for shader generators to know about the type. It can be used for type comparisons as well as getting more information about the type. Type descriptors for all standard library data types are registered by default and can be accessed from the Type namespace, e.g. Type::FLOAT.

To register custom types use the macro TYPEDESC_DEFINE_TYPE to define it in a header and the macro TYPEDESC_REGISTER_TYPE to register it in the type registry. Registration must be done in order to access the type's name later using getName() and to find the type by name using TypeDesc::get().

The class is a POD type of 64-bits and can efficiently be stored and passed by value. Type compare operations and hash operations are done using a precomputed hash value.

Member Function Documentation

◆ get()

static TypeDesc get ( const string &  name)
static

Return a type description by name.

If no type is found Type::NONE is returned.

◆ getSize()

size_t getSize ( ) const
inline

Return the number of elements the type is composed of.

Will return 1 for scalar types and a size greater than 1 for aggregate type. For array types 0 is returned since the number of elements is undefined until an array is instantiated.

◆ typeId()

uint32_t typeId ( ) const
inline

Return the unique id assigned to this type.

The id is a hash of the given type name.


The documentation for this class was generated from the following file: