HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #include "RE_UniformNames.h"
21 
22 class RE_Render;
23 class RE_Shader;
24 
25 // The members of this enumeration are used as indices into
26 // re_BuiltInUniform::theUniforms. Thus, changing this enumeration requires
27 // updating re_BuiltInUniform::theUniforms.
29 {
34 
44 
52 
57 
69 
75 
82 
88 
96 
106 
111 
116 
121 
123 
126 
128 
130 
132 };
133 #define RE_UNIFORM_CUSTOM RE_UNIFORM_BUILT_IN__count
134 
135 // RE_Uniform::typeTypeSizes expects this ordering. If you modify this
136 // enumeration, make sure that you also modify 'theTypeSizes' initialization.
138 {
213 
215 };
216 
218 
220 {
221 public:
222  // 'size' is the array size.
223  RE_Uniform(const char *name, RE_UniformType type, int size = 1);
224  RE_Uniform(RE_UniformBuiltIn built_in, int size);
225  virtual ~RE_Uniform();
226 
227  bool operator==(const RE_Uniform &uniform) const;
228 
229  // Removes the array subscript "[]" from the end of 'name' if there is one
230  // and stores the result in 'out'.
231  static void getArrayNameAndIndex(const char *str,
232  UT_String &name_out,
233  int *index_out);
234 
235  // Appends an array subscript to the name of this uniform and stores the
236  // result in 'out'. Only call this method for array uniforms.
237  void getIndexedName(int index, UT_WorkBuffer &out)const;
238  //void getIndexedName(int index, UT_String &out)const;
239 
240  const UT_StringHolder &getName() const { return myName; }
241 
242  // getSize() returns the array size or 1 if this uniform is not an array.
243  // Note that GLSL allows arrays of size 1 so this method cannot be used
244  // to determine whether or not this uniform is an array.
245  int getSize() const { return myArraySize; }
246  RE_UniformType getType() const { return myType; }
247  RE_UniformBuiltIn getBuiltInType() const { return myUniformType; }
248  int getByteSize() const { return myValueBytes; }
249 
250  // Get/set the value of this uniform. If this uniform is an array
251  // then 'index' specifies which array element value to return/set;
252  // otherwise, its ignored.
253  const void *getValue(int index=0) const;
254  bool setValue(const void *value, int index=0);
255  bool setValues(const void *value);
256 
257  // Return the color or alpha for (R,G,B,A) color values. Will assert if the
258  // uniform is not a color.
259  UT_Color getColor(int index=0) const;
260  fpreal getAlpha(int index=0) const;
261 
262  UT_Vector2F getVector2(int index=0) const;
263  UT_Vector3F getVector3(int index=0) const;
264  UT_Vector4F getVector4(int index=0) const;
265 
266  UT_Matrix3D getMatrix3(int index=0) const;
267  UT_Matrix4D getMatrix4(int index=0) const;
268 
269  // Copy the values of 'copy' into this uniform. The type and size must
270  // match. Returns true if the value changed.
271  bool copy(const RE_Uniform *copy);
272 
273  // Copy the values in data into this uniform. The array must be at least
274  // as large as the value returned by getByteSize(). Returns true if the
275  // value changed.
276  bool copyBytes(const void *data);
277 
278  // The version is incremented whenever the value of this uniform is
279  // changed. The version starts at 0.
280  int getVersion() const { return myVersion; }
281 
282  void setAutoGenerated(bool gen=true)
283  { myAutoGeneratedFlag = gen; }
284  bool isAutoGenerated() const {return myAutoGeneratedFlag;}
285 
286  // Returns an element of RE_UniformBuiltIn if the specified uniform's
287  // type, size, and name match the RE_UniformBuiltIn's type, size, and
288  // name and the uniform is supported for the specified language; otherwise,
289  // returns -1.
290  static int getBuiltIn(const RE_Uniform *uniform,
291  int languages =
293  static int getBuiltIn(const UT_StringHolder &name,
294  RE_UniformType type,
295  int languages =
297 
298  // Static member functions for retrieving information about built-in
299  // uniforms.
300  static const char *getBuiltInName(RE_UniformBuiltIn built_in);
301  static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
302 
303  static void initBuiltIns();
304 
305  // Specify that a given uniform object should represent a given built-in
306  // uniform. After a built-in has been registered, calling getBuiltIn(int)
307  // returns the registered uniform object. By specifying a uniform object
308  // when calling unregisterBuilInt(), the built-in will only be unregistered
309  // if the currently registered uniform object matches the specified object.
310  static void registerBuiltIn(RE_Render *r,
311  RE_UniformBuiltIn built_in,
312  const RE_Uniform &uniform);
313 
314  // A convenience version for single-index variables. 'data' must match the
315  // uniform's data type.
316  static void registerBuiltIn(RE_Render *r,
317  RE_UniformBuiltIn built_in,
318  const void *data = NULL);
319 
320  // Assign a new value to a previous registered uniform.
321  static bool assignBuiltIn(RE_Render *r,
322  RE_UniformBuiltIn built_in,
323  const void *data);
324 
325  // Assign a range of values to a previously registered uniform array.
326  // Element zero passed in 'data' always corresponds to element 'start' in
327  // the uniform.
328  static bool assignBuiltInArray(RE_Render *r,
329  RE_UniformBuiltIn built_in,
330  const void *data,
331  int start,
332  int num);
333 
334  // Remove the uniform. If registerBuiltIn was called, the unform is unbound
335  // only. If assignBuiltIn was called, the uniform is unbound and deleted.
336  static void unregisterBuiltIn(RE_Render *r,
337  RE_UniformBuiltIn built_in);
338 
339  void print() const;
340 
341  // For RE_Shader - caching of uniform index in the uniform.
342  void storeShaderUniformIndex(const RE_Shader *sh,
343  int index) const;
344  int getShaderUniformIndex(const RE_Shader *sh) const;
345 
346  void copyTo(RE_UniformStackEntry &entry) const;
347  void copyFrom(const RE_UniformStackEntry &entry);
348 
349 
350  static int getVectorSize(RE_UniformType type);
351  static bool isFloat(RE_UniformType type);
352  static bool isInt(RE_UniformType type);
353  static bool isSampler(RE_UniformType type);
354  static bool isImage(RE_UniformType type);
355 
356 private:
357  static const int theTypeSizes[RE_UNIFORM_TYPE__count];
358  UT_StringHolder myName;
359  RE_UniformType myType;
360  int myArraySize;
361  int myValueBytes;
362  int myVersion;
363  char *myValues;
364  bool myAutoGeneratedFlag;
365  RE_UniformBuiltIn myUniformType;
366 
367  // uniform index caching
368  mutable int myStoredIndex;
369  mutable int myStoredShaderSerial;
370  mutable const void *myStoredShader; // void *, ptr compare only
371 };
372 
374 {
375 public:
377  : myByteSize(0), myArraySize(0), myVersion(0), myData(NULL) {}
379  {
380  if(myData)
381  free(myData);
382  }
383 
384  void *myData;
388 };
389 
390 #endif
RE_UniformStackEntry()
Definition: RE_Uniform.h:376
RE_UniformType getType() const
Definition: RE_Uniform.h:246
RE_UniformBuiltIn getBuiltInType() const
Definition: RE_Uniform.h:247
GLsizeiptr size
Definition: glew.h:1681
GLuint const GLchar * name
Definition: glew.h:1814
#define RE_API
Definition: RE_API.h:10
GLuint index
Definition: glew.h:1814
bool isAutoGenerated() const
Definition: RE_Uniform.h:284
void setAutoGenerated(bool gen=true)
Definition: RE_Uniform.h:282
RE_UniformType
Definition: RE_Uniform.h:137
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GA_API const UT_StringHolder gen
RE_UniformBuiltIn
Definition: RE_Uniform.h:28
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
int myArraySize
Definition: RE_Uniform.h:386
int getSize() const
Definition: RE_Uniform.h:245
GLuint start
Definition: glew.h:1253
double fpreal
Definition: SYS_Types.h:276
int myVersion
Definition: RE_Uniform.h:385
GLuint num
Definition: glew.h:2690
int getByteSize() const
Definition: RE_Uniform.h:248
const UT_StringHolder & getName() const
Definition: RE_Uniform.h:240
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
OIIO_API bool copy(string_view from, string_view to, std::string &err)
IMF_EXPORT bool isImage(const std::string &name)
~RE_UniformStackEntry()
Definition: RE_Uniform.h:378
int myByteSize
Definition: RE_Uniform.h:387
GLsizei const GLfloat * value
Definition: glew.h:1849
Definition: RE_Uniform.h:373
void * myData
Definition: RE_Uniform.h:384
int getVersion() const
Definition: RE_Uniform.h:280
std::enable_if< internal::is_string< S >::value >::type print(std::basic_ostream< FMT_CHAR(S)> &os, const S &format_str, const Args &...args)
Definition: ostream.h:146