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>
18 #include <UT/UT_Options.h>
20 #include <VEX/VEX_PodTypes.h>
21 #include <VEX/VEX_VexTypes.h> // for VEX_Type
22 
25 
26 class UT_JSONWriter;
27 
28 /// The CVEX_Type enum defines the VEX types available to CVEX.
30 {
31  CVEX_TYPE_INVALID = -1, // Invalid type
32  CVEX_TYPE_INTEGER, // Integer
33  CVEX_TYPE_FLOAT, // Float
34  CVEX_TYPE_VECTOR2, // 2-tuple of float
35  CVEX_TYPE_VECTOR3, // 3-tuple of float
36  CVEX_TYPE_VECTOR4, // 4-tuple of float
37  CVEX_TYPE_MATRIX2, // 4-tuple of float
38  CVEX_TYPE_MATRIX3, // 9-tuple of float
39  CVEX_TYPE_MATRIX4, // 16-tuple of float
40  CVEX_TYPE_STRING, // string values
41  CVEX_TYPE_DICT, // dictionary values
42  CVEX_TYPE_INTEGER_ARRAY, // Integer array
43  CVEX_TYPE_FLOAT_ARRAY, // Float array
44  CVEX_TYPE_VECTOR2_ARRAY, // 2-tuple of float array
45  CVEX_TYPE_VECTOR3_ARRAY, // 3-tuple of float array
46  CVEX_TYPE_VECTOR4_ARRAY, // 4-tuple of float array
47  CVEX_TYPE_MATRIX2_ARRAY, // 4-tuple of float array
48  CVEX_TYPE_MATRIX3_ARRAY, // 9-tuple of float array
49  CVEX_TYPE_MATRIX4_ARRAY, // 16-tuple of float array
50  CVEX_TYPE_STRING_ARRAY, // string array.
51  CVEX_TYPE_DICT_ARRAY, // dictionary array.
52 };
53 
54 /// @brief A class representing a VEX value.
55 ///
56 /// The CVEX_Value objects are created internally in the CVEX library. They
57 /// provide a mapping from the CVEX library to the underlying VEX
58 /// representation of objects.
59 template <VEX_Precision PREC>
61 {
62 public:
65  bool varying);
66  ~CVEX_ValueT();
67 
68  /// Query name of VEX value
69  const UT_StringHolder &getName() const { return myName; }
70  /// Query type of VEX value
71  CVEX_Type getType() const { return myType; }
72  void setType(CVEX_Type type);
73  /// Query whether the VEX value is an export (or read-only)
74  bool isExport() const { return myExport; }
75  /// Query whether the VEX value is uniform or varying
76  bool isVarying() const { return myVarying; }
77  /// Query the array size of the VEX value.
78  /// @note This is @b not the used for VEX arrays, but rather represents the
79  /// number of entries in the varying array.
80  int getArraySize() const { return myArraySize; }
81 
82  /// Get the raw data pointer.
83  /// For numeric types, the data refers to a raw array of data (depending on
84  /// the getType() of the value.
85  /// - CVEX_TYPE_INTEGER @c int
86  /// - CVEX_TYPE_FLOAT @c fpreal32
87  /// - CVEX_TYPE_VECTOR2 @c UT_Vector2F
88  /// - CVEX_TYPE_VECTOR3 @c UT_Vector3F
89  /// - CVEX_TYPE_VECTOR4 @c UT_Vector4F
90  /// - CVEX_TYPE_MATRIX2 @c UT_Matrix2F
91  /// - CVEX_TYPE_MATRIX3 @c UT_Matrix3F
92  /// - CVEX_TYPE_MATRIX4 @c UT_Matrix4F
93  /// For CVEX_TYPE_STRING, the data will point to a UT_StringArray.
94  void *getRawData() { return myData; }
95 
96  bool isPackedArray() const { return myIsPackedArray; }
97 
98  /// The array size is NOT the size in bytes, but rather the array size of
99  /// the input data. It should either be 1 or N, where N is the number of
100  /// values being computed by VEX.
101  ///
102  /// When passing data for output variables, please check to see whether
103  /// the output variable is uniform or varying. Varying values need to
104  /// have a full array of data (including string arrays).
105  ///
106  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
107  /// so the data must be persistent.
108  bool setTypedData(VEXint<PREC> *data, int array_size);
109  bool setTypedData(VEXfloat<PREC> *data, int array_size);
110  bool setTypedData(VEXvec2<PREC> *data, int array_size);
111  bool setTypedData(VEXvec3<PREC> *data, int array_size);
112  bool setTypedData(VEXvec4<PREC> *data, int array_size);
113  bool setTypedData(VEXmat2<PREC> *data, int array_size);
114  bool setTypedData(VEXmat3<PREC> *data, int array_size);
115  bool setTypedData(VEXmat4<PREC> *data, int array_size);
116 
117  /// When setting values for string types, you need to pass in a
118  /// CVEX_StringArray instead of a void *. For input variables, the length
119  /// of the array will determine whether the parameter is varying or
120  /// uniform.
121  ///
122  /// The CVEX_Value object will hold a pointer to the CVEX_StringArray,
123  /// so the data must be persistent.
124  ///
125  /// When setting data for outputs, the packed arrays should be empty
126  /// and the array size specified.
127  bool setTypedData(CVEX_StringArray &stringdata);
128  bool setTypedData(CVEX_DictArray &dictdata);
129  bool setTypedData(UT_Array<UT_Array<VEXint<PREC>> > &intdata);
130  bool setTypedData(UT_PackedArrayOfArrays<VEXint<PREC>> &intdata,
131  int arraysize=0);
132  /// This is stored as xyzxyzxyz for vector data.
133  bool setTypedData(UT_Array<UT_Array<VEXfloat<PREC>> > &fltdata);
134  bool setTypedData(UT_PackedArrayOfArrays<VEXfloat<PREC>> &fltdata,
135  int arraysize=0);
136  bool setTypedData(UT_Array<CVEX_StringArray> &stringdata);
137  bool setTypedData(UT_Array<CVEX_DictArray> &dictdata);
138 
139  /// Type unsafe way of setting VEX data. Avoid using if possible.
140  bool setRawData(CVEX_Type type, void *data, int array_size);
141 
142 
143  // Deprecated equivalents. Please avoid, they're error-prone.
144  SYS_DEPRECATED(13.0)
145  void *getData()
146  { return getRawData(); }
147 
148  SYS_DEPRECATED(13.0)
149  bool setData(void *data, int array_size)
150  { return setRawData(myType, data, array_size); }
151 
152  SYS_DEPRECATED(13.0)
153  bool setData(CVEX_StringArray &stringdata)
154  { return setTypedData(stringdata); }
155 
156  static int getTupleSize(CVEX_Type t);
157  static CVEX_Type getArrayBaseType(CVEX_Type t);
158 
159  /// The IsConstant determines eligibility for constant folding.
160  /// It likely implies Uniform. But it is quite reasonable to have
161  /// a Uniform parameter that isn't constant, it is then a demand
162  /// that the VEX Assemble does not fold the input regardless of
163  /// the initial value during load()
164  void setIsConstant(bool isconstant)
165  { myIsConstant = isconstant; }
166  bool isConstant() const
167  { return myIsConstant; }
168 
169  /// Given the list of vex parameters, returns the list of cvex parmeters
170  /// that have valid cvex types.
171  static VEX_Type cvexToVexType(CVEX_Type type, bool &isarray);
172  static CVEX_Type vexToCVexType(VEX_Type vextype, bool isarray);
173 
174  /// For debugging
175  void dump() const;
176  void dump(UT_JSONWriter &w) const;
177 
178 private:
179  void dumpValue(UT_JSONWriter &w) const;
180  void clear();
181  void clearAndAllocArray(bool ispacked);
182 
183  void *myData;
184  void *myStringSet;
185  void *myDictSet;
186  void *myArrayType;
187  UT_StringHolder myName;
188  CVEX_Type myType; // Data type
189  VEX_Type myVexType; // VEX Type (mapped from CVEX_Type)
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  template <VEX_Precision ALLPREC>
199  friend class CVEX_ContextT;
200  template <VEX_Precision ALLPREC>
201  friend class CVEX_ValueListT;
202 };
203 
205 
208 
209 #endif
VEX_Type
VEX variable types.
Definition: VEX_VexTypes.h:18
#define SYS_DEPRECATED(__V__)
CVEX_EXTERN_TEMPLATE(CVEX_ValueT< VEX_32 >)
CVEX_Type getType() const
Query type of VEX value.
Definition: CVEX_Value.h:71
void
Definition: png.h:1083
void setIsConstant(bool isconstant)
Definition: CVEX_Value.h:164
bool isVarying() const
Query whether the VEX value is uniform or varying.
Definition: CVEX_Value.h:76
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
const UT_StringHolder & getName() const
Query name of VEX value.
Definition: CVEX_Value.h:69
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
int getArraySize() const
Definition: CVEX_Value.h:80
List of input or output values for a CVEX_Context.
A class representing a VEX value.
Definition: CVEX_Value.h:60
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
typename VEX_PrecisionResolver< P >::mat4_type VEXmat4
Definition: VEX_PodTypes.h:74
GLuint const GLchar * name
Definition: glcorearb.h:786
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:29
GLdouble t
Definition: glad.h:2397
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:74
typename VEX_PrecisionResolver< P >::vec2_type VEXvec2
Definition: VEX_PodTypes.h:69
void * getRawData()
Definition: CVEX_Value.h:94
#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:96
bool isConstant() const
Definition: CVEX_Value.h:166
typename VEX_PrecisionResolver< P >::int_type VEXint
Definition: VEX_PodTypes.h:68
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
Call VEX from C++.
Definition: CVEX_Context.h:203
type
Definition: core.h:1059
typename VEX_PrecisionResolver< P >::mat3_type VEXmat3
Definition: VEX_PodTypes.h:73
Definition: format.h:895