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