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  int getInt(int index=0) const;
268  fpreal getFloat(int index=0) const;
269 
270  // Return the color or alpha for (R,G,B,A) color values. Will assert if the
271  // uniform is not a color.
272  UT_Color getColor(int index=0) const;
273  fpreal getAlpha(int index=0) const;
274 
275  UT_Vector2F getVector2(int index=0) const;
276  UT_Vector3F getVector3(int index=0) const;
277  UT_Vector4F getVector4(int index=0) const;
278 
279  UT_Vector3i getVector3i(int index=0) const;
280 
281  UT_Matrix3D getMatrix3(int index=0) const;
282  UT_Matrix4D getMatrix4(int index=0) const;
283 
284  // Copy the values of 'copy' into this uniform. The type and size must
285  // match. Returns true if the value changed.
286  bool copy(const RE_Uniform *copy);
287 
288  // Copy the values in data into this uniform. The array must be at least
289  // as large as the value returned by getByteSize(). Returns true if the
290  // value changed.
291  bool copyBytes(const void *data);
292 
293  // The version is incremented whenever the value of this uniform is
294  // changed. The version starts at 0.
295  int getVersion() const { return myVersion; }
296 
297  void setAutoGenerated(bool gen=true)
298  { myAutoGeneratedFlag = gen; }
299  bool isAutoGenerated() const {return myAutoGeneratedFlag;}
300 
301  // Returns an element of RE_UniformBuiltIn if the specified uniform's
302  // type, size, and name match the RE_UniformBuiltIn's type, size, and
303  // name and the uniform is supported for the specified language; otherwise,
304  // returns -1.
305  static int getBuiltIn(const RE_Uniform *uniform,
306  int languages =
308  static int getBuiltIn(const UT_StringHolder &name,
309  RE_UniformType type,
310  int languages =
312 
313  // Static member functions for retrieving information about built-in
314  // uniforms.
315  static const char *getBuiltInName(RE_UniformBuiltIn built_in);
316  static RE_UniformType getBuiltInType(RE_UniformBuiltIn built_in);
317 
318  static void initBuiltIns();
319 
320  // Specify that a given uniform object should represent a given built-in
321  // uniform. After a built-in has been registered, calling getBuiltIn(int)
322  // returns the registered uniform object. By specifying a uniform object
323  // when calling unregisterBuilInt(), the built-in will only be unregistered
324  // if the currently registered uniform object matches the specified object.
325  static void registerBuiltIn(RE_Render *r,
326  RE_UniformBuiltIn built_in,
327  const RE_Uniform &uniform);
328 
329  // A convenience version for single-index variables. 'data' must match the
330  // uniform's data type.
331  static void registerBuiltIn(RE_Render *r,
332  RE_UniformBuiltIn built_in,
333  const void *data = nullptr);
334 
335  // Assign a new value to a previous registered uniform.
336  static bool assignBuiltIn(RE_Render *r,
337  RE_UniformBuiltIn built_in,
338  const void *data);
339 
340  // Assign a range of values to a previously registered uniform array.
341  // Element zero passed in 'data' always corresponds to element 'start' in
342  // the uniform.
343  static bool assignBuiltInArray(RE_Render *r,
344  RE_UniformBuiltIn built_in,
345  const void *data,
346  int start,
347  int num);
348 
349  // Remove the uniform. If registerBuiltIn was called, the unform is unbound
350  // only. If assignBuiltIn was called, the uniform is unbound and deleted.
351  static void unregisterBuiltIn(RE_Render *r,
352  RE_UniformBuiltIn built_in);
353 
354  void print() const;
355 
356  // For RE_Shader - caching of uniform index in the uniform.
357  void storeShaderUniformIndex(const RE_Shader *sh,
358  int index) const;
359  int getShaderUniformIndex(const RE_Shader *sh) const;
360 
361  void copyTo(RE_UniformStackEntry &entry) const;
362  void copyFrom(const RE_UniformStackEntry &entry);
363 
364 
365  static int getVectorSize(RE_UniformType type);
366  static bool isFloat(RE_UniformType type);
367  static bool isInt(RE_UniformType type);
368  static bool isSampler(RE_UniformType type);
369  static bool isImage(RE_UniformType type);
370 
371 private:
372  static const int theTypeSizes[RE_UNIFORM_TYPE__count];
373  UT_StringHolder myName;
374  RE_UniformType myType;
375  int myArraySize;
376  int myValueBytes;
377  int myValueCapacity;
378  int myVersion;
379  char *myValues;
380  bool myAutoGeneratedFlag;
381  RE_UniformBuiltIn myUniformType;
382 
383  // uniform index caching
384  mutable int myStoredIndex;
385  mutable int myStoredShaderSerial;
386  mutable exint myStoredShaderID;
387 };
388 
390 {
391 public:
393  : myByteSize(0), myArraySize(0), myVersion(0), myData(nullptr) {}
395  {
396  if(myData)
397  free(myData);
398  }
399 
400  void *myData;
404 };
405 
406 #endif
RE_UniformStackEntry()
Definition: RE_Uniform.h:392
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
int64 exint
Definition: SYS_Types.h:125
bool isAutoGenerated() const
Definition: RE_Uniform.h:299
void setAutoGenerated(bool gen=true)
Definition: RE_Uniform.h:297
RE_UniformType
Definition: RE_Uniform.h:145
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
int getByteCapacity() const
Definition: RE_Uniform.h:257
GA_API const UT_StringHolder gen
RE_UniformBuiltIn
Definition: RE_Uniform.h:28
GLuint const GLchar * name
Definition: glcorearb.h:786
int myArraySize
Definition: RE_Uniform.h:402
int getSize() const
Definition: RE_Uniform.h:253
GLsizeiptr size
Definition: glcorearb.h:664
int myVersion
Definition: RE_Uniform.h:401
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
GLboolean r
Definition: glcorearb.h:1222
~RE_UniformStackEntry()
Definition: RE_Uniform.h:394
int myByteSize
Definition: RE_Uniform.h:403
type
Definition: core.h:1059
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
Definition: core.h:2976
Definition: RE_Uniform.h:389
Definition: format.h:895
void * myData
Definition: RE_Uniform.h:400
int getVersion() const
Definition: RE_Uniform.h:295