HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CVEX_Value.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: CVEX_Value.h ( CVEX Library, C++)
7  *
8  * COMMENTS: C++ interface to VEX. This class is used to specify
9  * input/output variable data.
10  */
11 
12 #ifndef __CVEX_Value__
13 #define __CVEX_Value__
14 
15 #include "CVEX_API.h"
16 #include <UT/UT_Array.h>
17 #include <UT/UT_StringHolder.h>
19 #include <VEX/VEX_PodTypes.h>
20 #include <VEX/VEX_VexTypes.h> // for VEX_Type
21 
23 
24 /// The CVEX_Type enum defines the VEX types available to CVEX.
25 typedef enum {
26  CVEX_TYPE_INVALID = -1, // Invalid type
27  CVEX_TYPE_INTEGER, // Integer
28  CVEX_TYPE_FLOAT, // Float
29  CVEX_TYPE_VECTOR2, // 2-tuple of float
30  CVEX_TYPE_VECTOR3, // 3-tuple of float
31  CVEX_TYPE_VECTOR4, // 4-tuple of float
32  CVEX_TYPE_MATRIX2, // 4-tuple of float
33  CVEX_TYPE_MATRIX3, // 9-tuple of float
34  CVEX_TYPE_MATRIX4, // 16-tuple of float
35  CVEX_TYPE_STRING, // string values
36  CVEX_TYPE_INTEGER_ARRAY, // Integer array
37  CVEX_TYPE_FLOAT_ARRAY, // Float array
38  CVEX_TYPE_VECTOR2_ARRAY, // 2-tuple of float array
39  CVEX_TYPE_VECTOR3_ARRAY, // 3-tuple of float array
40  CVEX_TYPE_VECTOR4_ARRAY, // 4-tuple of float array
41  CVEX_TYPE_MATRIX2_ARRAY, // 4-tuple of float array
42  CVEX_TYPE_MATRIX3_ARRAY, // 9-tuple of float array
43  CVEX_TYPE_MATRIX4_ARRAY, // 16-tuple of float array
44  CVEX_TYPE_STRING_ARRAY, // string array.
45 } CVEX_Type;
46 
47 /// @brief A class representing a VEX value.
48 ///
49 /// The CVEX_Value objects are created internally in the CVEX library. They
50 /// provide a mapping from the CVEX library to the underlying VEX
51 /// representation of objects.
53 public:
56  bool varying);
57  ~CVEX_Value();
58 
59  /// Query name of VEX value
60  const UT_StringHolder &getName() const { return myName; }
61  /// Query type of VEX value
62  CVEX_Type getType() const { return myType; }
63  void setType(CVEX_Type type);
64  void setPrecision(VEX_Precision p) { myPrec = p; }
65  /// Query whether the VEX value is an export (or read-only)
66  bool isExport() const { return myExport; }
67  /// Query whether the VEX value is uniform or varying
68  bool isVarying() const { return myVarying; }
69  /// Query the array size of the VEX value.
70  /// @note This is @b not the used for VEX arrays, but rather represents the
71  /// number of entries in the varying array.
72  int getArraySize() const { return myArraySize; }
73 
74  /// Get the raw data pointer.
75  /// For numeric types, the data refers to a raw array of data (depending on
76  /// the getType() of the value.
77  /// - CVEX_TYPE_INTEGER @c int
78  /// - CVEX_TYPE_FLOAT @c fpreal32
79  /// - CVEX_TYPE_VECTOR2 @c UT_Vector2F
80  /// - CVEX_TYPE_VECTOR3 @c UT_Vector3F
81  /// - CVEX_TYPE_VECTOR4 @c UT_Vector4F
82  /// - CVEX_TYPE_MATRIX2 @c UT_Matrix2F
83  /// - CVEX_TYPE_MATRIX3 @c UT_Matrix3F
84  /// - CVEX_TYPE_MATRIX4 @c UT_Matrix4F
85  /// For CVEX_TYPE_STRING, the data will point to a UT_StringArray.
86  void *getRawData() { return myData; }
87 
88  bool isPackedArray() const { return myIsPackedArray; }
89 
90  /// The array size is NOT the size in bytes, but rather the array size of
91  /// the input data. It should either be 1 or N, where N is the number of
92  /// values being computed by VEX.
93  ///
94  /// When passing data for output variables, please check to see whether
95  /// the output variable is uniform or varying. Varying values need to
96  /// have a full array of data (including string arrays).
97  ///
98  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
99  /// so the data must be persistent.
100  bool setTypedData(int32 *data, int array_size);
101  bool setTypedData(fpreal32 *data, int array_size);
102  bool setTypedData(UT_Vector2F *data, int array_size);
103  bool setTypedData(UT_Vector3F *data, int array_size);
104  bool setTypedData(UT_Vector4F *data, int array_size);
105  bool setTypedData(UT_Matrix2F *data, int array_size);
106  bool setTypedData(UT_Matrix3F *data, int array_size);
107  bool setTypedData(UT_Matrix4F *data, int array_size);
108 
109  bool setTypedData(int64 *data, int array_size);
110  bool setTypedData(fpreal64 *data, int array_size);
111  bool setTypedData(UT_Vector2D *data, int array_size);
112  bool setTypedData(UT_Vector3D *data, int array_size);
113  bool setTypedData(UT_Vector4D *data, int array_size);
114  bool setTypedData(UT_Matrix2D *data, int array_size);
115  bool setTypedData(UT_Matrix3D *data, int array_size);
116  bool setTypedData(UT_Matrix4D *data, int array_size);
117 
118  /// When setting values for string types, you need to pass in a
119  /// CVEX_StringArray instead of a void *. For input variables, the length
120  /// of the array will determine whether the parameter is varying or
121  /// uniform.
122  ///
123  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
124  /// so the data must be persistent.
125  ///
126  /// When setting data for outputs, the packed arrays should be empty
127  /// and the array size specified.
128  bool setTypedData(CVEX_StringArray &stringdata);
129  bool setTypedData(UT_Array<UT_Array<int32> > &intdata);
130  bool setTypedData(UT_PackedArrayOfArrays<int32> &intdata,
131  int arraysize=0);
132  /// This is stored as xyzxyzxyz for vector data.
133  bool setTypedData(UT_Array<UT_Array<fpreal32> > &fltdata);
134  bool setTypedData(UT_PackedArrayOfArrays<fpreal32> &fltdata,
135  int arraysize=0);
136  bool setTypedData(UT_Array<UT_Array<int64> > &intdata);
137  bool setTypedData(UT_PackedArrayOfArrays<int64> &intdata,
138  int arraysize=0);
139  /// This is stored as xyzxyzxyz for vector data.
140  bool setTypedData(UT_Array<UT_Array<fpreal64> > &fltdata);
141  bool setTypedData(UT_PackedArrayOfArrays<fpreal64> &fltdata,
142  int arraysize=0);
143  bool setTypedData(UT_Array<CVEX_StringArray> &stringdata);
144 
145  /// Type unsafe way of setting VEX data. Avoid using if possible.
146  bool setRawData(CVEX_Type type, VEX_Precision, void *data, int array_size);
147 
148 
149  // Deprecated equivalents. Please avoid, they're error-prone.
150  SYS_DEPRECATED(13.0)
151  void *getData()
152  { return getRawData(); }
153 
154  SYS_DEPRECATED(13.0)
155  bool setData(void *data, int array_size)
156  { return setRawData(myType, VEX_32, data, array_size); }
157 
158  SYS_DEPRECATED(13.0)
159  bool setData(CVEX_StringArray &stringdata)
160  { return setTypedData(stringdata); }
161 
162  static int getTupleSize(CVEX_Type t);
163  static CVEX_Type getArrayBaseType(CVEX_Type t);
164 
165  /// The IsConstant determines eligibility for constant folding.
166  /// It likely implies Uniform. But it is quite reasonable to have
167  /// a Uniform parameter that isn't constant, it is then a demand
168  /// that the VEX Assemble does not fold the input regardless of
169  /// the initial value during load()
170  void setIsConstant(bool isconstant)
171  { myIsConstant = isconstant; }
172  bool isConstant() const
173  { return myIsConstant; }
174 
175  /// Given the list of vex parameters, returns the list of cvex parmeters
176  /// that have valid cvex types.
177  static VEX_Type cvexToVexType(CVEX_Type type, bool &isarray);
178  static CVEX_Type vexToCVexType(VEX_Type vextype, bool isarray);
179 
180 private:
181  void clear();
182 
183  void *myData;
184  void *myStringSet;
185  void *myArrayType;
186  UT_StringHolder myName;
187  CVEX_Type myType; // Data type
188  VEX_Type myVexType; // VEX Type (mapped from CVEX_Type)
189  VEX_Precision myPrec; // VEX Data precision
190  int myVexIndex; // Offset into VEX symbol table
191  int myArraySize; // Array size
192  bool myExport; // Whether the data is output by VEX
193  bool myVarying; // Whether the data is varying
194  bool myIsArray; // Am I an array?
195  bool myIsConstant; // Am I eligible for constant folding?
196  bool myIsPackedArray; // If the array is packed.
197 
198  friend class CVEX_Context;
199 };
200 
201 #endif
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
bool isExport() const
Query whether the VEX value is an export (or read-only)
Definition: CVEX_Value.h:66
#define SYS_DEPRECATED(__V__)
bool isConstant() const
Definition: CVEX_Value.h:172
CVEX_Type getType() const
Query type of VEX value.
Definition: CVEX_Value.h:62
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
VEX_Precision
Definition: VEX_PodTypes.h:25
void * getRawData()
Definition: CVEX_Value.h:86
Call VEX from C++.
Definition: CVEX_Context.h:151
UT_Array< UT_StringHolder > CVEX_StringArray
Definition: CVEX_Value.h:22
long long int64
Definition: SYS_Types.h:107
bool isVarying() const
Query whether the VEX value is uniform or varying.
Definition: CVEX_Value.h:68
void setIsConstant(bool isconstant)
Definition: CVEX_Value.h:170
double fpreal64
Definition: SYS_Types.h:192
const UT_StringHolder & getName() const
Query name of VEX value.
Definition: CVEX_Value.h:60
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
int int32
Definition: SYS_Types.h:35
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:25
A class representing a VEX value.
Definition: CVEX_Value.h:52
void setPrecision(VEX_Precision p)
Definition: CVEX_Value.h:64
bool isPackedArray() const
Definition: CVEX_Value.h:88
int getArraySize() const
Definition: CVEX_Value.h:72
#define CVEX_API
Definition: CVEX_API.h:10
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
float fpreal32
Definition: SYS_Types.h:191