HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_Types.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VEX_Types.h ( VEX Library, C++)
7  *
8  * COMMENTS: Data types for VEX variables
9  */
10 
11 #ifndef __VEX_Types__
12 #define __VEX_Types__
13 
14 #include "VEX_API.h"
15 #include <SYS/SYS_StaticAssert.h>
16 #include <UT/UT_Vector3.h>
17 #include <UT/UT_Vector4.h>
18 #include <UT/UT_Matrix3.h>
19 #include <UT/UT_Matrix4.h>
20 #include "VEX_PodTypes.h"
21 #include "VEX_VexTypes.h"
22 #include "VEX_RefObject.h"
23 
24 template <VEX_Precision PREC> class VEX_Value;
25 template <VEX_Precision PREC> class VEX_Instance;
26 class VEX_ProcArray;
27 class VEX_OpCode;
28 class FS_DiskCache;
29 
30 // Two way type resolver
31 //
32 // VEX_VexTypeResolver: C++ Type -> Vex Type
33 // VEX_TypeResolver: Vex Type + PREC -> C++ Type
34 //
35 
36 template <typename T>
38 template <VEX_Type VTYPE, VEX_Precision PREC>
40 
41 
42 #define VEX_TYPERESOLVE_CASE(VexType, CPPType) \
43  template <> \
44  struct VEX_VexTypeResolver<VEX##CPPType<VEX_32> > \
45  { \
46  static constexpr VEX_Type type = VEX_TYPE_##VexType; \
47  }; \
48  template <> \
49  struct VEX_VexTypeResolver<VEX##CPPType<VEX_64> > \
50  { \
51  static constexpr VEX_Type type = VEX_TYPE_##VexType; \
52  }; \
53  template <VEX_Precision PREC> \
54  struct VEX_TypeResolver<VEX_TYPE_##VexType, PREC> \
55  { \
56  typedef VEX##CPPType<PREC> T; \
57  };
58  /* end of macro */
59 
61 VEX_TYPERESOLVE_CASE(INTEGER, int);
62 VEX_TYPERESOLVE_CASE(VECTOR2, vec2);
64 VEX_TYPERESOLVE_CASE(VECTOR4, vec4);
65 VEX_TYPERESOLVE_CASE(MATRIX2, mat2);
66 VEX_TYPERESOLVE_CASE(MATRIX3, mat3);
67 VEX_TYPERESOLVE_CASE(MATRIX4, mat4);
68 
69 template <>
71 {
72  static constexpr VEX_Type type = VEX_TYPE_STRING;
73 };
74 template <VEX_Precision PREC>
76 {
77  typedef UT_StringHolder T;
78 };
79 template <>
81 {
82  static constexpr VEX_Type type = VEX_TYPE_BSDF;
83 };
84 template <VEX_Precision PREC>
86 {
87  typedef VEX_RefObject* T;
88 };
89 
90 #undef VEX_TYPERESOLVE_CASE
91 
92 
94 {
95  VEX_STORE_UNDEF, // Undefined until a later date
96 
97  VEX_STORE_PARAMETER, // Possibly bound to some other source
98  VEX_STORE_LOCAL, // Local variable - storage deferred until bind
99  VEX_STORE_CONST, // Constant
100  VEX_STORE_GLOBAL, // Global variable
101 
102  VEX_MAX_STORAGE // Last entry is a counter only
103 };
104 
106 {
108  VEX_BASETYPE_INT, // Integer
111 };
112 
114 {
115  VEX_UI_NONE, // No ui hint
116  VEX_UI_COLOR, // Parameter represents a color
117  VEX_UI_DIRECTION, // a direction vector
118  VEX_UI_VECTOR, // a position vector
119  VEX_UI_VECTOR4, // a position vector 4
120  VEX_UI_UV, // a uv position
121  VEX_UI_UVW, // a uvw position
122  VEX_UI_ANGLE, // an angle
123  VEX_UI_TOGGLE, // a boolean toggle
124  VEX_UI_BUTTON, // a button for executing a callback
125  VEX_UI_FILE, // a filename
126  VEX_UI_IMGFILE, // an image file/ramp
127  VEX_UI_GEOFILE, // a geometry file
128  VEX_UI_OPPATH, // an operator path
129  VEX_UI_OPLIST, // a list of operator paths
130  VEX_UI_EMBED, // an embedded set of parameters
132 };
133 
134 class VEX_RWType {
135 public:
137  : myRead(false)
138  , myWrite(false) {}
139  VEX_RWType(bool read, bool write)
140  : myRead(read)
141  , myWrite(write) {}
142 
143  void setRead(bool r = true) { myRead = r; }
144  void setWrite(bool w = true) { myWrite = w; }
145  bool isRead() const { return myRead; }
146  bool isWrite() const { return myWrite; }
147 
148  bool operator==(const VEX_RWType &rhs) const
149  { return myRead == rhs.myRead &&
150  myWrite == rhs.myWrite; }
151  bool operator!=(const VEX_RWType &rhs) const
152  { return !(*this == rhs); }
153 
154  const char *asString() const
155  {
156  if (myRead && myWrite) return "modify";
157  if (myRead) return "read";
158  if (myWrite) return "write";
159  return "unused";
160  }
161 
162 private:
163  bool myRead;
164  bool myWrite;
165 };
166 
167 static const VEX_RWType VEX_RW_NONE(false, false);
168 static const VEX_RWType VEX_RW_READ(true, false);
169 static const VEX_RWType VEX_RW_WRITE(false, true);
170 static const VEX_RWType VEX_RW_MODIFY(true, true);
171 
172 VEX_API const char *VEXgetType(VEX_Type type);
176 VEX_API VEX_Type VEXgetType(const char *label);
177 VEX_API VEX_Type VEXgetType(const char *label, bool &isarray);
178 // Dangerous as there is no unique mapping.
179 // VEX_API VEX_Type VEXgetType(int size);
180 VEX_API VEX_Type VEXgetMangleType(char mangle);
184 VEX_API const char *VEXgetUIHint(VEX_UIHint type);
185 VEX_API VEX_UIHint VEXgetUIHint(const char *label);
186 
187 SYS_FORCE_INLINE constexpr bool
189 {
190  switch (type)
191  {
192  case VEX_TYPE_FLOAT: return true;
193  case VEX_TYPE_INTEGER: return true;
194  case VEX_TYPE_VECTOR2: return true;
195  case VEX_TYPE_VECTOR: return true;
196  case VEX_TYPE_VECTOR4: return true;
197  case VEX_TYPE_MATRIX2: return true;
198  case VEX_TYPE_MATRIX3: return true;
199  case VEX_TYPE_MATRIX4: return true;
200  default: return false;
201  }
202  return false;
203 }
204 
205 
207 
208 template <VEX_Precision PREC> static inline constexpr size_t
209 VEXsizeof(VEX_Type type)
210 {
211  switch (type)
212  {
213  case VEX_TYPE_VECTOR4: return sizeof(VEXvec4<PREC>);
214  case VEX_TYPE_VECTOR: return sizeof(VEXvec3<PREC>);
215  case VEX_TYPE_VECTOR2: return sizeof(VEXvec2<PREC>);
216  case VEX_TYPE_FLOAT: return sizeof(VEXfloat<PREC>);
217  case VEX_TYPE_INTEGER: return sizeof(VEXint<PREC>);
218  case VEX_TYPE_STRING: return sizeof(UT_StringHolder);
219  case VEX_TYPE_MATRIX2: return sizeof(VEXmat2<PREC>);
220  case VEX_TYPE_MATRIX3: return sizeof(VEXmat3<PREC>);
221  case VEX_TYPE_MATRIX4: return sizeof(VEXmat4<PREC>);
222  case VEX_TYPE_BSDF: return sizeof(VEX_RefObject *);
223  default: break;
224  }
225  return 0;
226 }
227 
228 VEX_API int VEXgetArgCount(VEX_Type type); // Tuple size
229 VEX_API int VEXgetFloatCount(VEX_Type type); // Float-tuple size
230 
231 template <typename T> static inline constexpr int VEXtupleSize()
232  { SYS_UNIMPLEMENTED_TEMPLATE(T); return 0; }
233 template <> inline constexpr int VEXtupleSize<VEXint<VEX_32>>() { return 1; }
234 template <> inline constexpr int VEXtupleSize<VEXint<VEX_64>>() { return 1; }
235 template <> inline constexpr int VEXtupleSize<VEXfloat<VEX_32>>() { return 1; }
236 template <> inline constexpr int VEXtupleSize<VEXfloat<VEX_64>>() { return 1; }
237 template <> inline constexpr int VEXtupleSize<VEXvec2<VEX_32>>() { return 2; }
238 template <> inline constexpr int VEXtupleSize<VEXvec2<VEX_64>>() { return 2; }
239 template <> inline constexpr int VEXtupleSize<VEXvec3<VEX_32>>() { return 3; }
240 template <> inline constexpr int VEXtupleSize<VEXvec3<VEX_64>>() { return 3; }
241 template <> inline constexpr int VEXtupleSize<VEXvec4<VEX_32>>() { return 4; }
242 template <> inline constexpr int VEXtupleSize<VEXvec4<VEX_64>>() { return 4; }
243 template <> inline constexpr int VEXtupleSize<VEXmat2<VEX_32>>() { return 4; }
244 template <> inline constexpr int VEXtupleSize<VEXmat2<VEX_64>>() { return 4; }
245 template <> inline constexpr int VEXtupleSize<VEXmat3<VEX_32>>() { return 9; }
246 template <> inline constexpr int VEXtupleSize<VEXmat3<VEX_64>>() { return 9; }
247 template <> inline constexpr int VEXtupleSize<VEXmat4<VEX_32>>() { return 16; }
248 template <> inline constexpr int VEXtupleSize<VEXmat4<VEX_64>>() { return 16; }
249 
250 #endif
251 
VEX_Storage
Definition: VEX_Types.h:93
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
VEX_API const char * VEXgetBaseType(VEX_BaseType type)
VEX_API const char * VEXgetUIHint(VEX_UIHint type)
VEX_API FS_DiskCache & VEXcompileCache()
#define VEX_TYPERESOLVE_CASE(VexType, CPPType)
Definition: VEX_Types.h:42
#define VEX_API
Definition: VEX_API.h:12
VEX_API const char * VEXgetStorage(VEX_Storage type)
void read(T &in, bool &v)
Definition: ImfXdr.h:611
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
bool isWrite() const
Definition: VEX_Types.h:146
VEX_API int VEXgetFloatCount(VEX_Type type)
VEX_API int VEXgetArgCount(VEX_Type type)
SYS_FORCE_INLINE constexpr bool VEXisPrecisioned(VEX_Type type)
Definition: VEX_Types.h:188
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
VEX_API const char * VEXgetShortStorage(VEX_Storage type)
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
VEX_BaseType
Definition: VEX_Types.h:105
typename VEX_PrecisionResolver< P >::mat2_type VEXmat2
Definition: VEX_PodTypes.h:72
VEX_API const char * VEXgetType(VEX_Type type)
bool isRead() const
Definition: VEX_Types.h:145
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
#define SYS_UNIMPLEMENTED_TEMPLATE(T)
bool operator!=(const VEX_RWType &rhs) const
Definition: VEX_Types.h:151
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
GLboolean r
Definition: glcorearb.h:1221
VEX_UIHint
Definition: VEX_Types.h:113
VEX_RWType(bool read, bool write)
Definition: VEX_Types.h:139
void write(T &out, bool v)
Definition: ImfXdr.h:332
void setRead(bool r=true)
Definition: VEX_Types.h:143
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
bool operator==(const VEX_RWType &rhs) const
Definition: VEX_Types.h:148
void setWrite(bool w=true)
Definition: VEX_Types.h:144
VEX_API char VEXgetMangleType(VEX_Type type)
const char * asString() const
Definition: VEX_Types.h:154