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