HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RE_Uniform.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: RE_Uniform.h (Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __RE_Uniform__
12 #define __RE_Uniform__
13 
14 #include "RE_API.h"
15 
16 #include <UT/UT_Color.h>
17 #include <UT/UT_String.h>
18 #include <UT/UT_LinkList.h>
19 #include "RE_Types.h"
20 
21 class RE_Render;
22 class RE_Shader;
23 
24 // The members of this enumeration are used as indices into
25 // re_BuiltInUniform::theUniforms. Thus, changing this enumeration requires
26 // updating re_BuiltInUniform::theUniforms.
28 {
33 
43 
51 
56 
67 
73 
80 
86 
94 
100 
105 
110 
115 
117 
120 
122 
124 
126 };
127 #define RE_UNIFORM_CUSTOM RE_UNIFORM_BUILT_IN__count
128 
129 // RE_Uniform::typeTypeSizes expects this ordering. If you modify this
130 // enumeration, make sure that you also modify 'theTypeSizes' initialization.
132 {
206 
208 };
209 
211 
213 {
214 public:
215  // 'size' is the array size.
216  RE_Uniform(const char *name, RE_UniformType type, int size = 1);
217  RE_Uniform(RE_UniformBuiltIn built_in, int size);
218  virtual ~RE_Uniform();
219 
220  bool operator==(const RE_Uniform &uniform) const;
221 
222  // Removes the array subscript "[]" from the end of 'name' if there is one
223  // and stores the result in 'out'.
224  static void getArrayNameAndIndex(const char *str,
225  UT_String &name_out,
226  int *index_out);
227 
228  // Appends an array subscript to the name of this uniform and stores the
229  // result in 'out'. Only call this method for array uniforms.
230  void getIndexedName(int index, UT_String &out)const;
231 
232  const UT_String &getName() const { return myName; }
233 
234  // getSize() returns the array size or 1 if this uniform is not an array.
235  // Note that GLSL allows arrays of size 1 so this method cannot be used
236  // to determine whether or not this uniform is an array.
237  int getSize() const { return myArraySize; }
238  RE_UniformType getType() const { return myType; }
239  RE_UniformBuiltIn getBuiltInType() const { return myUniformType; }
240  int getByteSize() const { return myValueBytes; }
241 
242  // Get/set the value of this uniform. If this uniform is an array
243  // then 'index' specifies which array element value to return/set;
244  // otherwise, its ignored.
245  const void *getValue(int index=0) const;
246  bool setValue(const void *value, int index=0);
247  bool setValues(const void *value);
248 
249  // Return the color or alpha for (R,G,B,A) color values. Will assert if the
250  // uniform is not a color.
251  UT_Color getColor(int index=0) const;
252  fpreal getAlpha(int index=0) const;
253 
254  UT_Vector2F getVector2(int index=0) const;
255  UT_Vector3F getVector3(int index=0) const;
256  UT_Vector4F getVector4(int index=0) const;
257 
258  UT_Matrix3D getMatrix3(int index=0) const;
259  UT_Matrix4D getMatrix4(int index=0) const;
260 
261  // Copy the values of 'copy' into this uniform. The type and size must
262  // match. Returns true if the value changed.
263  bool copy(const RE_Uniform *copy);
264 
265  // Copy the values in data into this uniform. The array must be at least
266  // as large as the value returned by getByteSize(). Returns true if the
267  // value changed.
268  bool copyBytes(const void *data);
269 
270  // The version is incremented whenever the value of this uniform is
271  // changed. The version starts at 0.
272  int getVersion() const { return myVersion; }
273 
274  void setAutoGenerated(bool gen=true)
275  { myAutoGeneratedFlag = gen; }
276  bool isAutoGenerated() const {return myAutoGeneratedFlag;}
277 
278  // Returns an element of RE_UniformBuiltIn if the specified uniform's
279  // type, size, and name match the RE_UniformBuiltIn's type, size, and
280  // name and the uniform is supported for the specified language; otherwise,
281  // returns -1.
282  static int getBuiltIn(const RE_Uniform *uniform,
283  int languages =
285  static int getBuiltIn(const UT_String &name,
286  RE_UniformType type,
287  int languages =
289 
290  // Static member functions for retrieving information about built-in
291  // uniforms.
292  static const char *getBuiltInName(RE_UniformBuiltIn built_in);
293  static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
294 
295  static void initBuiltIns();
296 
297  // Specify that a given uniform object should represent a given built-in
298  // uniform. After a built-in has been registered, calling getBuiltIn(int)
299  // returns the registered uniform object. By specifying a uniform object
300  // when calling unregisterBuilInt(), the built-in will only be unregistered
301  // if the currently registered uniform object matches the specified object.
302  static void registerBuiltIn(RE_Render *r,
303  RE_UniformBuiltIn built_in,
304  const RE_Uniform &uniform);
305 
306  // A convenience version for single-index variables. 'data' must match the
307  // uniform's data type.
308  static void registerBuiltIn(RE_Render *r,
309  RE_UniformBuiltIn built_in,
310  const void *data = NULL);
311 
312  // Assign a new value to a previous registered uniform.
313  static bool assignBuiltIn(RE_Render *r,
314  RE_UniformBuiltIn built_in,
315  const void *data);
316 
317  // Assign a range of values to a previously registered uniform array.
318  // Element zero passed in 'data' always corresponds to element 'start' in
319  // the uniform.
320  static bool assignBuiltInArray(RE_Render *r,
321  RE_UniformBuiltIn built_in,
322  const void *data,
323  int start,
324  int num);
325 
326  // Remove the uniform. If registerBuiltIn was called, the unform is unbound
327  // only. If assignBuiltIn was called, the uniform is unbound and deleted.
328  static void unregisterBuiltIn(RE_Render *r,
329  RE_UniformBuiltIn built_in);
330 
331  void print() const;
332 
333  // For RE_Shader - caching of uniform index in the uniform.
334  void storeShaderUniformIndex(const RE_Shader *sh,
335  int index) const;
336  int getShaderUniformIndex(const RE_Shader *sh) const;
337 
338  void copyTo(RE_UniformStackEntry &entry) const;
339  void copyFrom(const RE_UniformStackEntry &entry);
340 
341 
342  static int getVectorSize(RE_UniformType type);
343  static bool isFloat(RE_UniformType type);
344  static bool isInt(RE_UniformType type);
345  static bool isSampler(RE_UniformType type);
346 
347 private:
348  static const int theTypeSizes[RE_UNIFORM_TYPE__count];
349  UT_String myName;
350  RE_UniformType myType;
351  int myArraySize;
352  int myValueBytes;
353  int myVersion;
354  char *myValues;
355  bool myAutoGeneratedFlag;
356  RE_UniformBuiltIn myUniformType;
357 
358  // uniform index caching
359  mutable int myStoredIndex;
360  mutable int myStoredShaderSerial;
361  mutable const void *myStoredShader; // void *, ptr compare only
362 };
363 
365 {
366 public:
368  : myByteSize(0), myArraySize(0), myVersion(0), myData(NULL) {}
370  {
371  if(myData)
372  free(myData);
373  }
374 
375  void *myData;
379 };
380 
381 #endif
382 
RE_UniformStackEntry()
Definition: RE_Uniform.h:367
RE_UniformType getType() const
Definition: RE_Uniform.h:238
RE_UniformBuiltIn getBuiltInType() const
Definition: RE_Uniform.h:239
#define RE_API
Definition: RE_API.h:10
GLuint start
Definition: glcorearb.h:474
bool isAutoGenerated() const
Definition: RE_Uniform.h:276
void setAutoGenerated(bool gen=true)
Definition: RE_Uniform.h:274
RE_UniformType
Definition: RE_Uniform.h:131
GLsizeiptr size
Definition: glcorearb.h:663
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GA_API const UT_StringHolder gen
RE_UniformBuiltIn
Definition: RE_Uniform.h:27
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
int myArraySize
Definition: RE_Uniform.h:377
int getSize() const
Definition: RE_Uniform.h:237
GLsizei const GLfloat * value
Definition: glcorearb.h:823
double fpreal
Definition: SYS_Types.h:269
int myVersion
Definition: RE_Uniform.h:376
int getByteSize() const
Definition: RE_Uniform.h:240
GLuint index
Definition: glcorearb.h:785
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
png_infop png_uint_32 int num
Definition: png.h:2158
GLboolean r
Definition: glcorearb.h:1221
~RE_UniformStackEntry()
Definition: RE_Uniform.h:369
int myByteSize
Definition: RE_Uniform.h:378
Definition: RE_Uniform.h:364
const UT_String & getName() const
Definition: RE_Uniform.h:232
void * myData
Definition: RE_Uniform.h:375
int getVersion() const
Definition: RE_Uniform.h:272