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 
53 
58 
72 
79 
86 
92 
100 
110 
115 
120 
125 
129 
132 
134 
136 
138 
140 };
141 #define RE_UNIFORM_CUSTOM RE_UNIFORM_BUILT_IN__count
142 
143 // RE_Uniform::typeTypeSizes expects this ordering. If you modify this
144 // enumeration, make sure that you also modify 'theTypeSizes' initialization.
146 {
221 
223 };
224 
226 
228 {
229 public:
230  // 'size' is the array size.
231  RE_Uniform(const char *name, RE_UniformType type, int size = 1);
232  RE_Uniform(RE_UniformBuiltIn built_in, int size);
233  ~RE_Uniform() override;
234 
235  bool operator==(const RE_Uniform &uniform) const;
236 
237  // Removes the array subscript "[]" from the end of 'name' if there is one
238  // and stores the result in 'out'.
239  static void getArrayNameAndIndex(const char *str,
240  UT_String &name_out,
241  int *index_out);
242 
243  // Appends an array subscript to the name of this uniform and stores the
244  // result in 'out'. Only call this method for array uniforms.
245  void getIndexedName(int index, UT_WorkBuffer &out)const;
246  //void getIndexedName(int index, UT_String &out)const;
247 
248  const UT_StringHolder &getName() const { return myName; }
249 
250  // getSize() returns the array size or 1 if this uniform is not an array.
251  // Note that GLSL allows arrays of size 1 so this method cannot be used
252  // to determine whether or not this uniform is an array.
253  int getSize() const { return myArraySize; }
254  RE_UniformType getType() const { return myType; }
255  RE_UniformBuiltIn getBuiltInType() const { return myUniformType; }
256  int getByteSize() const { return myValueBytes; }
257  int getByteCapacity() const { return myValueCapacity; }
258 
259  // Get/set the value of this uniform. If this uniform is an array
260  // then 'index' specifies which array element value to return/set;
261  // otherwise, its ignored.
262  const void *getValue(int index=0) const;
263  void *getValue(int index=0);
264  bool setValue(const void *value, int index=0);
265  bool setValues(const void *value);
266 
267  // Return the color or alpha for (R,G,B,A) color values. Will assert if the
268  // uniform is not a color.
269  UT_Color getColor(int index=0) const;
270  fpreal getAlpha(int index=0) const;
271 
272  UT_Vector2F getVector2(int index=0) const;
273  UT_Vector3F getVector3(int index=0) const;
274  UT_Vector4F getVector4(int index=0) const;
275 
276  UT_Matrix3D getMatrix3(int index=0) const;
277  UT_Matrix4D getMatrix4(int index=0) const;
278 
279  // Copy the values of 'copy' into this uniform. The type and size must
280  // match. Returns true if the value changed.
281  bool copy(const RE_Uniform *copy);
282 
283  // Copy the values in data into this uniform. The array must be at least
284  // as large as the value returned by getByteSize(). Returns true if the
285  // value changed.
286  bool copyBytes(const void *data);
287 
288  // The version is incremented whenever the value of this uniform is
289  // changed. The version starts at 0.
290  int getVersion() const { return myVersion; }
291 
292  void setAutoGenerated(bool gen=true)
293  { myAutoGeneratedFlag = gen; }
294  bool isAutoGenerated() const {return myAutoGeneratedFlag;}
295 
296  // Returns an element of RE_UniformBuiltIn if the specified uniform's
297  // type, size, and name match the RE_UniformBuiltIn's type, size, and
298  // name and the uniform is supported for the specified language; otherwise,
299  // returns -1.
300  static int getBuiltIn(const RE_Uniform *uniform,
301  int languages =
303  static int getBuiltIn(const UT_StringHolder &name,
304  RE_UniformType type,
305  int languages =
307 
308  // Static member functions for retrieving information about built-in
309  // uniforms.
310  static const char *getBuiltInName(RE_UniformBuiltIn built_in);
311  static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
312 
313  static void initBuiltIns();
314 
315  // Specify that a given uniform object should represent a given built-in
316  // uniform. After a built-in has been registered, calling getBuiltIn(int)
317  // returns the registered uniform object. By specifying a uniform object
318  // when calling unregisterBuilInt(), the built-in will only be unregistered
319  // if the currently registered uniform object matches the specified object.
320  static void registerBuiltIn(RE_Render *r,
321  RE_UniformBuiltIn built_in,
322  const RE_Uniform &uniform);
323 
324  // A convenience version for single-index variables. 'data' must match the
325  // uniform's data type.
326  static void registerBuiltIn(RE_Render *r,
327  RE_UniformBuiltIn built_in,
328  const void *data = nullptr);
329 
330  // Assign a new value to a previous registered uniform.
331  static bool assignBuiltIn(RE_Render *r,
332  RE_UniformBuiltIn built_in,
333  const void *data);
334 
335  // Assign a range of values to a previously registered uniform array.
336  // Element zero passed in 'data' always corresponds to element 'start' in
337  // the uniform.
338  static bool assignBuiltInArray(RE_Render *r,
339  RE_UniformBuiltIn built_in,
340  const void *data,
341  int start,
342  int num);
343 
344  // Remove the uniform. If registerBuiltIn was called, the unform is unbound
345  // only. If assignBuiltIn was called, the uniform is unbound and deleted.
346  static void unregisterBuiltIn(RE_Render *r,
347  RE_UniformBuiltIn built_in);
348 
349  void print() const;
350 
351  // For RE_Shader - caching of uniform index in the uniform.
352  void storeShaderUniformIndex(const RE_Shader *sh,
353  int index) const;
354  int getShaderUniformIndex(const RE_Shader *sh) const;
355 
356  void copyTo(RE_UniformStackEntry &entry) const;
357  void copyFrom(const RE_UniformStackEntry &entry);
358 
359 
360  static int getVectorSize(RE_UniformType type);
361  static bool isFloat(RE_UniformType type);
362  static bool isInt(RE_UniformType type);
363  static bool isSampler(RE_UniformType type);
364  static bool isImage(RE_UniformType type);
365 
366 private:
367  static const int theTypeSizes[RE_UNIFORM_TYPE__count];
368  UT_StringHolder myName;
369  RE_UniformType myType;
370  int myArraySize;
371  int myValueBytes;
372  int myValueCapacity;
373  int myVersion;
374  char *myValues;
375  bool myAutoGeneratedFlag;
376  RE_UniformBuiltIn myUniformType;
377 
378  // uniform index caching
379  mutable int myStoredIndex;
380  mutable int myStoredShaderSerial;
381  mutable const void *myStoredShader; // void *, ptr compare only
382 };
383 
385 {
386 public:
388  : myByteSize(0), myArraySize(0), myVersion(0), myData(nullptr) {}
390  {
391  if(myData)
392  free(myData);
393  }
394 
395  void *myData;
399 };
400 
401 #endif
RE_UniformStackEntry()
Definition: RE_Uniform.h:387
RE_UniformType getType() const
Definition: RE_Uniform.h:254
RE_UniformBuiltIn getBuiltInType() const
Definition: RE_Uniform.h:255
#define RE_API
Definition: RE_API.h:10
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
GLuint start
Definition: glcorearb.h:475
bool isAutoGenerated() const
Definition: RE_Uniform.h:294
void setAutoGenerated(bool gen=true)
Definition: RE_Uniform.h:292
GLuint const GLchar * name
Definition: glcorearb.h:786
RE_UniformType
Definition: RE_Uniform.h:145
GLsizeiptr size
Definition: glcorearb.h:664
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLuint num
Definition: glew.h:2695
int getByteCapacity() const
Definition: RE_Uniform.h:257
GA_API const UT_StringHolder gen
RE_UniformBuiltIn
Definition: RE_Uniform.h:28
int myArraySize
Definition: RE_Uniform.h:397
int getSize() const
Definition: RE_Uniform.h:253
int myVersion
Definition: RE_Uniform.h:396
fpreal64 fpreal
Definition: SYS_Types.h:277
int getByteSize() const
Definition: RE_Uniform.h:256
const UT_StringHolder & getName() const
Definition: RE_Uniform.h:248
GLuint index
Definition: glcorearb.h:786
IMF_EXPORT bool isImage(const std::string &name)
Definition: core.h:1131
~RE_UniformStackEntry()
Definition: RE_Uniform.h:389
int myByteSize
Definition: RE_Uniform.h:398
type
Definition: core.h:1059
GLboolean r
Definition: glcorearb.h:1222
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
Definition: RE_Uniform.h:384
Definition: format.h:895
void * myData
Definition: RE_Uniform.h:395
int getVersion() const
Definition: RE_Uniform.h:290