HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RE_Shader.h
Go to the documentation of this file.
1 
2 /*
3  * PROPRIETARY INFORMATION. This software is proprietary to
4  * Side Effects Software Inc., and is not to be reproduced,
5  * transmitted, or disclosed in any way without written permission.
6  *
7  * NAME: Render Library (C++)
8  *
9  * COMMENTS:
10  * OpenGL GLSL/Cg Shader base definition. Abstracts the difference
11  * between the two.
12  *
13  */
14 #ifndef __RE_Shader__
15 #define __RE_Shader__
16 
17 #include "RE_API.h"
18 #include "RE_Texture.h"
19 #include "RE_TextureTypes.h"
20 #include "RE_Types.h"
21 #include "RE_Uniform.h"
22 
23 #include <UT/UT_Array.h>
24 #include <UT/UT_Color.h>
25 #include <UT/UT_IntrusivePtr.h>
26 #include <UT/UT_Matrix2.h>
27 #include <UT/UT_Matrix3.h>
28 #include <UT/UT_Matrix4.h>
29 #include <UT/UT_String.h>
30 #include <UT/UT_StringHolder.h>
31 #include <UT/UT_SymbolTable.h>
32 #include <UT/UT_ValArray.h>
33 #include <UT/UT_Vector2.h>
34 #include <UT/UT_Vector3.h>
35 #include <UT/UT_Vector4.h>
36 #include <UT/UT_VectorTypes.h>
37 #include <UT/UT_WorkBuffer.h>
38 #include <SYS/SYS_Math.h>
39 #include <SYS/SYS_Types.h>
40 #include <iosfwd>
41 
42 class RE_ElementArray;
43 class RE_Geometry;
44 class RE_Material;
45 class RE_OGLTexture;
46 class RE_Render;
47 class RE_ShaderStage;
48 class RE_UniformBlock;
49 class RE_UniformData;
50 class RE_VertexArray;
51 class RE_VertexMap;
52 class RE_VertexState;
53 class UT_StringArray;
54 
55 class re_LibFunc;
56 class re_VertexName;
57 
59 
61 {
62 public:
63  /// Program name is readable, shader_version may be 0 or a
64  /// valid GLSL version (110, 120, 130, 140, 150, 330, 400, 410, 420..)
65  enum { USE_GLSL_BASE_VERSION = -1,
66  USE_SHADER_GLSL_VERSION = 0 };
67 
68  RE_Shader(const char *program_name, int shader_version);
69  virtual ~RE_Shader();
70 
71  exint getUniqueID() const { return myUniqueID; }
72 
73  /// Returns the amount of main memory (NOT graphics memory!)
74  /// owned by this RE_Shader.
75  virtual int64 getMemoryUsage(bool inclusive) const;
76 
77  /// If true, register this shader so that RE_Shader::getShader() can find
78  /// this shader (default is true).
79  void setRegisterProgram(bool register_program);
80 
81  ///Call to allocate a specific shader type. If you want to allocate a shader
82  ///of a specific GLSL version, set the version to the same number as the
83  ///#version string in the shader (ie, 120 for 1.20, 330 for 3.30). Otherwise
84  ///the shader inherits the version from the first shader object attached.
85  static RE_Shader *create(const char *name,
86  int shader_version = 0,
88 
89  ///Create a shader and load all shader files listed in shader_files, up to
90  ///a nullptr filename. If the shader compiles and links, a non-nullptr shader will
91  ///be returned. 'compile_msg' will contain any error messages otherwise.
92  ///Shader stages must have extensions .vert, .geom and .frag.
94  const char *name,
95  const char **shader_files,
96  int shader_version = USE_SHADER_GLSL_VERSION,
97  UT_String *compile_msg = nullptr,
98  bool use_houdini_libs = true,
100  bool register_program = true,
101  const char *extra_defines = nullptr);
102 
103  /// A version with a single string containing whitespace-separated filenames
105  const char *name,
106  const char *shader_files,
107  int shader_version = USE_SHADER_GLSL_VERSION,
108  UT_String *compile_msg = nullptr,
109  bool use_houdini_libs = true,
111  bool register_program = true,
112  const char *extra_defines = nullptr);
113 
114  /// Readable name of the shader
115  const char *getName() const { return myProgramName; }
116 
117  /// Any define commands used to alter this shader
118  const char *getDefines() const { return myExtraDefines; }
119 
120  /// Raw GL id of the shader
121  int getProgram() const { return myProgramObject; }
122 
123  // Return the shader with the given program ID.
124  static RE_Shader *lookupProgram(int id);
125 
126  /// True if the shader has been successfully linked
127  bool isLinked() const { return myLinkedFlag; }
128 
129  /// Returns the version of the shader (110,120,130,140,150,330,400,410).
130  int getCodeVersion() const { return myCodeVersion; }
131 
132  /// Returns the minimum GLSL version supported (base requirement)
133  static int getBaseGLSLVersion();
134 
135  /// determine the version of the shader from the source (#version <num>)
136  /// return 100 if no version is specified.
137  static int determineCodeVersion(const char *shader_string);
138 
139  /// Allocate a new shader stage of the specified type, with an optional
140  /// readable name.
141  virtual RE_ShaderStage *newShader(RE_ShaderType type,
142  const char *name = 0) = 0;
143 
144  /// @{
145  /// loadShader() loads a shader from an ASCII file.
146  /// addShader() is used when the source is already available.
147  /// 'messages' returns the warnings & errors (if any) from shader
148  /// compilation.
149  /// Multiple shaders can be attached to the same shader type; it is expected
150  /// that one is the main shader, and others are functions.
151  RE_ShaderStage *loadShader(RE_Render *r,
152  RE_ShaderType stype,
153  const char *filename,
154  UT_String *messages = nullptr,
155  const char *shader_name = nullptr,
156  const char *defines = "",
157  int default_code_version=USE_GLSL_BASE_VERSION,
158  int geom_max_verts = -1);
159 
160  RE_ShaderStage *addShader(RE_Render *r,
161  RE_ShaderType stype,
162  const char *shader_source,
163  const char *shader_name,
164  int codeversion,
165  UT_String *messages = nullptr);
166  /// @}
167 
168  /// If true, this shader may use Houdini's builtin functions.
169  void useHoudiniLibraryFuncs();
170 
171  /// If true, this shader follows the default Houdini attribute map.
172  void useDefaultAttribMap(bool enable = true);
173 
174  /// If true, this shader defines its own attribute locations in shader code
175  /// Do not move any attributes.
176  void useExplicitAttribMap(bool enable = true);
177 
178  ///Individual Shader objects can be created separately and attached. returns
179  ///true if the shader was attached, and false if it was already attached.
180  virtual bool attachShader(RE_Render *r,
182  UT_String *messages = nullptr);
183 
184  // Detaching a shader object prevents it from being deleted when the shader
185  // is deleted. Returns true if the shader was detached, or false if the
186  // shader was not present in the program.
187  virtual bool detachShader(RE_Render *r,
189 
190  /// Returns an attached shader by the given name.
191  RE_ShaderStage *getShader(const char *shader_name,
193 
194  /// bind vertex shader input 'name' to vertex array index 'vertex_index'.
195  /// Must be called before linking, or a re-link must be done.
196  virtual bool setVertexInput(RE_Render *r,
197  const char *name,
198  int vertex_index);
199 
200  /// bind fragment shader output 'name' to color attachment 'buffer_index'.
201  /// Must be called before linking. Only needed for custom fragment output
202  /// (ie, not gl_FragData[] or gl_FragColor).
203  virtual bool setFragmentOutput(RE_Render *r,
204  const char *name,
205  int buffer_index);
206 
207  /// Links all the shaders together; called implicitly if needed by
208  /// RE_Render::setShader(). Note that linking the shader will clear
209  /// out any uniforms that have been set.
210  virtual bool linkShaders(RE_Render *r, UT_String *messages = nullptr);
211 
212  /// Bumped every time a link is performed (uniforms invalidated, etc).
213  int getLinkSerial() const { return myShaderSerial; }
214 
215  /// Ensures that the shader can run given the current GL state. This mostly
216  /// deals with texture bindings matching what is expected by the shader.
217  /// If this returns false, the shader will not run, and 'messages' can be
218  /// used to fetch the reason.
219  virtual bool validateShader(RE_Render *r, UT_String *messages = nullptr);
220 
221  /// Clears and deletes all the shader objects of a certain type (or all)
222  virtual void clearShaders(RE_Render *r,
224 
225 
226  /// Returns true if this shader program has a shader of 'type' attached.
227  /// type may be a bitmask of shader types, in which case it returns true if
228  /// any of the shader types exist.
229  bool hasShader(RE_ShaderType type) const;
230 
231  // GEOMETRY SHADERS ------------------------------------------------------
232 
233  /// @name Geometry Shaders
234  /// Geometry shaders must be initialized with a cap on how many vertices
235  /// they emit per primitive, as well as the primitives they operate on,
236  /// and the primitives they produce. A vertex and fragment shader MUST be
237  /// used with a geometry shader. A geometry shader will fail if the
238  /// primitives drawn do not match the geometry shader input.
239  /// Input primitives can be points, line variants (lines, line loop, line
240  /// strip) or triangle variants (tris, tristrips, trifans). Quads and polys
241  /// are not supported. The output must be points, linestrip or tristrip.
242  //@{
243 
244  /// Specify geometry shader parameters.
245  virtual bool setGeometryParms(RE_Render *r,
246  int max_vertices,
248  RE_PrimType output);
249 
250  /// @brief Fetch current geometry shader values.
251  /// Return the geometry shader parameters specified by setGeometryParms() or
252  /// the shader itself (via layout(in=triangles), etc).
253  void getGeometryParms(int &maxverts,
254  RE_PrimType &input_type,
255  RE_PrimType &output_type) const
256  {
257  maxverts = myGeoShaderMaxVertices;
258  input_type = myGeoShaderInputPrims;
259  output_type= myGeoShaderOutputPrims;
260  }
261  //@}
262 
263  // TRANSFORM FEEDBACK ----------------------------------------------------
264 
265  /// @name Transform Feedback
266  /// Using transform feedback, it is possible to capture vertex or geometry
267  /// shader outputs and write these values to buffers (RE_VertexArrays).
268  /// Method to add or remove shader outputs should be called before the
269  /// shader is linked, otherwise they will cause a re-link of the shader.
270  /// Note that relinking with clear out any uniform values, so these buffers
271  /// should be set up early.
272  //@{
273 
274  /// @brief Specify an RE_Geometry to collect data from Transform Feedback.
275  /// Specify a geometry object to hold all the arrays for transform feedback.
276  /// You retain ownership of the object unless 'give_ownership' is true.
277  /// If no object is attached when the shader is linked, one will be
278  /// created for you (with ownership maintained by this shader).
279  void addCaptureGeometry(RE_Geometry *object,
280  bool give_ownership = false);
281 
282  /// Return the capture geometry for transform feedback.
283  RE_Geometry *getCaptureGeometry(bool take_ownership = false);
284 
285  /// Specify a generic attribute to capture during transform feedback.
286  bool addFeedbackBuffer(const char *attrib_name);
287 
288  /// Remove a generic attribute from the capture geometry.
289  bool removeFeedbackBuffer(const char *attrib_name);
290 
291  /// Will generate a new owned capture geometry if one isn't present.
292  void setFeedbackBufferSize(int num_vertices);
293 
294  /// Remove all attributes from the capture gemetry.
295  void clearAllFeedbackBuffers();
296 
297  /// True if this shader has transform feedback varyings available.
298  bool hasTransformFeedback() const;
299 
300  /// @brief Fetch a vertex array written to by the shader.
301  /// These are only valid after the shader has been linked for
302  /// transform feedback (usually due to a draw call). Returns a vertex array
303  /// for the named feedback buffer.
304  RE_VertexArray *getFeedbackBuffer(const char *attrib_name) const;
305 
306 
307  /// @brief Check if a feedback buffer will be written by this shader
308  /// Returns true if the attribute is available to be captured. Will return
309  /// false if no buffer was setup to capture the attribute, or the shader
310  /// does not output that attribute.
311  /// This method must be called after the shader is linked.
312  bool isFeedbackBufferUsed(RE_BufferType glattrib,
313  int texlevel = 0) const;
314 
315  /// @brief Check if a feedback buffer will be written by this shader
316  /// Returns true if the attribute is available to be captured. Will return
317  /// false if no buffer was setup to capture the attribute, or the shader
318  /// does not output that attribute.
319  /// This method must be called after the shader is linked.
320  bool isFeedbackBufferUsed(const char *attrib) const;
321 
322  /// @private For RE_Render only.
323  virtual bool bindForTransformFeedback(RE_Render *r);
324 
325  /// @}
326 
327  // SHADING OPTIONS -------------------------------------------------------
328 
329  /// For multisampled framebuffers, this sets the fraction of samples that
330  /// should be shaded by a fragment shader, from 0.0 to 1.0. For example,
331  /// setting this to 0.5 would guarentee _at least_ 4 color samples for a 8x
332  /// multisample buffer. The default is 0.0 (1 color sample, N coverage)
333  /// This only has an effect on GL4 hardware. It is ignored unless
334  /// RE_EXT_SAMPLE_SHADING is supported.
335  /// @{
337  { myShadingRate = SYSclamp(rate,0.0,1.0); }
339  { return SYSmax(myShadingRate,0.0); }
340  bool isSampleShading() const { return myShadingRate >= 0.0; }
341  /// @}
342 
343  /// Disables the shading rate for this shader. The rate set by
344  /// RE_Render::setShaderSampleRate() is used instead.
345  void disableShadingRate() { myShadingRate = -1.0; }
346 
347  // UNIFORMS --------------------------------------------------------------
348 
349  /// @brief Set the value of a uniform.
350  /// Set uniform value(s) for a specific type. False will be returned if the
351  /// shader is not linked (errors?), the given name does not exist, or the
352  /// type does not match the GLSL uniform type.
353  /// @{
354  bool bindInt(RE_Render *r, const UT_StringHolder &name, int v);
355  bool bindFloat(RE_Render *r, const UT_StringHolder &name, float v);
356  bool bindDouble(RE_Render *r, const UT_StringHolder &name, double v);
357 
358  bool bindColor(RE_Render *r, const UT_StringHolder &name, const UT_Color &c);
359  bool bindColor(RE_Render *r, const UT_StringHolder &name, const UT_Color &c,
360  fpreal alpha);
361 
362  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector2F &v);
363  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector3F &v);
364  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector4F &v);
365 
366  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector2D &v);
367  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector3D &v);
368  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector4D &v);
369 
370  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector2i &v);
371  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector3i &v);
372  bool bindVector(RE_Render *r,const UT_StringHolder &name,const UT_Vector4i &v);
373 
374  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
375  const UT_Vector2FArray &vals);
376  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
377  const UT_Vector3FArray &vals);
378  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
379  const UT_Vector4FArray &vals);
380 
381  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
382  const UT_Vector2DArray &vals);
383  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
384  const UT_Vector3DArray &vals);
385  bool bindVectors(RE_Render *r, const UT_StringHolder &name,
386  const UT_Vector4DArray &vals);
387 
388  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix2F &m);
389  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix3F &m);
390  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix4F &m);
391 
392  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix2D &m);
393  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix3D &m);
394  bool bindMatrix(RE_Render *r,const UT_StringHolder &name,const UT_Matrix4D &m);
395  /// @}
396 
397  /// Bind a texture map using named textures in TIL_TextureMap. You can also
398  /// bind a texture with its raw OpenGL ID using bindVariableInt().
399  /// @{
400  /// Bind a new texture object using the mapname (filename, op:/coppath)
401  virtual bool bindTextureMap(RE_Render *r,
402  const UT_StringHolder &name,
403  const char *mapname,
404  const char *relative_to) = 0;
405  /// @}
406 
407  /// Return the texture type for the sampler named 'name'.
408  virtual RE_TextureDimension getTextureMapType(RE_Render *r,
409  const UT_StringHolder &name) = 0;
410 
411  /// Return the number of samplers this shader references
412  int getNumTextures() const { return myTextureUniforms.entries(); }
413 
414  /// Return the number of image samplers this shader references (GL4.2
415  /// shader load/store images, not regular texture samplers)
416  int getNumImages() const { return myImageUniforms.entries(); }
417 
418  /// @brief Return the name of a sampler uniform
419  /// Return the texture sampler name of the enumerated samplers at 'tex_index'
420  /// Must be within [0, getNumTextures()-1].
421  const char *getTextureSamplerName(int tex_index) const;
422 
423  /// Return the texture sampler type at 'tex_index' [0, getNumTextures()-1].
424  RE_TextureDimension getTextureSamplerType(int tex_index) const;
425 
426  // Return the uniform name of the sampler bounds to 'tex_unit'
427  UT_StringHolder findSamplerAtUnit(int tex_unit) const;
428 
429  /// @brief return the texture unit of sampler 'uniform_name'
430  /// Return the texture unit this sampler has been assigned to, or -1 if
431  /// 'uniform_name' does not exist, or is not a sampler. array_index is used
432  /// to identify indices of sampler arrays.
433  int getUniformTextureUnit(const UT_StringHolder &uniform_name,
434  int array_index = 0) const;
435 
436  /// Set a binding point for the given sampler
437  bool setUniformTextureUnit(RE_Render *r,
438  const UT_StringHolder &uniform_name,
439  int unit_index);
440 
441  /// @brief return the image unit of sampler 'uniform_name'
442  /// Return the image unit this image uniform has been assigned to, or -1 if
443  /// 'uniform_name' does not exist, or is not a image uniform. Images are
444  /// different than textures, used by RE_EXT_IMAGE_LOAD_STORE (GL4.2).
445  int getUniformImageUnit(const UT_StringHolder &uniform_name) const;
446 
447  /// Return the uniform type of the uniform named 'uniform_name', or
448  /// RE_UNIFORM_INVALID if it does not exist.
449  RE_UniformType getUniformType(const UT_StringHolder &uniform_name) const;
450 
451 
452  /// Returns the number of active uniforms in this shader.
453  int getNumUniforms() const { return myUniforms.entries(); }
454 
455  /// Returns the name of active uniform 'idx' [0, getNumUniforms()-1]
456  const char *getUniformName(int idx) const;
457 
458  /// Return the GL uniform location of uniform 'idx' [0, getNumUniforms()-1]
459  int getUniformLocation(int idx) const;
460 
461  /// Return the GL uniform type 'idx' [ 0, getNumUniforms()-1]
462  RE_UniformType getUniformType(int idx) const;
463 
464  /// Return the index of the uniform block a uniform is in, -1 for none.
465  int getBlockIndexForUniform(int idx) const;
466 
467 
468  /// @name Setting Uniforms
469  /// These methods set uniform values in a shader. 'name' is the name of the
470  /// uniform in the shader. 'val' is the value that uniform should take.
471  /// 'array_size' is used if the uniform is an array. 'saved_idx' is an
472  /// optimization to speed up subsequent accesses to the uniforms. Initially
473  /// it should be -1.
474  //@{
475 
476  /// Generic Integer scalar
477  virtual bool bindVariableInt(RE_Render *r,
478  const UT_StringHolder &name, const int *val,
479  int array_size=1, int *saved_idx=0)=0;
480  /// Generic Integer vector-2
481  virtual bool bindVariableInt2(RE_Render *r,
482  const UT_StringHolder &name, const int *val,
483  int array_size=1, int *saved_idx=0)=0;
484  /// Generic Integer vector-3
485  virtual bool bindVariableInt3(RE_Render *r,
486  const UT_StringHolder &name, const int *val,
487  int array_size=1, int *saved_idx=0)=0;
488  /// Generic Integer vector-4
489  virtual bool bindVariableInt4(RE_Render *r,
490  const UT_StringHolder &name, const int *val,
491  int array_size=1, int *saved_idx=0)=0;
492 
493  /// 64b Integer handle for bindless texturing
494  virtual bool bindUint64(RE_Render *r,
495  const UT_StringHolder &name, uint64 *val,
496  int array_size = 1, int *saved_idx=0) =0;
497 
498  virtual bool bindVariable1(RE_Render *r,
499  const UT_StringHolder &name, const fpreal32 *val,
500  int array_size=1, int *saved_idx=0)=0;
501  virtual bool bindVariable2(RE_Render *r,
502  const UT_StringHolder &name, const fpreal32 *val,
503  int array_size=1, int *saved_idx=0)=0;
504  virtual bool bindVariable3(RE_Render *r,
505  const UT_StringHolder &name, const fpreal32 *val,
506  int array_size=1, int *saved_idx=0)=0;
507  virtual bool bindVariable4(RE_Render *r,
508  const UT_StringHolder &name, const fpreal32 *val,
509  int array_size=1, int *saved_idx=0)=0;
510 
511  virtual bool bindVariable1(RE_Render *r,
512  const UT_StringHolder &name, const fpreal64 *val,
513  int array_size=1, int *saved_idx=0)=0;
514  virtual bool bindVariable2(RE_Render *r,
515  const UT_StringHolder &name, const fpreal64 *val,
516  int array_size=1, int *saved_idx=0)=0;
517  virtual bool bindVariable3(RE_Render *r,
518  const UT_StringHolder &name, const fpreal64 *val,
519  int array_size=1, int *saved_idx=0)=0;
520  virtual bool bindVariable4(RE_Render *r,
521  const UT_StringHolder &name, const fpreal64 *val,
522  int array_size=1, int *saved_idx=0)=0;
523 
524  virtual bool bindMatrix2(RE_Render *r,
525  const UT_StringHolder &name, const fpreal32 *val,
526  int array_size=1, int *saved_idx=0)=0;
527  virtual bool bindMatrix3(RE_Render *r,
528  const UT_StringHolder &name, const fpreal32 *val,
529  int array_size=1, int *saved_idx=0)=0;
530  virtual bool bindMatrix4(RE_Render *r,
531  const UT_StringHolder &name, const fpreal32 *val,
532  int array_size=1, int *saved_idx=0)=0;
533 
534  virtual bool bindMatrix2(RE_Render *r,
535  const UT_StringHolder &name, const fpreal64 *val,
536  int array_size=1, int *saved_idx=0)=0;
537  virtual bool bindMatrix3(RE_Render *r,
538  const UT_StringHolder &name, const fpreal64 *val,
539  int array_size=1, int *saved_idx=0)=0;
540  virtual bool bindMatrix4(RE_Render *r,
541  const UT_StringHolder &name, const fpreal64 *val,
542  int array_size=1, int *saved_idx=0)=0;
543 
544  /// Sampler buffer bound to a texture. The shader manages the texture
545  /// unit assignment, the binding of the texture to the texture unit, and
546  /// the assingment of the sampler buffer uniform.
547  virtual bool bindTexture(RE_Render *r,
548  const UT_StringHolder &name,
549  RE_Texture *tex,
550  int *saved_idx=0)=0;
551  //@}
552 
553  /// Bind a texture to an image slot for reading, writing, or both.
554  /// Requires RE_EXT_IMAGE_LOAD_STORE (or GL4.2).
555  virtual bool bindImage(RE_Render *r,
556  const UT_StringHolder &name,
557  RE_Texture *image,
558  RE_BufferAccess image_access) = 0;
559 
560  /// Bind a texture array layer, cubemap layer, or a 3D texture slice
561  /// to an image slot for reading, writing, or both.
562  /// Requires RE_EXT_IMAGE_LOAD_STORE (or GL4.2).
563  virtual bool bindImageLayer(RE_Render *r,
564  const UT_StringHolder &name,
565  RE_Texture *image,
566  RE_BufferAccess image_access,
567  int layer) = 0;
568 
569  /// assign a bindless texture to its handle uniform. 'texture' must have
570  /// a texture handle, and uniform_name must refer to a texture handle.
571  bool setTextureHandle(RE_Render *r,
572  const UT_StringHolder &uniform_name,
574  int *saved_idx = 0);
575 
576  /// Remove a bindless handle from the uniform, clearing it to 0 (no tex).
577  bool clearTextureHandle(RE_Render *r,
578  const UT_StringHolder &uniform_name,
579  int *saved_idx = 0);
580 
581  /// @brief Bind an RE_Uniform's values to the corresponding GL uniform
582  /// Bind an RE_Uniform to this shader. If 'uniform' is an array uniform
583  /// then 'index' specifies which array element to bind. 'index' must be
584  /// less than uniform->getSize(). Pass -1 for 'index' (the default) to
585  /// bind all elements of an array; passing -1 for non-arrays is safe and
586  /// is equivalent to passing 0.
587  virtual bool bindUniform(RE_Render *r,
588  const RE_Uniform *uniform, int index = -1);
589 
590  /// returns true if the named uniform exists in the shader.
591  bool hasUniform(const UT_StringHolder &uniform_name) const;
592 
593  /// @brief Queries the use of a builtin uniform
594  /// Returns true if this shader has the specified built-in uniform.
595  /// 'uniform' must be an RE_UniformBuiltIn. Note that certain
596  /// built-in uniforms may only be supported for certain languages.
597  bool hasBuiltInUniform(RE_UniformBuiltIn uniform) const;
598 
599  /// Returns a list of RE_UniformBuiltIn IDs this shader uses.
601  { return myBuiltInUniforms; }
602 
603  /// @brief Bind all builtin uniforms.
604  /// Bind all builtin uniforms this shader uses to their current values in
605  /// RE_Render
606  void bindBuiltIns(RE_Render *r,
607  bool force_update = false);
608 
609  /// Called to invalidate the cached uniform, usually by
610  /// RE_Uniform::unregisterBuiltIn().
611  void invalidateUniform(RE_UniformBuiltIn uniform);
612 
613  /// Prints all the active uniforms plus their values to stream os (or cerr)
614  virtual void printUniforms(RE_Render *r,
615  std::ostream *os = nullptr) const {}
616 
617  // UNIFORM BLOCKS -------------------------------------------------------
618 
619  // RE_EXT_UNIFORM_BUFFER must be supported, or these will always return 0
620  // NOTE: these methods are specifically for swapping blocks in and out for
621  // optimization purposes.
622  // You do not need to use these directly to bind values to uniform
623  // blocks - the bind...() methods will do that automatically.
624  // See RE_UniformBuffer.h for more information.
625 
626  /// Returns the OpenGL maximum number of supported blocks.
627  virtual int getMaxUniformBlocks(RE_Render *) { return 0; }
628 
629  /// Returns the OpenGL maximum size of a uniform block, in bytes.
630  virtual int getMaxUniformBlockSizeB(RE_Render *) { return 0; }
631 
632 
633  /// Returns the number of blocks and specific uniform blocks.
634  virtual int getNumUniformBlocks() const { return 0; }
635 
636  /// Return an attached uniform block by index
637  virtual RE_UniformBlockHandle getUniformBlock(int ) const { return nullptr; }
638 
639  /// Return an attached uniform block by name
640  virtual RE_UniformBlockHandle getUniformBlock(const char *name) const
641  { return nullptr; }
642 
643  /// Returns the block binding point of the named block.
644  virtual int getUniformBlockIndex(const char *name) const
645  { return -1; }
646 
647  /// @brief Attach an RE_UniformBlock to this shader
648  /// Attach a single uniform block to the shader. The shader owns the block
649  /// while attached, and will delete it if the shader is deleted, or may
650  /// delete it if linkShaders() is called and it is no longer in use.
651  /// If you want to cache a block, detach it when you're done with the shader.
652  /// If a block with the same name is already attached to this shader, it will
653  /// be deleted.
654  virtual bool attachUniformBlock(RE_UniformBlock *) { return false; }
655 
656  /// @brief Detach a named RE_UniformBlock from this shader
657  /// Detach a single uniform block by name or pointer. The shader will no
658  /// longer keep a reference to it, and will not delete it when relinking or
659  /// when the shader is deleted.
660  /// Note that a shader must have all blocks attached when executed. Detaching
661  /// a uniform block does not remove the GL binding to the block, it merely
662  /// removes this shader's ownership of the block (for performance reasons)
663  virtual RE_UniformBlockHandle detachUniformBlock(const char *) {return nullptr;}
664 
665  /// Detach a specific RE_UniformBlock from this shader.
666  virtual bool detachUniformBlock(RE_UniformBlock *) { return false; }
667 
668  /// Detaches all blocks referenced by this shader.
669  virtual bool detachAllUniformBlocks() { return false; }
670 
671  /// Uploads attached uniform blocks that are dirty (uniform modifications)
672  /// and ensures they are bound to the shader.
673  virtual bool bindAllUniformBlocks(RE_Render *) { return false; }
674 
675  /// @brief Initialize a uniform block based on this shader's block layout
676  /// Initializes a uniform block with the proper offsets and size for block
677  /// index 'index'. If index is -1, block must have the name of one of the
678  /// uniform blocks in the shader.
679  virtual bool initUniformBlock(RE_Render *r,
680  RE_UniformBlock *block,
681  int index = -1) const
682  { return false; }
683 
684  /// Copies the structure of the named uniform block, and possibly the data.
686  bool data_too) const
687  { return nullptr; }
688 
689  /// Update an offset/name/size information in 'b' with the uniforms for the
690  /// correspondingly-named uniform block in this shader.
691  virtual bool updateUniformBlock(const RE_UniformBlockHandle &b) const
692  { return false; }
693 
694  /// Override the currently bound uniform block without deleting the block
695  /// currently residing at that index. If 'block_index' is -1, the name of
696  /// the block is used to find the block index. Only one override can be
697  /// active at once. Passing nullptr for the block clears the override.
699  int block_index = -1)
700  { return -1; }
701  /// Remove an override block from the shader, by index.
702  virtual void removeOverrideBlock(int ) {}
703  /// Remove a specific override block from the shader.
705  /// Remove all override blocks from the shader.
706  virtual void removeOverrideBlocks()
707  { myLightsId=-1; myLightsSerial=-1; }
708  /// Return the currently bound override block for an index, if any is bound
709  virtual RE_UniformBlockHandle getOverrideBlock(int ) const { return nullptr; }
710 
711  // STORAGE BUFFER BLOCKS -----------------------------------------------
712 
713  /// Create a buffer for buffer block 'name'. If it has an open-ended array,
714  /// array_size specifies the size of that array, othwer it is ignored.
716  int array_size)
717  { return nullptr; }
718 
719  /// Return the block definition for storage block 'name'
721  { return nullptr; }
722 
723  /// Return the storage block bound to 'name' (bound by attachStorageBlock)
725  { return nullptr; }
726 
727  /// Return the raw buffer bound to 'name' (bound by attachStorageBlock)
729  { return nullptr; }
730 
731  /// Attach a shader storage block to the binding point corresponding to its
732  /// name. Shader storage blocks should be created with createStorageBlock().
733  virtual bool attachStorageBlock(const RE_UniformBlockHandle &block)
734  { return false; }
735 
736  /// Detach a shader storage block from the binding point corresponding to
737  /// its name.
738  virtual bool detachStorageBlock(const RE_UniformBlockHandle &block)
739  { return false; }
740 
741  /// Attach a GL buffer to the shader storage block binding point that shares
742  /// its name (getAttributeName()). This method is for simple storage blocks,
743  /// such as "buffer blockname { vec4 color[]; }".
744  virtual bool attachStorageBuffer(RE_VertexArray *raw_buffer)
745  { return false; }
746  /// Detach a GL buffer from the shader storage block binding point that
747  /// shares its name (raw_buffer->getAttributeName()).
748  virtual bool detachStorageBuffer(RE_VertexArray *raw_buffer)
749  { return false; }
750 
751  /// Unbind the block or buffer attached to binding point 'bind_name'.
752  virtual bool detachStorageBinding(const char *bind_name)
753  { return false; }
754 
755  // ATTRIBUTES ----------------------------------------------------------
756 
757  /// Return if the vertex shader has input attributes
758  bool hasShaderAttribs() const
759  { return myAttribNames.entries() > 0; }
760 
761  /// Return the number of vertex shader input attributes
762  int getNumShaderAttribs() const
763  { return myAttribNames.entries(); }
764 
765  bool hasTessellation() const
766  { return myTessEvalShaders.entries()>0; }
767 
768  /// Return the name of vertex shader input at index 'i'
769  const char *getShaderAttribName(int i) const
770  { return myAttribNames(i); }
771 
772  /// Return the ID of the attribute if it is a known type, or
773  /// RE_GENATTRIB_UNDEF if it is not.
774  RE_GenericAttribID getShaderAttribGenID(int i) const;
775 
776  /// Return the GL attribute location of vertex shader input at index 'i'
777  int getShaderAttribLocation(int i) const
778  { return myAttribLocations(i); }
779 
780  /// Return the type of vertex shader input at index 'i'
782  { return myAttribTypes(i); }
783 
784  /// Return the vector size of vertex shader input at index 'i'
785  int getShaderAttribSize(int i) const
786  { return myAttribSizes(i); }
787 
788  /// Return a string array of all vertex shader input names.
790  { return myAttribNames; }
791 
792  /// Return an int array of all vertex shader input locations.
794  { return myAttribLocations; }
795 
796  /// Return an int array of all vertex shader input sizes.
798  { return myAttribSizes; }
799 
800  /// Returns the name of a vertex shader input at GL location 'loc'
801  const char * getAttribNameForLocation(int loc) const;
802 
803  /// Return the default GL location of generic vertex attribute 't'
805  { return myAttrModeLocs(t); }
806 
807  /// Return the texture sampler unit of a texture buffer object for 't'
809  { return myAttrSamplerLocs(t); }
810 
811  /// Return the number of GL-builtin vertex shader inputs (gl_Vertex, gl_*)
813  { return myBuiltInAttribNames.entries(); }
814  /// Return the name of GL-builtin vertex shader input at index 'i'
815  const char * getBuiltinAttrib(int i) const
816  { return myBuiltInAttribNames(i); }
817 
818  /// Return the number of texture-buffer object attributes
820  { return myBufferAttribNames.entries(); }
821  /// Return the name of texture-buffer object attribute at index 'i'
822  const char * getBufferAttrib(int i) const
823  { return myBufferAttribNames(i); }
825  { return myBufferAttribGenIDs(i); }
826 
827  /// Return the number of texture buffer object samplers in this shader
828  int getNumBufferTextures() const;
829  /// Name of the texture buffer object sampler at index 'i'
830  const char * getBufferTextureName(int i) const;
831  /// Type of the texture buffer object sampler at index 'i' (float, int, uint)
832  RE_GPUType getBufferTextureType(int i) const;
833  /// True if the shader has a texture buffer object sampler named 'name'
834  bool hasBufferTexture(const char *name) const;
835 
836  /// @brief Return information about vertex shader input 'attrib_name'
837  /// Returns the location and size of the named vertex attribute, or false if
838  /// it does not exist in this shader.
839  /// This also includes the GL built-ins, though these will not set location
840  /// type, or size; only return true/false for their presence in the shader.
841  bool getAttribute(const char *attrib_name,
842  int &location,
843  RE_GPUType &type,
844  int &size) const;
845 
846  /// Simpler version of getAttribute() - just returns if the attribute exists
847  bool hasAttribute(const char *attrib_name) const
848  {
849  int loc,size;
850  RE_GPUType t;
851  return getAttribute(attrib_name,loc,t,size);
852  }
853 
854  /// @brief Return information about vertex shader input at 'index'
855  /// Similar to getAttribute(), but the name of the input does not need to be
856  /// known. GL builtins are not supported by this method. index must be
857  /// within [0, getNumAttribs()-1].
858  bool getAttributeIndex(int index,
859  UT_String &name,
860  int &location,
861  RE_GPUType &type,
862  int &size) const;
863 
864  void printAttributes(std::ostream *os = nullptr) const;
865 
866  /// @brief Zero out the constant attribute location given by 'array'
867  /// Bind a constant zero for this array. If data is non-nullptr,
868  /// this data is used, otherwise the current constant data for this array
869  /// is used (default 0's).
870  bool bindZeroConstant(RE_Render *r, RE_VertexArray *array);
871 
872  // TEXTURES ------------------------------------------------------------
873 
874  /// Loads texture maps specified by the RE_TextureMap bindTextureMap()
875  virtual void loadShaderTexMaps(RE_Render *) = 0;
876  virtual void loadBoundTextures(RE_Render *r) = 0;
877  virtual void unloadBoundTextures(RE_Render *r) = 0;
878 
879  /// Returns the number of texture samplers used by shader 'stage'. As
880  /// RE_ShaderType is a bitfield, multiple stages can be queried at once
881  /// and the sum will be returned. Requires RE_EXT_PROGRAM_INTERFACE_QUERY.
882  int getNumTextures(RE_ShaderType stage) const;
883 
884  /// Override texture compression for texture bound via bindTextureMap()
885  // @{
886  RE_TextureCompress getTextureFormat() const { return myTexFormat; }
888  { myTexFormat = format; }
889  // @}
890 
891  /// Limit the resolution of the textures to a max width and height.
892  //@{
893  void limitTextureSize(bool limit, int w, int h);
894  bool limitTextureSize() const { return myLimitTextureSize; }
895 
896  int getMaxTextureWidth() const { return myMaxTexW; }
897  int getMaxTextureHeight() const { return myMaxTexH; }
898  //@}
899 
900  /// Scale by a constant scale factor for textures bound via bindTextureMap()
901  //@{
902  void setTextureScale(float sc) { myTextureScale = sc; }
903  float getTextureScale() const { return myTextureScale; }
904  //@}
905 
906  /// Enable or disable mipmapping for textures bound via bindTextureMap()
907  //@{
908  bool mipMapTextures() const { return myMipMapTexture; }
909  void mipMapTextures(bool yes) { myMipMapTexture = yes; }
910  //@}
911 
912  /// Set anisotropic filtering for textures bound via bindTextureMap()
913  //@{
915  { myTextureAnisotropy = samples; }
917  { return myTextureAnisotropy; }
918  //@}
919 
920  /// Returns the shader source of some or all attached shaders
921  void getShaderSource(RE_Render *r,
922  UT_String &source,
924 
925  /// @brief Prepare this shader for rendering
926  /// Binds uniform buffer objects and all builtin uniforms. Optionally
927  /// re-binds vertex attribute locations in 'obj'.
928  bool prepForDrawing(RE_Render *r,
929  RE_Geometry *obj = nullptr,
930  RE_ElementArray *element = nullptr,
931  RE_VertexState *state = nullptr,
932  unsigned int vertex_stride = 0,
933  RE_OverrideList *atrbover=0,
934  int instance_group = 0);
935 
936  bool cleanupAfterDrawing(RE_Render *r,
937  RE_Geometry *obj=nullptr,
938  RE_VertexState *vstate = nullptr,
939  RE_OverrideList *atrbover=0);
940 
941  /// Cached RE_LightList information (uniform blocks)
942  //@{
943  bool matchesLights(int light_serial, int light_id) const;
944  void setLightID(int light_serial, int light_id, int mask);
945  int getLightMask() const { return myLightMask; }
946  //@}
947 
948  /// COMPUTE
949  virtual bool runCompute(RE_Render *r,
950  int num_wg_x,
951  int num_wg_y = 1,
952  int num_wg_z = 1);
953  virtual bool runCompute(RE_Render *r,
954  RE_VertexArray *wg_buffer, int offset);
955 
956  /// @brief Fetch a shader based on GL program id
957  /// Returns the RE_Shader object with the specified program object if it
958  /// exists; otherwise, returns nullptr.
959  static RE_Shader *getShader(int program_object);
960 
961  // Loads only the source from the Houdini OGL shader path. Returns true if
962  // the file was successfully loaded.
963  static bool loadFile(const char *filename,
964  const char *defines,
966  int &codeversion,
967  UT_String *messages,
968  int default_code_version = 0,
969  int max_verts = -1,
970  bool loadingInclude = false);
971 protected:
972  virtual void removeTextureRefs(RE_OGLTexture *) {}
973 
974  // Get the index of an attribute or uniform based on its name. The
975  // returned index can be used to look up corresponding elements in
976  // the myAttrib*s arrays or the myUniform*s arrays, respectively.
977  virtual int getAttributeIndex(const char *name) const;
978  int getUniformIndex(const UT_StringHolder &name) const;
979 
980  // Creates/destroys a mapping from the specified program id to this shader
981  // in the shader table.
982  static void registerProgram(RE_Shader *shader, int program_object);
983 
984  // Loads any built-in Houdini shaders that loadShader() noted if
985  // useHoudiniLibraryFuncs() is on.
986  bool loadHoudiniLibraryFuncs(RE_Render *r, UT_String *msg);
987 
988  const char **getTransformFeedbackAttribs(int &num_attribs);
989 
990 
991  static int loadProgramFile(RE_Render *r,
992  const char *file,
993  const char *basepath,
994  UT_String &prog_name,
995  UT_StringArray &files,
996  UT_StringArray &files_names,
997  UT_StringArray &inputs,
998  UT_StringArray &outputs,
999  UT_StringArray &defines,
1000  int &codeversion,
1001  fpreal &shading_rate,
1002  int &max_verts,
1003  bool &use_attrib_map,
1004  bool &explicit_attrib_map,
1005  int max_version,
1006  RE_ShaderLanguage &shader_lang,
1007  UT_String *msg);
1008 
1009  static RE_Texture * getDefaultTBO(RE_Render *r);
1010 
1012  {
1013  re_NeededLibFuncs(const char *file, const char *func, RE_ShaderType s)
1014  : myFile(file), myFunc(func), myStage(s), myLoaded(false) {}
1018  bool myLoaded;
1019  };
1020  static void scanSourceForFuncs(const char *line,
1021  RE_ShaderType shtype,
1023  re_LibFunc *library,
1024  int glmajor,
1025  int glminor);
1026  static bool getCodeBlock(const char *block_name,
1027  UT_StringHolder &block_source);
1028 
1029  void setGeomMaxVerts(int max_verts)
1030  { myGeoShaderMaxVertices = max_verts; }
1031 
1032 
1042  int myMaxTexW, myMaxTexH;
1046 
1053 
1055 
1059 
1069 
1078 
1079  int myBuiltInMap[ RE_UNIFORM_BUILT_IN__count ];
1082 
1085 
1088 
1092 
1096 
1102 
1103  UT_IntArray myDrawBoundTextures; // scope: single draw.
1105 
1106 public:
1107  // These are called by RE_Render. Use r->pushShader() or r->bindShader()
1108  // or r->popShader() instead
1109  // This should set the shader as current.
1110  virtual void applyShader(RE_Render *r, bool update_re = true) = 0;
1111  // This should do a cleanup and unset any current shader.
1112  virtual void removeShader(RE_Render *r, bool update_re = true) = 0;
1113  // This should cleanup after the shader, but leave it set as current.
1114  virtual void cleanup(RE_Render *r) = 0;
1115 
1116  // public only for RE_OGLRender.
1117  static void unregisterProgram(int program_object);
1118  static void removeAllTextureRefs(RE_OGLTexture *);
1119 };
1120 
1121 
1123 {
1124 public:
1126  const char *name = 0);
1127  virtual ~RE_ShaderStage();
1128 
1129  /// Returns the amount of main memory (NOT graphics memory!)
1130  /// owned by this RE_ShaderStage.
1131  virtual int64 getMemoryUsage(bool inclusive) const
1132  {
1133  int64 mem = inclusive ? sizeof(*this) : 0;
1134  mem += myName.getMemoryUsage(false);
1135  mem += myFilename.getMemoryUsage(false);
1136  return mem;
1137  }
1138 
1139  const char * getName() const { return myName; }
1140  RE_ShaderType getShaderType() const { return myType; }
1141 
1142  const UT_String &getFilename() const { return myFilename; }
1143  void setFilename(const char * fname)
1144  { myFilename.harden(fname); }
1145 
1146  // This maintains an internal cache of shader source code; once the shader
1147  // is loaded, the cached source is used.
1148  bool loadShader(RE_Render *r,
1149  const char *filename,
1150  UT_String *messages = nullptr,
1151  bool dump_source_on_error = true,
1152  const char *defines = nullptr,
1153  int default_code_version
1155  int max_verts = -1);
1156 
1157  virtual bool setSource(RE_Render *r,
1158  const char *source_code,
1159  int version,
1160  UT_String *messages = nullptr,
1161  bool dump_source_on_error = true) = 0;
1162  virtual bool getSource(RE_Render *r, UT_String &source);
1163 
1164  void setID(int id) { myID = id; }
1165  int getID() const { return myID; }
1166 
1167  // Returns the version of the shader (100,110,120,130,140,150,330,400,410).
1168  int getCodeVersion() const { return myCodeVersion; }
1169 protected:
1170  void setCodeVersion(int v) { myCodeVersion=v; }
1171 private:
1172 
1173  UT_String myName;
1174  UT_String myFilename;
1175  RE_ShaderType myType;
1176  int myID;
1177  int myCodeVersion;
1178 };
1179 
1180 class RE_UniformData // private to RE - no RE_API
1181 {
1182 public:
1185  arraysize(0), topsize(0), topstride(0),
1186  uniformblock(-1), dataoffset(0),
1187  location(-1), tex_unit(-1), image_unit(-1),
1188  value_cached(false)
1189  {}
1190 
1192  : name(data.name),
1193  type(data.type),
1194  arraysize(data.arraysize),
1195  topsize(data.topsize),
1196  topstride(data.topstride),
1197  uniformblock(data.uniformblock),
1198  dataoffset(data.dataoffset),
1199  location(data.location),
1200  tex_unit(data.tex_unit),
1201  image_unit(data.image_unit),
1202  value_cached(false)
1203  {}
1204 
1205  bool typeMatch(const RE_UniformData *data) const
1206  {
1207  return (type == data->type &&
1208  arraysize == data->arraysize &&
1209  dataoffset == data->dataoffset);
1210  }
1211 
1212  /// Returns the amount of main memory (NOT graphics memory!)
1213  /// owned by this RE_UniformData.
1214  int64 getMemoryUsage(bool inclusive) const
1215  {
1216  int64 mem = inclusive ? sizeof(*this) : 0;
1217  mem += name.getMemoryUsage(false);
1218  return mem;
1219  }
1220 
1221  enum { cached_data_size = sizeof(UT_Matrix4D) };
1222 
1225  int arraysize; // array size of member element, ie, int[4]
1226  int topsize; // array size of buffer variable
1227  int topstride; // array stride of buffer variable
1231  int tex_unit; // for normal textures
1232  int image_unit; // for image-load-store images
1235 };
1236 
1237 /// --- Inlines
1238 
1239 inline bool
1241 {
1242  return bindVariableInt(r, name, &v);
1243 }
1244 
1245 inline bool
1247 {
1248  return bindVariable1(r, name, &v);
1249 }
1250 
1251 inline bool
1253 {
1254  return bindVariable1(r, name, &v);
1255 }
1256 
1257 inline bool
1259 {
1260  return bindVariable2(r, name, v.data());
1261 }
1262 
1263 inline bool
1265 {
1266  fpreal32 col[3];
1267 
1268  c.getRGB(col, col+1, col+2);
1269  return bindVariable3(r, name, col);
1270 }
1271 
1272 inline bool
1274  fpreal alpha)
1275 {
1276  fpreal32 col[4];
1277 
1278  c.getRGB(col, col+1, col+2);
1279  col[3] = alpha;
1280  return bindVariable4(r, name, col);
1281 }
1282 
1283 
1284 inline bool
1286 {
1287  return bindVariable3(r, name, v.data());
1288 }
1289 
1290 inline bool
1292 {
1293  return bindVariable4(r, name, v.data());
1294 }
1295 
1296 inline bool
1298 {
1299  return bindVariable2(r, name, v.data());
1300 }
1301 
1302 inline bool
1304 {
1305  return bindVariable3(r, name, v.data());
1306 }
1307 
1308 inline bool
1310 {
1311  return bindVariable4(r, name, v.data());
1312 }
1313 
1314 
1315 inline bool
1317 {
1318  return bindVariableInt2(r, name, v.data());
1319 }
1320 
1321 inline bool
1323 {
1324  return bindVariableInt3(r, name, v.data());
1325 }
1326 
1327 inline bool
1329 {
1330  return bindVariableInt4(r, name, v.data());
1331 }
1332 
1333 inline bool
1335  const UT_StringHolder &name,
1336  const UT_Vector2FArray &vals)
1337 {
1338  return bindVariable2(r, name, vals(0).data(), vals.entries());
1339 }
1340 
1341 
1342 inline bool
1344  const UT_Vector4FArray &vals)
1345 {
1346  return bindVariable4(r, name, vals(0).data(), vals.entries());
1347 }
1348 
1349 inline bool
1351  const UT_Vector2DArray &vals)
1352 {
1353  return bindVariable2(r, name, vals(0).data(), vals.entries());
1354 }
1355 
1356 inline bool
1358  const UT_Vector4DArray &vals)
1359 {
1360  return bindVariable4(r, name, vals(0).data(), vals.entries());
1361 }
1362 
1363 inline bool
1365 {
1366  return bindMatrix2(r, name, m.data());
1367 }
1368 
1369 inline bool
1371 {
1372  return bindMatrix3(r, name, m.data());
1373 }
1374 
1375 inline bool
1377 {
1378  return bindMatrix4(r, name, m.data());
1379 }
1380 
1381 inline bool
1383 {
1384  return bindMatrix2(r, name, m.data());
1385 }
1386 
1387 inline bool
1389 {
1390  return bindMatrix3(r, name, m.data());
1391 }
1392 
1393 inline bool
1395 {
1396  return bindMatrix4(r, name, m.data());
1397 }
1398 
1399 inline RE_GenericAttribID
1401 {
1402  return myAttribGenIDs(i);
1403 }
1404 
1405 #endif
const char * getBuiltinAttrib(int i) const
Return the name of GL-builtin vertex shader input at index 'i'.
Definition: RE_Shader.h:815
int getCodeVersion() const
Definition: RE_Shader.h:1168
const UT_String & getFilename() const
Definition: RE_Shader.h:1142
#define SYSmax(a, b)
Definition: SYS_Math.h:1513
virtual RE_UniformBlockHandle copyUniformBlock(const char *name, bool data_too) const
Copies the structure of the named uniform block, and possibly the data.
Definition: RE_Shader.h:685
virtual bool updateUniformBlock(const RE_UniformBlockHandle &b) const
Definition: RE_Shader.h:691
RE_UniformData(const RE_UniformData &data)
Definition: RE_Shader.h:1191
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLboolean enable
Definition: glew.h:2750
UT_Matrix4T< fpreal64 > UT_Matrix4D
bool hasShaderAttribs() const
Return if the vertex shader has input attributes.
Definition: RE_Shader.h:758
RE_GPUType getShaderAttribType(int i) const
Return the type of vertex shader input at index 'i'.
Definition: RE_Shader.h:781
int myProgramObject
Definition: RE_Shader.h:1035
GLint location
Definition: glcorearb.h:805
int getProgram() const
Raw GL id of the shader.
Definition: RE_Shader.h:121
GT_API const UT_StringHolder filename
UT_IntArray myAttribSizes
Definition: RE_Shader.h:1067
UT_String myProgramName
Definition: RE_Shader.h:1033
char cached_data[cached_data_size]
Definition: RE_Shader.h:1234
UT_ValArray< RE_ShaderStage * > myTessEvalShaders
Definition: RE_Shader.h:1049
void setID(int id)
Definition: RE_Shader.h:1164
virtual int getMaxUniformBlockSizeB(RE_Render *)
Returns the OpenGL maximum size of a uniform block, in bytes.
Definition: RE_Shader.h:630
GLenum GLuint GLint GLint layer
Definition: glcorearb.h:1299
virtual int64 getMemoryUsage(bool inclusive) const
Definition: RE_Shader.h:1131
virtual RE_UniformBlockHandle createStorageBlock(const char *name, int array_size)
Definition: RE_Shader.h:715
#define RE_API
Definition: RE_API.h:10
bool isSampleShading() const
Definition: RE_Shader.h:340
UT_String myExtraDefines
Definition: RE_Shader.h:1034
UT_StringList myBufferAttribNames
Definition: RE_Shader.h:1062
void getRGB(float *r, float *g, float *b) const
Definition: UT_Color.h:101
virtual void printUniforms(RE_Render *r, std::ostream *os=nullptr) const
Prints all the active uniforms plus their values to stream os (or cerr)
Definition: RE_Shader.h:614
UT_Array< RE_GenericAttribID > myBufferAttribGenIDs
Definition: RE_Shader.h:1063
void setFilename(const char *fname)
Definition: RE_Shader.h:1143
UT_IntArray myImageUniforms
Definition: RE_Shader.h:1095
UT_IntrusivePtr< RE_UniformBlock > RE_UniformBlockHandle
Definition: RE_Shader.h:56
int myLightMask
Definition: RE_Shader.h:1100
const GLfloat * c
Definition: glew.h:16631
GLenum GLenum GLenum input
Definition: glew.h:14162
virtual int getUniformBlockIndex(const char *name) const
Returns the block binding point of the named block.
Definition: RE_Shader.h:644
const UT_IntArray & getShaderAttribSizes() const
Return an int array of all vertex shader input sizes.
Definition: RE_Shader.h:797
RE_TextureCompress myTexFormat
Definition: RE_Shader.h:1040
int getSource() override
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
int64 exint
Definition: SYS_Types.h:125
int getMaxTextureWidth() const
Limit the resolution of the textures to a max width and height.
Definition: RE_Shader.h:896
GLenum GLsizei GLenum GLenum const void * image
Definition: glew.h:4973
bool hasTessellation() const
Definition: RE_Shader.h:765
virtual bool detachStorageBinding(const char *bind_name)
Unbind the block or buffer attached to binding point 'bind_name'.
Definition: RE_Shader.h:752
virtual void removeOverrideBlock(RE_UniformBlock *b)
Remove a specific override block from the shader.
Definition: RE_Shader.h:704
virtual RE_UniformBlockHandle getStorageBlock(const char *name)
Return the block definition for storage block 'name'.
Definition: RE_Shader.h:720
fpreal myShadingRate
Definition: RE_Shader.h:1093
void setCodeVersion(int v)
Definition: RE_Shader.h:1170
int myLightsSerial
Definition: RE_Shader.h:1098
bool bindColor(RE_Render *r, const UT_StringHolder &name, const UT_Color &c)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1264
UT_StringList myAttribNames
Definition: RE_Shader.h:1061
GLuint const GLchar * name
Definition: glcorearb.h:786
RE_UniformType
Definition: RE_Uniform.h:145
bool bindMatrix(RE_Render *r, const UT_StringHolder &name, const UT_Matrix2F &m)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1364
virtual RE_UniformBlockHandle getStorageBlockBinding(const char *name)
Return the storage block bound to 'name' (bound by attachStorageBlock)
Definition: RE_Shader.h:724
RE_TextureDimension
GLenum src
Definition: glcorearb.h:1793
unsigned long long uint64
Definition: SYS_Types.h:117
bool typeMatch(const RE_UniformData *data) const
Definition: RE_Shader.h:1205
virtual RE_UniformBlockHandle getOverrideBlock(int) const
Return the currently bound override block for an index, if any is bound.
Definition: RE_Shader.h:709
const char * getName() const
Readable name of the shader.
Definition: RE_Shader.h:115
UT_ValArray< re_VertexName * > myTransformFeedbackVertices
Definition: RE_Shader.h:1091
float fpreal32
Definition: SYS_Types.h:200
GLdouble GLdouble t
Definition: glew.h:1403
void disableShadingRate()
Definition: RE_Shader.h:345
const T * data() const
Return the raw matrix data.
Definition: UT_Matrix3.h:1155
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector3.h:283
bool bindInt(RE_Render *r, const UT_StringHolder &name, int v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1240
void setAnisotropySamples(int samples)
Set anisotropic filtering for textures bound via bindTextureMap()
Definition: RE_Shader.h:914
int getMaxTextureHeight() const
Limit the resolution of the textures to a max width and height.
Definition: RE_Shader.h:897
UT_ValArray< RE_UniformData * > myUniforms
Definition: RE_Shader.h:1070
int getCodeVersion() const
Returns the version of the shader (110,120,130,140,150,330,400,410).
Definition: RE_Shader.h:130
RE_GenericAttribID getShaderAttribGenID(int i) const
Definition: RE_Shader.h:1400
GLsizei samples
Definition: glcorearb.h:1298
UT_Array< RE_GenericAttribID > myAttribGenIDs
Definition: RE_Shader.h:1065
UT_Array< re_NeededLibFuncs > * myNeededLibraryFuncs
Definition: RE_Shader.h:1086
virtual bool initUniformBlock(RE_Render *r, RE_UniformBlock *block, int index=-1) const
Initialize a uniform block based on this shader's block layout Initializes a uniform block with the p...
Definition: RE_Shader.h:679
bool hasAttribute(const char *attrib_name) const
Simpler version of getAttribute() - just returns if the attribute exists.
Definition: RE_Shader.h:847
re_NeededLibFuncs(const char *file, const char *func, RE_ShaderType s)
Definition: RE_Shader.h:1013
GLsizeiptr size
Definition: glcorearb.h:664
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
RE_VertexMap * myVertexMap
Definition: RE_Shader.h:1083
int getNumImages() const
Definition: RE_Shader.h:416
double fpreal64
Definition: SYS_Types.h:201
RE_ShaderType
Definition: RE_Types.h:228
virtual RE_UniformBlockHandle getUniformBlock(int) const
Return an attached uniform block by index.
Definition: RE_Shader.h:637
int myCodeVersion
Definition: RE_Shader.h:1087
RE_GenericAttribID
Definition: RE_Types.h:329
UT_StringList myBuiltInAttribNames
Definition: RE_Shader.h:1060
GLenum array
Definition: glew.h:9108
RE_GPUType
Definition: RE_Types.h:44
RE_Geometry * myTransformFeedbackGeometry
Definition: RE_Shader.h:1089
virtual int getNumUniformBlocks() const
Returns the number of blocks and specific uniform blocks.
Definition: RE_Shader.h:634
RE_BufferType
Definition: RE_Types.h:265
int getNumTextures() const
Return the number of samplers this shader references.
Definition: RE_Shader.h:412
UT_IntArray myAttrModeLocs
Definition: RE_Shader.h:1076
UT_IntArray myNumTexturesPerStage
Definition: RE_Shader.h:1054
UT_IntArray myDrawBoundTextures
Definition: RE_Shader.h:1103
GLint limit
Definition: glew.h:13230
virtual bool detachAllUniformBlocks()
Detaches all blocks referenced by this shader.
Definition: RE_Shader.h:669
int getShaderAttribSize(int i) const
Return the vector size of vertex shader input at index 'i'.
Definition: RE_Shader.h:785
virtual RE_UniformBlockHandle detachUniformBlock(const char *)
Detach a named RE_UniformBlock from this shader Detach a single uniform block by name or pointer...
Definition: RE_Shader.h:663
GLint GLuint mask
Definition: glcorearb.h:124
virtual bool detachStorageBuffer(RE_VertexArray *raw_buffer)
Definition: RE_Shader.h:748
bool mipMapTextures() const
Enable or disable mipmapping for textures bound via bindTextureMap()
Definition: RE_Shader.h:908
bool myLinkedFlag
Definition: RE_Shader.h:1036
UT_ValArray< RE_ShaderStage * > myGeometryShaders
Definition: RE_Shader.h:1050
const GLdouble * v
Definition: glcorearb.h:837
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
bool bindDouble(RE_Render *r, const UT_StringHolder &name, double v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1252
UT_ValArray< const RE_Uniform * > myBuiltInLastUniform
Definition: RE_Shader.h:1073
UT_IntArray myAttribLocations
Definition: RE_Shader.h:1064
int64 getMemoryUsage(bool inclusive) const
Definition: RE_Shader.h:1214
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:1040
int getAttributeModeLoc(RE_GenericAttribID t) const
Return the default GL location of generic vertex attribute 't'.
Definition: RE_Shader.h:804
UT_ValArray< RE_ShaderStage * > myTessControlShaders
Definition: RE_Shader.h:1048
bool bindVectors(RE_Render *r, const UT_StringHolder &name, const UT_Vector2FArray &vals)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1334
UT_SymbolMap< int > myUniformBlockTable
Definition: RE_Shader.h:1075
GLhandleARB obj
Definition: glew.h:6266
const char * getShaderAttribName(int i) const
Return the name of vertex shader input at index 'i'.
Definition: RE_Shader.h:769
int getNumUniforms() const
Returns the number of active uniforms in this shader.
Definition: RE_Shader.h:453
bool bindFloat(RE_Render *r, const UT_StringHolder &name, float v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1246
bool isLinked() const
True if the shader has been successfully linked.
Definition: RE_Shader.h:127
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector2.h:220
long long int64
Definition: SYS_Types.h:116
UT_IntArray myAttrSamplerLocs
Definition: RE_Shader.h:1077
virtual int overrideUniformBlock(RE_UniformBlock *block, int block_index=-1)
Definition: RE_Shader.h:698
GLuint id
Definition: glcorearb.h:655
int myTextureAnisotropy
Definition: RE_Shader.h:1045
RE_UniformBuiltIn
Definition: RE_Uniform.h:28
virtual bool detachUniformBlock(RE_UniformBlock *)
Detach a specific RE_UniformBlock from this shader.
Definition: RE_Shader.h:666
bool myMipMapTexture
Definition: RE_Shader.h:1044
virtual bool attachUniformBlock(RE_UniformBlock *)
Attach an RE_UniformBlock to this shader Attach a single uniform block to the shader. The shader owns the block while attached, and will delete it if the shader is deleted, or may delete it if linkShaders() is called and it is no longer in use. If you want to cache a block, detach it when you're done with the shader. If a block with the same name is already attached to this shader, it will be deleted.
Definition: RE_Shader.h:654
int64 myRenderSerial
Definition: RE_Shader.h:1081
int getAnisotropySamples() const
Set anisotropic filtering for textures bound via bindTextureMap()
Definition: RE_Shader.h:916
virtual bool attachStorageBlock(const RE_UniformBlockHandle &block)
Definition: RE_Shader.h:733
const UT_IntArray & getBuiltInUniformList() const
Returns a list of RE_UniformBuiltIn IDs this shader uses.
Definition: RE_Shader.h:600
RE_ShaderType getShaderType() const
Definition: RE_Shader.h:1140
int myMaxTexW
Definition: RE_Shader.h:1042
UT_ValArray< RE_ShaderStage * > myVertexShaders
Definition: RE_Shader.h:1047
int getNumBufferAttribs() const
Return the number of texture-buffer object attributes.
Definition: RE_Shader.h:819
GT_API const UT_StringHolder version
void setTextureScale(float sc)
Scale by a constant scale factor for textures bound via bindTextureMap()
Definition: RE_Shader.h:902
int getLightMask() const
Cached RE_LightList information (uniform blocks)
Definition: RE_Shader.h:945
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:611
void setTextureFormat(RE_TextureCompress format)
Override texture compression for texture bound via bindTextureMap()
Definition: RE_Shader.h:887
GLboolean * data
Definition: glcorearb.h:131
fpreal getShadingRate() const
Definition: RE_Shader.h:338
virtual RE_VertexArray * getStorageBufferBinding(const char *name)
Return the raw buffer bound to 'name' (bound by attachStorageBlock)
Definition: RE_Shader.h:728
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
RE_TextureCompress getTextureFormat() const
Override texture compression for texture bound via bindTextureMap()
Definition: RE_Shader.h:886
void setGeomMaxVerts(int max_verts)
Definition: RE_Shader.h:1029
int getID() const
Definition: RE_Shader.h:1165
GLuint GLfloat * val
Definition: glcorearb.h:1608
UT_Array< RE_GPUType > myAttribTypes
Definition: RE_Shader.h:1066
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
const UT_StringList & getShaderAttribNames() const
Return a string array of all vertex shader input names.
Definition: RE_Shader.h:789
GLuint shader
Definition: glcorearb.h:785
GLenum func
Definition: glcorearb.h:783
RE_BufferAccess
Definition: RE_Types.h:295
void setShadingRate(fpreal rate)
Definition: RE_Shader.h:336
const T * data() const
Return the raw matrix data.
Definition: UT_Matrix4.h:1125
bool myRegisterProgram
Definition: RE_Shader.h:1039
UT_IntArray myBufferTextures
Definition: RE_Shader.h:1084
virtual void removeOverrideBlock(int)
Remove an override block from the shader, by index.
Definition: RE_Shader.h:702
int getAttributeSamplerLoc(RE_GenericAttribID t) const
Return the texture sampler unit of a texture buffer object for 't'.
Definition: RE_Shader.h:808
float myTextureScale
Definition: RE_Shader.h:1043
bool myLimitTextureSize
Definition: RE_Shader.h:1041
virtual int getMaxUniformBlocks(RE_Render *)
Returns the OpenGL maximum number of supported blocks.
Definition: RE_Shader.h:627
virtual RE_UniformBlockHandle getUniformBlock(const char *name) const
Return an attached uniform block by name.
Definition: RE_Shader.h:640
fpreal64 fpreal
Definition: SYS_Types.h:277
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:227
const char * getBufferAttrib(int i) const
Return the name of texture-buffer object attribute at index 'i'.
Definition: RE_Shader.h:822
GLuint index
Definition: glcorearb.h:786
virtual void removeOverrideBlocks()
Remove all override blocks from the shader.
Definition: RE_Shader.h:706
UT_StringHolder name
Definition: RE_Shader.h:1223
UT_ValArray< RE_ShaderStage * > myComputeShaders
Definition: RE_Shader.h:1052
const char * getDefines() const
Any define commands used to alter this shader.
Definition: RE_Shader.h:118
UT_SymbolMap< int > myUniformTable
Definition: RE_Shader.h:1074
int myShaderSerial
Definition: RE_Shader.h:1097
bool myTransformFeedbackGeometryOwned
Definition: RE_Shader.h:1090
const GLdouble * m
Definition: glew.h:9166
RE_UniformType type
Definition: RE_Shader.h:1224
UT_IntArray myBuiltInVersion
Definition: RE_Shader.h:1072
const UT_IntArray & getShaderAttribLocations() const
Return an int array of all vertex shader input locations.
Definition: RE_Shader.h:793
void mipMapTextures(bool yes)
Enable or disable mipmapping for textures bound via bindTextureMap()
Definition: RE_Shader.h:909
float getTextureScale() const
Scale by a constant scale factor for textures bound via bindTextureMap()
Definition: RE_Shader.h:903
MX_RENDER_API ShaderPtr createShader(const string &shaderName, GenContext &context, ElementPtr elem)
Create a shader for a given element.
bool limitTextureSize() const
Limit the resolution of the textures to a max width and height.
Definition: RE_Shader.h:894
GLuint texture
Definition: glcorearb.h:415
virtual bool bindAllUniformBlocks(RE_Render *)
Definition: RE_Shader.h:673
int64 myBuiltInUniformSerial
Definition: RE_Shader.h:1080
RE_PrimType myGeoShaderOutputPrims
Definition: RE_Shader.h:1058
bool myUseExplicitAttribMap
Definition: RE_Shader.h:1038
UT_StringList myFeedbackNames
Definition: RE_Shader.h:1068
bool bindVector(RE_Render *r, const UT_StringHolder &name, const UT_Vector2F &v)
Set the value of a uniform. Set uniform value(s) for a specific type. False will be returned if the s...
Definition: RE_Shader.h:1258
const char * getName() const
Definition: RE_Shader.h:1139
GLintptr offset
Definition: glcorearb.h:665
void getGeometryParms(int &maxverts, RE_PrimType &input_type, RE_PrimType &output_type) const
Fetch current geometry shader values. Return the geometry shader parameters specified by setGeometryP...
Definition: RE_Shader.h:253
GLsizei GLenum GLenum * types
Definition: glcorearb.h:2542
UT_ValArray< RE_ShaderStage * > myFragmentShaders
Definition: RE_Shader.h:1051
RE_PrimType myGeoShaderInputPrims
Definition: RE_Shader.h:1057
virtual bool detachStorageBlock(const RE_UniformBlockHandle &block)
Definition: RE_Shader.h:738
int setSource(int source) override
const T * data() const
Return the raw matrix data.
Definition: UT_Matrix2.h:423
exint myUniqueID
Definition: RE_Shader.h:1101
int getNumShaderAttribs() const
Return the number of vertex shader input attributes.
Definition: RE_Shader.h:762
RE_TextureCompress
type
Definition: core.h:1059
GLboolean r
Definition: glcorearb.h:1222
bool myUseDefaultAttribMap
Definition: RE_Shader.h:1037
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
int getLinkSerial() const
Bumped every time a link is performed (uniforms invalidated, etc).
Definition: RE_Shader.h:213
RE_ShaderLanguage
Definition: RE_Types.h:242
virtual bool attachStorageBuffer(RE_VertexArray *raw_buffer)
Definition: RE_Shader.h:744
int getShaderAttribLocation(int i) const
Return the GL attribute location of vertex shader input at index 'i'.
Definition: RE_Shader.h:777
RE_PrimType
Definition: RE_Types.h:193
GLdouble s
Definition: glew.h:1395
int getNumBuiltinAttribs() const
Return the number of GL-builtin vertex shader inputs (gl_Vertex, gl_*)
Definition: RE_Shader.h:812
exint getUniqueID() const
Definition: RE_Shader.h:71
virtual void removeTextureRefs(RE_OGLTexture *)
Definition: RE_Shader.h:972
Definition: format.h:895
UT_IntArray myTextureUniforms
Definition: RE_Shader.h:1094
UT_WorkBuffer myWorkBuffer
Definition: RE_Shader.h:1104
int myGeoShaderMaxVertices
Definition: RE_Shader.h:1056
UT_IntArray myBuiltInUniforms
Definition: RE_Shader.h:1071
RE_GenericAttribID getBufferAttribID(int i) const
Definition: RE_Shader.h:824
int myLightsId
Definition: RE_Shader.h:1099