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