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  ~RE_Uniform() override;
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  int getByteCapacity() const { return myValueCapacity; }
250 
251  // Get/set the value of this uniform. If this uniform is an array
252  // then 'index' specifies which array element value to return/set;
253  // otherwise, its ignored.
254  const void *getValue(int index=0) const;
255  bool setValue(const void *value, int index=0);
256  bool setValues(const void *value);
257 
258  // Return the color or alpha for (R,G,B,A) color values. Will assert if the
259  // uniform is not a color.
260  UT_Color getColor(int index=0) const;
261  fpreal getAlpha(int index=0) const;
262 
263  UT_Vector2F getVector2(int index=0) const;
264  UT_Vector3F getVector3(int index=0) const;
265  UT_Vector4F getVector4(int index=0) const;
266 
267  UT_Matrix3D getMatrix3(int index=0) const;
268  UT_Matrix4D getMatrix4(int index=0) const;
269 
270  // Copy the values of 'copy' into this uniform. The type and size must
271  // match. Returns true if the value changed.
272  bool copy(const RE_Uniform *copy);
273 
274  // Copy the values in data into this uniform. The array must be at least
275  // as large as the value returned by getByteSize(). Returns true if the
276  // value changed.
277  bool copyBytes(const void *data);
278 
279  // The version is incremented whenever the value of this uniform is
280  // changed. The version starts at 0.
281  int getVersion() const { return myVersion; }
282 
283  void setAutoGenerated(bool gen=true)
284  { myAutoGeneratedFlag = gen; }
285  bool isAutoGenerated() const {return myAutoGeneratedFlag;}
286 
287  // Returns an element of RE_UniformBuiltIn if the specified uniform's
288  // type, size, and name match the RE_UniformBuiltIn's type, size, and
289  // name and the uniform is supported for the specified language; otherwise,
290  // returns -1.
291  static int getBuiltIn(const RE_Uniform *uniform,
292  int languages =
294  static int getBuiltIn(const UT_StringHolder &name,
295  RE_UniformType type,
296  int languages =
298 
299  // Static member functions for retrieving information about built-in
300  // uniforms.
301  static const char *getBuiltInName(RE_UniformBuiltIn built_in);
302  static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
303 
304  static void initBuiltIns();
305 
306  // Specify that a given uniform object should represent a given built-in
307  // uniform. After a built-in has been registered, calling getBuiltIn(int)
308  // returns the registered uniform object. By specifying a uniform object
309  // when calling unregisterBuilInt(), the built-in will only be unregistered
310  // if the currently registered uniform object matches the specified object.
311  static void registerBuiltIn(RE_Render *r,
312  RE_UniformBuiltIn built_in,
313  const RE_Uniform &uniform);
314 
315  // A convenience version for single-index variables. 'data' must match the
316  // uniform's data type.
317  static void registerBuiltIn(RE_Render *r,
318  RE_UniformBuiltIn built_in,
319  const void *data = NULL);
320 
321  // Assign a new value to a previous registered uniform.
322  static bool assignBuiltIn(RE_Render *r,
323  RE_UniformBuiltIn built_in,
324  const void *data);
325 
326  // Assign a range of values to a previously registered uniform array.
327  // Element zero passed in 'data' always corresponds to element 'start' in
328  // the uniform.
329  static bool assignBuiltInArray(RE_Render *r,
330  RE_UniformBuiltIn built_in,
331  const void *data,
332  int start,
333  int num);
334 
335  // Remove the uniform. If registerBuiltIn was called, the unform is unbound
336  // only. If assignBuiltIn was called, the uniform is unbound and deleted.
337  static void unregisterBuiltIn(RE_Render *r,
338  RE_UniformBuiltIn built_in);
339 
340  void print() const;
341 
342  // For RE_Shader - caching of uniform index in the uniform.
343  void storeShaderUniformIndex(const RE_Shader *sh,
344  int index) const;
345  int getShaderUniformIndex(const RE_Shader *sh) const;
346 
347  void copyTo(RE_UniformStackEntry &entry) const;
348  void copyFrom(const RE_UniformStackEntry &entry);
349 
350 
351  static int getVectorSize(RE_UniformType type);
352  static bool isFloat(RE_UniformType type);
353  static bool isInt(RE_UniformType type);
354  static bool isSampler(RE_UniformType type);
355  static bool isImage(RE_UniformType type);
356 
357 private:
358  static const int theTypeSizes[RE_UNIFORM_TYPE__count];
359  UT_StringHolder myName;
360  RE_UniformType myType;
361  int myArraySize;
362  int myValueBytes;
363  int myValueCapacity;
364  int myVersion;
365  char *myValues;
366  bool myAutoGeneratedFlag;
367  RE_UniformBuiltIn myUniformType;
368 
369  // uniform index caching
370  mutable int myStoredIndex;
371  mutable int myStoredShaderSerial;
372  mutable const void *myStoredShader; // void *, ptr compare only
373 };
374 
376 {
377 public:
379  : myByteSize(0), myArraySize(0), myVersion(0), myData(NULL) {}
381  {
382  if(myData)
383  free(myData);
384  }
385 
386  void *myData;
390 };
391 
392 #endif
RE_UniformStackEntry()
Definition: RE_Uniform.h:378
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:285
void setAutoGenerated(bool gen=true)
Definition: RE_Uniform.h:283
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
int getByteCapacity() const
Definition: RE_Uniform.h:249
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:388
int getSize() const
Definition: RE_Uniform.h:245
GLuint start
Definition: glew.h:1253
int myVersion
Definition: RE_Uniform.h:387
GLuint num
Definition: glew.h:2690
fpreal64 fpreal
Definition: SYS_Types.h:277
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:380
int myByteSize
Definition: RE_Uniform.h:389
GLsizei const GLfloat * value
Definition: glew.h:1849
Definition: RE_Uniform.h:375
void * myData
Definition: RE_Uniform.h:386
int getVersion() const
Definition: RE_Uniform.h:281
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