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.
52 template <VEX_Precision PREC>
54 {
55 public:
58  bool varying);
59  ~CVEX_ValueT();
60 
61  /// Query name of VEX value
62  const UT_StringHolder &getName() const { return myName; }
63  /// Query type of VEX value
64  CVEX_Type getType() const { return myType; }
65  void setType(CVEX_Type type);
66  /// Query whether the VEX value is an export (or read-only)
67  bool isExport() const { return myExport; }
68  /// Query whether the VEX value is uniform or varying
69  bool isVarying() const { return myVarying; }
70  /// Query the array size of the VEX value.
71  /// @note This is @b not the used for VEX arrays, but rather represents the
72  /// number of entries in the varying array.
73  int getArraySize() const { return myArraySize; }
74 
75  /// Get the raw data pointer.
76  /// For numeric types, the data refers to a raw array of data (depending on
77  /// the getType() of the value.
78  /// - CVEX_TYPE_INTEGER @c int
79  /// - CVEX_TYPE_FLOAT @c fpreal32
80  /// - CVEX_TYPE_VECTOR2 @c UT_Vector2F
81  /// - CVEX_TYPE_VECTOR3 @c UT_Vector3F
82  /// - CVEX_TYPE_VECTOR4 @c UT_Vector4F
83  /// - CVEX_TYPE_MATRIX2 @c UT_Matrix2F
84  /// - CVEX_TYPE_MATRIX3 @c UT_Matrix3F
85  /// - CVEX_TYPE_MATRIX4 @c UT_Matrix4F
86  /// For CVEX_TYPE_STRING, the data will point to a UT_StringArray.
87  void *getRawData() { return myData; }
88 
89  bool isPackedArray() const { return myIsPackedArray; }
90 
91  /// The array size is NOT the size in bytes, but rather the array size of
92  /// the input data. It should either be 1 or N, where N is the number of
93  /// values being computed by VEX.
94  ///
95  /// When passing data for output variables, please check to see whether
96  /// the output variable is uniform or varying. Varying values need to
97  /// have a full array of data (including string arrays).
98  ///
99  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
100  /// so the data must be persistent.
101  bool setTypedData(VEXint<PREC> *data, int array_size);
102  bool setTypedData(VEXfloat<PREC> *data, int array_size);
103  bool setTypedData(VEXvec2<PREC> *data, int array_size);
104  bool setTypedData(VEXvec3<PREC> *data, int array_size);
105  bool setTypedData(VEXvec4<PREC> *data, int array_size);
106  bool setTypedData(VEXmat2<PREC> *data, int array_size);
107  bool setTypedData(VEXmat3<PREC> *data, int array_size);
108  bool setTypedData(VEXmat4<PREC> *data, int array_size);
109 
110  /// When setting values for string types, you need to pass in a
111  /// CVEX_StringArray instead of a void *. For input variables, the length
112  /// of the array will determine whether the parameter is varying or
113  /// uniform.
114  ///
115  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
116  /// so the data must be persistent.
117  ///
118  /// When setting data for outputs, the packed arrays should be empty
119  /// and the array size specified.
120  bool setTypedData(CVEX_StringArray &stringdata);
121  bool setTypedData(UT_Array<UT_Array<VEXint<PREC>> > &intdata);
122  bool setTypedData(UT_PackedArrayOfArrays<VEXint<PREC>> &intdata,
123  int arraysize=0);
124  /// This is stored as xyzxyzxyz for vector data.
125  bool setTypedData(UT_Array<UT_Array<VEXfloat<PREC>> > &fltdata);
126  bool setTypedData(UT_PackedArrayOfArrays<VEXfloat<PREC>> &fltdata,
127  int arraysize=0);
128  bool setTypedData(UT_Array<CVEX_StringArray> &stringdata);
129 
130  /// Type unsafe way of setting VEX data. Avoid using if possible.
131  bool setRawData(CVEX_Type type, void *data, int array_size);
132 
133 
134  // Deprecated equivalents. Please avoid, they're error-prone.
135  SYS_DEPRECATED(13.0)
136  void *getData()
137  { return getRawData(); }
138 
139  SYS_DEPRECATED(13.0)
140  bool setData(void *data, int array_size)
141  { return setRawData(myType, data, array_size); }
142 
143  SYS_DEPRECATED(13.0)
144  bool setData(CVEX_StringArray &stringdata)
145  { return setTypedData(stringdata); }
146 
147  static int getTupleSize(CVEX_Type t);
148  static CVEX_Type getArrayBaseType(CVEX_Type t);
149 
150  /// The IsConstant determines eligibility for constant folding.
151  /// It likely implies Uniform. But it is quite reasonable to have
152  /// a Uniform parameter that isn't constant, it is then a demand
153  /// that the VEX Assemble does not fold the input regardless of
154  /// the initial value during load()
155  void setIsConstant(bool isconstant)
156  { myIsConstant = isconstant; }
157  bool isConstant() const
158  { return myIsConstant; }
159 
160  /// Given the list of vex parameters, returns the list of cvex parmeters
161  /// that have valid cvex types.
162  static VEX_Type cvexToVexType(CVEX_Type type, bool &isarray);
163  static CVEX_Type vexToCVexType(VEX_Type vextype, bool isarray);
164 
165 private:
166  void clear();
167  void clearAndAllocArray(bool ispacked);
168 
169  void *myData;
170  void *myStringSet;
171  void *myArrayType;
172  UT_StringHolder myName;
173  CVEX_Type myType; // Data type
174  VEX_Type myVexType; // VEX Type (mapped from CVEX_Type)
175  int myVexIndex; // Offset into VEX symbol table
176  int myArraySize; // Array size
177  bool myExport; // Whether the data is output by VEX
178  bool myVarying; // Whether the data is varying
179  bool myIsArray; // Am I an array?
180  bool myIsConstant; // Am I eligible for constant folding?
181  bool myIsPackedArray; // If the array is packed.
182 
183  template <VEX_Precision ALLPREC>
184  friend class CVEX_ContextT;
185  template <VEX_Precision ALLPREC>
186  friend class CVEX_ValueListT;
187 };
188 
190 
193 
194 #endif
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
#define SYS_DEPRECATED(__V__)
GLuint const GLchar * name
Definition: glew.h:1814
CVEX_EXTERN_TEMPLATE(CVEX_ValueT< VEX_32 >)
CVEX_Type getType() const
Query type of VEX value.
Definition: CVEX_Value.h:64
void setIsConstant(bool isconstant)
Definition: CVEX_Value.h:155
bool isVarying() const
Query whether the VEX value is uniform or varying.
Definition: CVEX_Value.h:69
const UT_StringHolder & getName() const
Query name of VEX value.
Definition: CVEX_Value.h:62
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
int getArraySize() const
Definition: CVEX_Value.h:73
List of input or output values for a CVEX_Context.
UT_Array< UT_StringHolder > CVEX_StringArray
Definition: CVEX_Value.h:22
A class representing a VEX value.
Definition: CVEX_Value.h:53
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
void
Definition: png.h:1083
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:25
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
typename VEX_PrecisionResolver< P >::mat2_type VEXmat2
Definition: VEX_PodTypes.h:72
bool isExport() const
Query whether the VEX value is an export (or read-only)
Definition: CVEX_Value.h:67
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
void * getRawData()
Definition: CVEX_Value.h:87
#define CVEX_API
Definition: CVEX_API.h:12
typename VEX_PrecisionResolver< P >::vec4_type VEXvec4
Definition: VEX_PodTypes.h:71
bool isPackedArray() const
Definition: CVEX_Value.h:89
bool isConstant() const
Definition: CVEX_Value.h:157
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
Call VEX from C++.
Definition: CVEX_Context.h:175
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
GLdouble GLdouble t
Definition: glew.h:1398