FastUIDraw
gl_program.hpp
Go to the documentation of this file.
1 /*!
2  * \file gl_program.hpp
3  * \brief file gl_program.hpp
4  *
5  * Adapted from: WRATHGLProgram.hpp of WRATH:
6  *
7  * Copyright 2013 by Nomovok Ltd.
8  * Contact: info@nomovok.com
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@nomovok.com>
16  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
17  *
18  */
19 
20 
21 #ifndef FASTUIDRAW_GL_PROGRAM_HPP
22 #define FASTUIDRAW_GL_PROGRAM_HPP
23 
24 #include <fastuidraw/util/util.hpp>
25 #include <fastuidraw/util/vecN.hpp>
31 
32 namespace fastuidraw {
33 namespace gl {
34 
35 /*!\addtogroup GLUtility
36  * @{
37  */
38 
39 
40 /*!
41  * \brief
42  * Simple Shader utility class providing a simple interface to build
43  * GL shader objects using a glsl::ShaderSouce as its source code.
44  *
45  * The actual GL object creation is defferred to later, in
46  * doing so, one can create Shader objects from outside the main GL
47  * thread. Each of the following commands
48  * - compile_success()
49  * - compile_log()
50  * - name()
51  *
52  * triggers the GL commands to compile the shader if the shader has
53  * not been yet attempeted to be compiled. Hence one may only call
54  * these from outside the rendering thread if shader_ready() returns
55  * true. Moreover, a Shader may only be deleted from the GL rendering
56  * thread.
57  */
58 class Shader:
59  public reference_counted<Shader>::concurrent
60 {
61 public:
62  /*!
63  * Ctor. Construct a Shader.
64  * \param src GLSL source code of the shader
65  * \param pshader_type type of shader, i.e. GL_VERTEX_SHADER
66  * for a vertex shader, etc.
67  */
68  Shader(const glsl::ShaderSource &src, GLenum pshader_type);
69 
70  ~Shader();
71 
72  /*!
73  * The actual GL shader is NOT built at constructor,
74  * rather it is built if any of
75  * - compile_success()
76  * - compile_log()
77  * - name()
78  *
79  * are called. This way, one can construct Shader
80  * objects from outside the GL thread. The functions
81  * return true if and only if the shader has been built.
82  */
83  bool
84  shader_ready(void);
85 
86  /*!
87  * Returns the GLSL source string fed to GL
88  * to create the GLSL shader.
89  */
90  c_string
91  source_code(void);
92 
93  /*!
94  * Returns the GLSL compile log of
95  * the GLSL source code.
96  * If the shader source has not yet
97  * been sent to GL for compiling, will
98  * trigger those commands. Hence, should
99  * only be called from the GL rendering
100  * thread or if shader_ready() returns true.
101  */
102  c_string
103  compile_log(void);
104 
105  /*!
106  * Returns true if and only if GL
107  * successfully compiled the shader.
108  * If the shader source has not yet
109  * been sent to GL for compiling, will
110  * trigger those commands. Hence, should
111  * only be called from the GL rendering
112  * thread or if shader_ready() returns true.
113  */
114  bool
115  compile_success(void);
116 
117  /*!
118  * Returns the GL name (i.e. ID assigned by GL)
119  * of this Shader.
120  * If the shader source has not yet
121  * been sent to GL for compiling, will
122  * trigger those commands. Hence, should
123  * only be called from the GL rendering
124  * thread or if shader_ready() returns true.
125  */
126  GLuint
127  name(void);
128 
129  /*!
130  * Returns the shader type of this
131  * Shader as set by it's constructor.
132  */
133  GLenum
134  shader_type(void);
135 
136  /*!
137  * Provided as a conveniance to return a string
138  * from a GL enumeration naming a shader type.
139  * For example <B>GL_VERTEX_SHADER</B> will
140  * return the string "GL_VERTEX_SHADER".
141  * Unreconized shader types will return the
142  * label "UNKNOWN_SHADER_STAGE".
143  */
144  static
145  c_string
146  gl_shader_type_label(GLenum ptype);
147 
148  /*!
149  * Returns the default shader version to feed to
150  * \ref glsl::ShaderSource::specify_version() to
151  * match with the GL API. If GL backend, then
152  * gives "330". If GLES backend, then gives "300 es".
153  */
154  static
155  c_string
157 
158 private:
159  void *m_d;
160 };
161 
162 /*!
163  * \brief
164  * A PreLinkAction is an action to apply to a \ref Program
165  * after attaching shaders but before linking.
166  */
168  public reference_counted<PreLinkAction>::concurrent
169 {
170 public:
171  virtual
172  ~PreLinkAction()
173  {}
174 
175  /*!
176  * To be implemented by a derived class to perform an action _before_ the
177  * GLSL program is linked. Default implementation does nothing.
178  * \param glsl_program GL name of GLSL program on which to perform the action.
179  */
180  virtual
181  void
182  action(GLuint glsl_program) const = 0;
183 };
184 
185 
186 /*!
187  * \brief
188  * A BindAttribute inherits from \ref PreLinkAction,
189  * it's purpose is to bind named attributes to named
190  * locations, i.e. it calls glBindAttributeLocation().
191  */
193 {
194 public:
195  /*!
196  * Ctor.
197  * \param pname name of attribute in GLSL code
198  * \param plocation location to which to place the attribute
199  */
200  BindAttribute(c_string pname, int plocation);
201 
202  ~BindAttribute();
203 
204  virtual
205  void
206  action(GLuint glsl_program) const;
207 
208 private:
209  void *m_d;
210 };
211 
212 /*!
213  * \brief
214  * A ProgramSeparable inherits from \ref PreLinkAction,
215  * its purpose is to set a GLSL program as separable,
216  * so that it can be used by a GLSL pipeline.
217  * Using a ProgramSeparable requires:
218  * - for GLES: GLES3.0 or higher
219  * - for GL: either GL version 4.1 or the extension GL_ARB_separate_shader_objects
220  */
222 {
223 public:
224  virtual
225  void
226  action(GLuint glsl_program) const;
227 };
228 
229 /*!
230  * \brief
231  * A BindFragDataLocation inherits from \ref PreLinkAction,
232  * its purpose is to bind a fragment shader out to
233  * a named location and index. Using a BindFragDataLocation
234  * requires:
235  * - for GLES: GLES3.0 (or higher) and the extension GL_EXT_blend_func_extended
236  * - for GL: GL version 3.3 (or higher)
237  */
239 {
240 public:
241  /*!
242  * Ctor.
243  * \param pname name of attribute in GLSL code
244  * \param plocation location for fragment shader output to occupy
245  * \param pindex index (used for dual source blending) for
246  * fragment shader output to occupy
247  */
248  BindFragDataLocation(c_string pname, int plocation, int pindex = 0);
249 
251 
252  virtual
253  void
254  action(GLuint glsl_program) const;
255 
256 private:
257  void *m_d;
258 };
259 
260 /*!
261  * \brief
262  * A TransformFeedbackVarying encapsulates a call to
263  * glTransformFeedbackVarying. Note that if there are
264  * multiple \ref TransformFeedbackVarying objects on a
265  * single \ref PreLinkActionArray, then only the last
266  * one added has effect.
267  */
269 {
270 public:
271  /*!
272  * Ctor.
273  * \param buffer_mode the buffer mode to use on
274  * glTransformFeedbackVarying.
275  */
276  explicit
277  TransformFeedbackVarying(GLenum buffer_mode = GL_INTERLEAVED_ATTRIBS);
278 
280 
281  /*!
282  * Return the \ref string_array holding the varyings to
283  * capture in transform feedback in the order they will
284  * be captured; modify this object the change what is
285  * captured in transform feedback.
286  */
287  string_array&
288  transform_feedback_varyings(void);
289 
290  /*!
291  * Return the \ref string_array holding the varyings to
292  * capture in transform feedback in the order they will
293  * be captured.
294  */
295  const string_array&
296  transform_feedback_varyings(void) const;
297 
298  virtual
299  void
300  action(GLuint glsl_program) const;
301 
302 private:
303  void *m_d;
304 };
305 
306 /*!
307  * \brief
308  * A PreLinkActionArray is a conveniance class
309  * wrapper over an array of \ref PreLinkAction handles.
310  */
312 {
313 public:
314  /*!
315  * Ctor.
316  */
317  PreLinkActionArray(void);
318 
319  /*!
320  * Copy ctor.
321  * \param obj value from which to copy
322  */
324 
326 
327  /*!
328  * Assignment operator.
329  * \param rhs value from which to copy.
330  */
332  operator=(const PreLinkActionArray &rhs);
333 
334  /*!
335  * Swap operation
336  * \param obj object with which to swap
337  */
338  void
339  swap(PreLinkActionArray &obj);
340 
341  /*!
342  * Add a prelink action to execute.
343  * \param h handle to action to add
344  */
347 
348  /*!
349  * Provided as a conveniance, equivalent to
350  * \code
351  * add(FASTUIDRAWnew BindAttribute(pname, plocation))
352  * \endcode
353  * \param pname name of the attribute
354  * \param plocation location to which to bind the attribute.
355  */
357  add_binding(c_string pname, int plocation)
358  {
360  h = FASTUIDRAWnew BindAttribute(pname, plocation);
361  return add(h);
362  }
363 
364  /*!
365  * Provided as a conveniance, equivalent to
366  * \code
367  * add(FASTUIDRAWnew BindFragDataLocation(pname, plocation, pindex))
368  * \endcode
369  * \param pname name of the attribute
370  * \param plocation location for fragment shader output to occupy
371  * \param pindex index (used for dual source blending) for
372  * fragment shader output to occupy
373  */
375  add_frag_binding(c_string pname, int plocation, int pindex = 0)
376  {
378  h = FASTUIDRAWnew BindFragDataLocation(pname, plocation, pindex);
379  return add(h);
380  }
381 
382  /*!
383  * Provided as a conveniance, equivalent to
384  * \code
385  * reference_counted_ptr<TransformFeedbackVarying> h;
386  * h = TransformFeedbackVarying(buffer_mode);
387  * h->transform_feedback_varyings() = varyings;
388  * add(h)
389  * \endcode
390  * \param varyings list of varyings to capture for transform feedback
391  * \param buffer_mode buffer mode (i.e. interleaved or not) for transform feedback
392  */
395  GLenum buffer_mode = GL_INTERLEAVED_ATTRIBS)
396  {
398  h = FASTUIDRAWnew TransformFeedbackVarying(buffer_mode);
399  h->transform_feedback_varyings() = varyings;
400  return add(h);
401  }
402 
403  /*!
404  * Executes PreLinkAction::action() for each of those
405  * actions added via add().
406  */
407  void
408  execute_actions(GLuint glsl_program) const;
409 
410 private:
411  void *m_d;
412 };
413 
414 class Program;
415 
416 /*!
417  * \brief
418  * A ProgramInitializer is a functor object called the first time
419  * a Program is bound (i.e. the first
420  * time Program::use_program() is called).
421  * It's main purpose is to facilitate initializing
422  * uniform values.
423  */
425  public reference_counted<ProgramInitializer>::concurrent
426 {
427 public:
428  virtual
430  {}
431 
432  /*!
433  * To be implemented by a derived class to perform additional
434  * one-time actions. Function is called after the GL program
435  * object is successfully linked.
436  * \param pr Program to initialize
437  * \param program_bound GLSL Program is already bound, the program is
438  * NOT bound if the GL/GLES API supports seperable
439  * program objects.
440  */
441  virtual
442  void
443  perform_initialization(Program *pr, bool program_bound) const = 0;
444 };
445 
446 /*!
447  * \brief
448  * Conveniance class to hold an array of handles
449  * of ProgramInitializer objects
450  */
452 {
453 public:
454  /*!
455  * Ctor.
456  */
458 
459  /*!
460  * Copy ctor.
461  * \param obj value from which to copy
462  */
464 
466 
467  /*!
468  * Assignment operator.
469  * \param rhs value from which to copy.
470  */
472  operator=(const ProgramInitializerArray &rhs);
473 
474  /*!
475  * Swap operation
476  * \param obj object with which to swap
477  */
478  void
480 
481  /*!
482  * Add an initializer
483  * \param h handle to initializer to add
484  */
487 
488  /*!
489  * Provided as a conveniance, creates a UniformInitializer
490  * object and adds that via add().
491  * \param uniform_name name of uniform in GLSL to initialize
492  * \param value value with which to set the uniform
493  */
494  template<typename T>
496  add_uniform_initializer(c_string uniform_name, const T &value);
497 
498  /*!
499  * Provided as a conveniance, creates a SamplerInitializer
500  * object and adds that via add().
501  * \param uniform_name name of uniform in GLSL to initialize
502  * \param value value with which to set the uniform, in this
503  * case specifies the texture unit as follows:
504  * a value of n means to use GL_TEXTUREn texture
505  * unit.
506  */
508  add_sampler_initializer(c_string uniform_name, int value);
509 
510  /*!
511  * Provided as a conveniance, creates a UniformBlockInitializer
512  * object and adds that via add().
513  * \param uniform_name name of uniform in GLSL to initialize
514  * \param value value with which to set the uniform, in this
515  * case specifies the binding point index to
516  * pass to glBindBufferBase or glBindBufferRange.
517  */
519  add_uniform_block_binding(c_string uniform_name, int value);
520 
521  /*!
522  * For each objected added via add(), call
523  * ProgramInitializer::perform_initialization().
524  * \param pr Program to pass along
525  * \param program_bound if the program is currently bound to
526  * the GL context
527  */
528  void
529  perform_initializations(Program *pr, bool program_bound) const;
530 
531  /*!
532  * Clear all elements that have been added via add().
533  */
534  void
535  clear(void);
536 
537 private:
538  void *m_d;
539 };
540 
541 /*!
542  * \brief
543  * Class for creating and using GLSL programs.
544  *
545  * A Program delays the GL commands to
546  * create the actual GL program until the first time
547  * it is bound with use_program(). In addition to
548  * proving the GL code to create the GLSL code,
549  * Program also provides queries GL for all
550  * active uniforms and attributes (see active_attributes(),
551  * active_uniforms(), find_uniform() and find_attribute()).
552  * Also, provides an interface so that a sequence of
553  * GL commands are executed the first time it is bound
554  * and also an interface so a sequence of actions is
555  * executed every time it is bound.
556  * Program's are considered a resource,
557  * as such have a resource manager.
558  */
559 class Program:
560  public reference_counted<Program>::concurrent
561 {
562 public:
563  /*!
564  * \brief
565  * Enumeration to describe the backing of a shader
566  * variable's value.
567  */
569  {
570  /*!
571  * Indicates that the shader variable is from
572  * the default uniform block; the variable's
573  * value is not sourced from a backing buffer
574  * object.
575  */
577 
578  /*!
579  * Indicats that the shader variable is an
580  * atomic buffer counter and sourced from
581  * a backing buffer object.
582  */
584 
585  /*!
586  * Indicats that the shader variable is from
587  * the a uniform block; the variable's value
588  * is sourced from a backing buffer object.
589  */
591 
592  /*!
593  * Indicats that the shader variable is from
594  * the a shader storage block; the variable
595  * is backed by a buffer object.
596  */
598 
599  /*!
600  * Indicates that the shader variable is an
601  * input (i.e an 'in' of GLSL).
602  */
604 
605  /*!
606  * Indicates that the shader variable is an
607  * output (i.e an 'out' of GLSL).
608  */
610 
611  /*!
612  * Indicates that the shader variable is a
613  * transform feedback variable
614  */
616 
617  /*!
618  * Indicates that the shader variable is a nullptr
619  * value; such values are returned when a query
620  * for a shader variable is made and there is
621  * no such shader variable.
622  */
624  };
625 
626  /*!
627  * \brief
628  * A shader_variable_info holds the type,
629  * size and name of a uniform or an attribute
630  * of a GL program.
631  */
633  {
634  public:
635  /*!
636  * Ctor
637  */
638  shader_variable_info(void);
639 
640  /*!
641  * Implicit cast operator to bool. If returns
642  * false, indicates that the shader_variable_info
643  * is null, and returns values for members also
644  * will indicate that the value is not an attribute,
645  * a uniform of the default uniform block, a variable
646  * of a shader storage block, or an atomic counter.
647  */
648  operator bool() const
649  {
650  return m_d != nullptr;
651  }
652 
653  /*!
654  * Name of the parameter within the GL API.
655  */
656  c_string
657  name(void) const;
658 
659  /*!
660  * GL enumeration stating the shader variable's
661  * GLSL type.
662  */
663  GLenum
664  glsl_type(void) const;
665 
666  /*!
667  * Returns the shader variables's backing source
668  * type.
669  */
671  shader_variable_src(void) const;
672 
673  /*!
674  * If parameter is an array, holds
675  * the legnth of the array, otherwise
676  * is 1.
677  */
678  GLint
679  count(void) const;
680 
681  /*!
682  * GL API index for the parameter. The value of index()
683  * is used in calls to GL to query about the parameter,
684  * such as glGetActiveUniform and glGetActiveUniformsiv.
685  */
686  GLuint
687  index(void) const;
688 
689  /*!
690  * "Location" of the uniform or attribute
691  * as returned by glGetUniformLocation
692  * or glGetAttribLocation. For members of
693  * a uniform block or a shader storage
694  * buffer, value is -1.
695  * \param array_element index into array variable represents
696  */
697  GLint
698  location(unsigned int array_element = 0) const;
699 
700  /*!
701  * Returns the index to what uniform block this
702  * belongs. If this value does not reside on a
703  * uniform block, returns -1. The index is the
704  * value to feed as bufferIndex in the GL API
705  * function's
706  * \code
707  * glGetProgramResourceiv(program, GL_UNIFORM_BLOCK, bufferIndex, ...)
708  * glGetProgramResourceName(program, GL_UNIFORM_BLOCK, bufferIndex, ...)
709  * glGetActiveUniformBlockiv(program, bufferIndex, ..)
710  * glGetActiveUniformBlockName(program, bufferIndex, ...)
711  * glUniformBlockBinding(program, bufferIndex, ...)
712  * \endcode
713  */
714  GLint
715  ubo_index(void) const;
716 
717  /*!
718  * Returns the offset into a backing buffer object
719  * on which the this is sourced (or written to).
720  * For attributes and uniforms of the default uniform
721  * block which are not atomic counters, returns -1.
722  * \param array_index index into array variable represents
723  * \param leading_array_index index into leading array (for case where
724  * shader_storage_buffer_top_level_array_size()
725  * is not negative one).
726  */
727  GLint
728  buffer_offset(unsigned int array_index = 0,
729  unsigned int leading_array_index = 0) const;
730 
731  /*!
732  * If this is an array, not an attribute or uniform
733  * of the default uniform block, then returns the stride,
734  * in bytes, between elements of the array. Otherwise
735  * returns -1.
736  */
737  GLint
738  array_stride(void) const;
739 
740  /*!
741  * Returns -1 if this is not an array of matrices
742  * from a uniform block that is not the default block.
743  * If not, then returns the stride between columns
744  * for column major matrixes and otherwise returns
745  * the stride between row major matrices.
746  */
747  GLint
748  matrix_stride(void) const;
749 
750  /*!
751  * If this a matrix from not the default uniform block,
752  * return true if the matrix is row major. Otherwise
753  * returns false.
754  */
755  bool
756  is_row_major(void) const;
757 
758  /*!
759  * If this is an atomic counter, returns the index of atomic
760  * buffer that the counter is associated with. If not, returns
761  * -1. The index is the value to feed as bufferIndex in the
762  * GL API to query the atomic buffer block, i.e the functions
763  * \code
764  * glGetProgramResourceiv(program, GL_ATOMIC_COUNTER_BUFFER, bufferIndex, ...)
765  * glGetActiveAtomicCounterBufferiv(GLint program, GLuint bufferIndex, ..)
766  * \endcode
767  */
768  GLint
769  abo_index(void) const;
770 
771  /*!
772  * If this variable is a member of a shader storage buffer, returns
773  * to what shader storage buffer block this belongs. If not a shader
774  * storage buffer variable, returns -1. This value is used for
775  * bufferIndex in the GL API routines
776  * \code
777  * glGetProgramResourceiv(program, GL_SHADER_STORAGE_BUFFER, bufferIndex, ...)
778  * glGetProgramResourceName(program, GL_SHADER_STORAGE_BUFFER, bufferIndex, ...)
779  * glShaderStorageBlockBinding(program, bufferIndex, ...)
780  * \endcode
781  */
782  GLint
783  shader_storage_buffer_index(void) const;
784 
785  /*!
786  * If this variable has shader_storage_buffer_index() return -1, then
787  * returns -1. Otherwise returns the size of the top level
788  * array to which the variable belongs. If the top level
789  * array is unsized returns 0.
790  */
791  GLint
792  shader_storage_buffer_top_level_array_size(void) const;
793 
794  /*!
795  * If this variable has shader_storage_buffer_index() return -1, then
796  * returns -1. Otherwise returns the stride of the top level
797  * array to which the variable belongs. If it does belong
798  * to a top level array, returns 0.
799  */
800  GLint
801  shader_storage_buffer_top_level_array_stride(void) const;
802 
803  /*!
804  * If this variable is a transform feedback variable, returns
805  * to what transform feedback buffer the variable is written.
806  * If not a transform feedback variable, returns -1.
807  */
808  GLint
809  transform_feedback_buffer_index(void) const;
810 
811  private:
812  explicit
813  shader_variable_info(const void*);
814 
815  const void *m_d;
816  friend class Program;
817  };
818 
819  /*!
820  * \brief
821  * A block_info represents an object from which
822  * one can query the members of a uniform or
823  * shader storage block.
824  */
826  {
827  public:
828  /*!
829  * Ctor
830  */
831  block_info(void);
832 
833  /*!
834  * Implicit cast operator to bool. If returns
835  * false, indicates that the block_info
836  * is null, and thus name() returns an empty
837  * string, block_index() returns -1, buffer_size()
838  * returns 0 and so on.
839  */
840  operator bool() const
841  {
842  return m_d ? true : false;
843  }
844 
845  /*!
846  * Name of the block within the GL API.
847  */
848  c_string
849  name(void) const;
850 
851  /*!
852  * Returns the backing type of the block.
853  */
855  shader_variable_src(void) const;
856 
857  /*!
858  * GL API index for the parameter. The value of block_index() is used
859  * in calls to GL to query and set properties of the block. The
860  * default uniform block will have this value as -1. The value of
861  * block_index() is the same value as shader_variable_info::ubo_index()
862  * for shader variables on a uniform block, for shader variables
863  * on a shader storage buffer block and it is the same value as
864  * shader_variable_info::shader_storage_buffer_index(void).
865  * Lastly, block_index() is the value to feed to Program::uniform_block()
866  * for uniform blocks and the value to feed to Program::shader_storage_block()
867  * for shader storage blocks.
868  */
869  GLint
870  block_index(void) const;
871 
872  /*!
873  * Returns the size in bytes of the block (i.e.the size needed for a
874  * buffer object to correctly back the block). The default uniform
875  * block will have the size as 0.
876  */
877  GLint
878  buffer_size(void) const;
879 
880  /*!
881  * Returns the buffer binding point of the block when the GLSL
882  * program was -FIRST- created. If that binding point has been
883  * changed (for instance for UBO's by calling glUniformBlockBinding,
884  * or for SSBO's by calling glShaderStorageBlockBinding), then the
885  * return value is not suitable to be used to compute the binding
886  * point. Note that GLES3 does not allow for the binding point
887  * of an SSBO to change (because glShaderStorageBlockBinding is
888  * not part of its API).
889  */
890  GLint
891  initial_buffer_binding(void) const;
892 
893  /*!
894  * Returns the number of active variables of the block.
895  * Note that an array of is classified as a single
896  * variable.
897  */
898  unsigned int
899  number_variables(void) const;
900 
901  /*!
902  * Returns the ID'd variable. The values are sorted in
903  * alphabetical order of shader_variable_info::name(). The
904  * variable list is for those variables of this block.
905  * \param I -ID- (not location) of variable, if I is
906  * not less than number_variables(), returns
907  * a shader_variable_info indicating no value (i.e.
908  * shader_variable_info::name() is an empty string and
909  * shader_variable_info::index() is -1).
910  */
912  variable(unsigned int I);
913 
914  /*!
915  * Find a shader variable in the block from the a name. The search
916  * handles the case where looking for an element of an array
917  * and also, in the case of a shader storage block variable where
918  * shader_variable_info::shader_storage_buffer_top_level_array_size()
919  * being not negative one, giving the leading index into the top
920  * level array as well. The values can be used in the methods
921  * shader_variable_info::location() and shader_variable_info::buffer_offset()
922  * to get the location and buffer offset of the element of the shader
923  * variable.
924  * \param name variable name to look for
925  * \param *out_array_index location to which to write the array index
926  * value; if nullptr, value is not written
927  * \param *out_leading_array_index location to which to write the
928  * leading array index value; if nullptr,
929  * value is not written
930  */
932  variable(c_string name,
933  unsigned int *out_array_index = nullptr,
934  unsigned int *out_leading_array_index = nullptr);
935 
936  /*!
937  * Comparison operation for sorting. Comparison is done
938  * by internal pointer value of object not the values
939  * of the object.
940  * \param rhs block_info to which to compare.
941  */
942  bool
943  operator<(block_info rhs) const
944  {
945  return m_d < rhs.m_d;
946  }
947 
948  private:
949  explicit
950  block_info(const void*);
951 
952  const void *m_d;
953  friend class Program;
954  };
955 
956  /*!
957  * \brief
958  * An atomic_buffer_info represents an object from which
959  * one can query the data of an atomic buffer.
960  */
962  {
963  public:
964  /*!
965  * Ctor
966  */
967  atomic_buffer_info(void);
968 
969  /*!
970  * Implicit cast operator to bool. If returns
971  * false, indicates that the atomic_buffer_info
972  * is null, and thus buffer_index() returns -1,
973  * buffer_size() returns 0 and so on.
974  */
975  operator bool() const
976  {
977  return m_d ? true : false;
978  }
979 
980  /*!
981  * Block label (to match better interface of \ref block_info);
982  * name is given as "#X_atomic_buffer" where X is the value of
983  * buffer_binding().
984  */
985  c_string
986  name(void) const;
987 
988  /*!
989  * GL API index for querying the atomic buffer. The value
990  * of buffer_index() is used in calls to GL to query the
991  * atomic buffer block, i.e. the value to feed as index to
992  * the GL API functions:
993  * \code
994  * glGetProgramResourceiv(program, GL_ATOMIC_COUNTER_BUFFER, index, ...)
995  * glGetActiveAtomicCounterBufferiv(GLuint program, GLuint index, ...)
996  * \endcode
997  * It is also the value to feed to Program::atomic_buffer().
998  */
999  GLint
1000  buffer_index(void) const;
1001 
1002  /*!
1003  * The GL API index for the binding point of the atomic
1004  * buffer, i.e. the value to feed as bufferIndex to the
1005  * GL API functions:
1006  * \code
1007  * glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, bufferIndex, ...)
1008  * glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, bufferIndex, ..)
1009  * \endcode
1010  */
1011  GLint
1012  buffer_binding(void) const;
1013 
1014  /*!
1015  * Returns the size in bytes of the atomic buffer (i.e.
1016  * the size needed for a buffer object to correctly back
1017  * the atomic buffer block).
1018  */
1019  GLint
1020  buffer_size(void) const;
1021 
1022  /*!
1023  * Returns the number of atomic -variables- of the
1024  * atomic buffer. Note that an array is classified
1025  * as a single variable.
1026  */
1027  unsigned int
1028  number_variables(void) const;
1029 
1030  /*!
1031  * Returns the ID'd atomic variable. The values are sorted in
1032  * alphabetical order of shader_variable_info::name(). The variable
1033  * list is for those atomic variables of this atomic buffer
1034  * \param I -array index- (not location) of atomic, if I is
1035  * not less than number_atomic_variables(), returns
1036  * a shader_variable_info indicating nothing (i.e.
1037  * shader_variable_info::name() is an empty string and
1038  * shader_variable_info::index() is -1).
1039  */
1041  variable(unsigned int I);
1042 
1043  /*!
1044  * Find a shader variable in the block from the a name. The search
1045  * handles the case where looking for an element of an array
1046  * The value can be used in the method shader_variable_info::buffer_offset()
1047  * to get the buffer offset of the element of the shader variable.
1048  * \param name variable name to look for
1049  * \param[out] *out_array_index location to which to write the array index
1050  * value; if nullptr, value is not written
1051  */
1053  variable(c_string name,
1054  unsigned int *out_array_index = nullptr);
1055 
1056  /*!
1057  * Comparison operation for sorting. Comparison is done
1058  * by internal pointer value of object not the values
1059  * of the object.
1060  * \param rhs atomic_buffer_info to which to compare.
1061  */
1062  bool
1063  operator<(atomic_buffer_info rhs) const
1064  {
1065  return m_d < rhs.m_d;
1066  }
1067 
1068  private:
1069  explicit
1070  atomic_buffer_info(const void*);
1071 
1072  const void *m_d;
1073  friend class Program;
1074  };
1075 
1076  /*!
1077  * Ctor.
1078  * \param pshaders shaders used to create the Program
1079  * \param action specifies actions to perform before linking of the Program
1080  * \param initers one-time initialization actions to perform at GLSL
1081  * program creation
1082  */
1084  const PreLinkActionArray &action = PreLinkActionArray(),
1086 
1087  /*!
1088  * Ctor.
1089  * \param vert_shader pointer to vertex shader to use for the Program
1090  * \param frag_shader pointer to fragment shader to use for the Program
1091  * \param action specifies actions to perform before and
1092  * after linking of the Program.
1093  * \param initers one-time initialization actions to perform at GLSL
1094  * program creation
1095  */
1097  reference_counted_ptr<Shader> frag_shader,
1098  const PreLinkActionArray &action = PreLinkActionArray(),
1100 
1101  /*!
1102  * Ctor.
1103  * \param vert_shader pointer to vertex shader to use for the Program
1104  * \param frag_shader pointer to fragment shader to use for the Program
1105  * \param action specifies actions to perform before and
1106  * after linking of the Program.
1107  * \param initers one-time initialization actions to perform at GLSL
1108  * program creation
1109  */
1110  Program(const glsl::ShaderSource &vert_shader,
1111  const glsl::ShaderSource &frag_shader,
1112  const PreLinkActionArray &action = PreLinkActionArray(),
1114 
1115  /*!
1116  * Ctor. Create a \ref Program from a previously linked GL shader.
1117  * \param pname GL ID of previously linked shader
1118  * \param take_ownership if true when dtor is called glDeleteProgram
1119  * is called as well
1120  */
1121  Program(GLuint pname, bool take_ownership);
1122 
1123  ~Program(void);
1124 
1125  /*!
1126  * Call to set GL to use the GLSLProgram
1127  * of this Program. The GL context
1128  * must be current.
1129  */
1130  void
1131  use_program(void);
1132 
1133  /*!
1134  * Returns the GL name (i.e. ID assigned by GL,
1135  * for use in glUseProgram) of this Program.
1136  * This function should
1137  * only be called either after use_program() has
1138  * been called or only when the GL context is
1139  * current.
1140  */
1141  GLuint
1142  name(void);
1143 
1144  /*!
1145  * Returns the link log of this Program,
1146  * essentially the value returned by
1147  * glGetProgramInfoLog. This function should
1148  * only be called either after use_program() has
1149  * been called or only when the GL context is
1150  * current.
1151  */
1152  c_string
1153  link_log(void);
1154 
1155  /*!
1156  * Returns how many seconds it took for the program
1157  * to be assembled and linked.
1158  */
1159  float
1160  program_build_time(void);
1161 
1162  /*!
1163  * Returns true if and only if this Program
1164  * successfully linked. This function should
1165  * only be called either after use_program() has
1166  * been called or only when the GL context is
1167  * current.
1168  */
1169  bool
1170  link_success(void);
1171 
1172  /*!
1173  * Returns the full log (including shader source
1174  * code and link_log()) of this Program.
1175  * This function should only be called either after
1176  * use_program() has been called or only when the GL
1177  * context is current.
1178  */
1179  c_string
1180  log(void);
1181 
1182  /*!
1183  * Returns a \ref block_info of the default uniform block,
1184  * the default uniform block does NOT include shader variables
1185  * coming from atomic buffer counters.
1186  */
1187  block_info
1188  default_uniform_block(void);
1189 
1190  /*!
1191  * Returns the number of active uniform blocks (not
1192  * including the default uniform block). This function should
1193  * only be called either after use_program() has been called
1194  * or only when the GL context is current.
1195  */
1196  unsigned int
1197  number_active_uniform_blocks(void);
1198 
1199  /*!
1200  * Returns the indexed uniform block; the index passed
1201  * is the index as used by the GL API to query the uniform
1202  * block (and thus the same as shader_variable_info::ubo_index()).
1203  * This function should only be called either after use_program()
1204  * has been called or only when the GL context is current.
1205  * \param I which one to fetch, if I is not less than
1206  * number_active_uniform_blocks(), then returns
1207  * a null block_info object.
1208  */
1209  block_info
1210  uniform_block(unsigned int I);
1211 
1212  /*!
1213  * Searches uniform_block(unsigned int) to find the
1214  * named uniform block. Return value ~0u indicates that
1215  * the uniform block could not be found, otherwise returns
1216  * the value to feed to uniform_block(unsigned int). This
1217  * function should only be called either after use_program()
1218  * has been called or only when the GL context is current.
1219  * \param uniform_block_name name of uniform block to find
1220  */
1221  unsigned int
1222  uniform_block_id(c_string uniform_block_name);
1223 
1224  /*!
1225  * Seaches uniform_block(unsigned int) to find the
1226  * named uniform block. If no such uniform block
1227  * has that name returns a null block_info object.
1228  * Provided as a conveniance, equivalent to
1229  * \code
1230  * uniform_block(uniform_block_id(uniform_block_name))
1231  * \endcode
1232  * This function should only be called either after
1233  * use_program() has been called or only when the GL
1234  * context is current.
1235  * \param uniform_block_name name of uniform block to find
1236  */
1237  block_info
1238  uniform_block(c_string uniform_block_name)
1239  {
1240  return uniform_block(uniform_block_id(uniform_block_name));
1241  }
1242 
1243  /*!
1244  * Returns the location of a uniform and also correctly
1245  * handles fetching the uniform of an element of a uniform
1246  * array. Returns -1 if there is no uniform on the default
1247  * block with that name.
1248  */
1249  GLint
1250  uniform_location(c_string name);
1251 
1252  /*!
1253  * Returns the number of active shader storage blocks.
1254  * This function should only be called either after
1255  * use_program() has been called or only when the GL context
1256  * is current.
1257  */
1258  unsigned int
1259  number_active_shader_storage_blocks(void);
1260 
1261  /*!
1262  * Returns the indexed shader_storage block; the index passed
1263  * is the index as used by the GL API to query the uniform
1264  * block (and thus the same as
1265  * shader_variable_info::shader_storage_buffer_index()).
1266  * This function should only be called either after use_program()
1267  * \param I which one to fetch, if I is not less than
1268  * number_active_shader_storage_blocks(), then returns
1269  * a nullptr block_info
1270  */
1271  block_info
1272  shader_storage_block(unsigned int I);
1273 
1274  /*!
1275  * Searches shader_storage_block(unsigned int) to find the named
1276  * shader_storage block. Return value ~0u indicates that the
1277  * shader_storage block could not be found. This function should
1278  * only be called either after use_program() has been called or
1279  * only when the GL context is current.
1280  * \param shader_storage_block_name name of shader storage to find
1281  */
1282  unsigned int
1283  shader_storage_block_id(c_string shader_storage_block_name);
1284 
1285  /*!
1286  * Seaches shader_storage_block(unsigned int) to find the
1287  * named uniform block. If no such uniform block
1288  * has that name returns a null block_info object.
1289  * Provided as a conveniance, equivalent to
1290  * \code
1291  * shader_storage_block(shader_storage_block_id(shader_storage_block_name))
1292  * \endcode
1293  * This function should only be called either after
1294  * use_program() has been called or only when the GL
1295  * context is current.
1296  * \param shader_storage_block_name name of shader storage to find
1297  */
1298  block_info
1299  shader_storage_block(c_string shader_storage_block_name)
1300  {
1301  return shader_storage_block(shader_storage_block_id(shader_storage_block_name));
1302  }
1303 
1304  /*!
1305  * Returns the number of active atomic buffers. This function
1306  * should only be called either after use_program() has been
1307  * called or only when the GL context is current.
1308  */
1309  unsigned int
1310  number_active_atomic_buffers(void);
1311 
1312  /*!
1313  * Returns the indexed atomic buffer. the index passed
1314  * is the index as used by the GL API to query the uniform
1315  * block (and thus the same as shader_variable_info::abo_index()).
1316  * This function should only be called either after use_program()
1317  * has been called or only when the GL context is current.
1318  * \param I which one to fetch, if I is not less than
1319  * number_active_atomic_buffers(), then returns
1320  * a null atomic_buffer_info
1321  */
1323  atomic_buffer(unsigned int I);
1324 
1325  /*!
1326  * Returns the index to feed to atomic_buffer(unsigned int)
1327  * to fetch the atomic buffer with the value of
1328  * atomic_buffer_info::buffer_binding().
1329  * \param binding_point value for atomic_buffer_info::buffer_binding()
1330  * to search for.
1331  */
1332  unsigned int
1333  atomic_buffer_id(unsigned int binding_point);
1334 
1335  /*!
1336  * Searches the default uniform block, all uniform blocks
1337  * and all shader storage blocks for a shader variable.
1338  */
1340  find_shader_variable(c_string name,
1341  unsigned int *out_array_index = nullptr,
1342  unsigned int *out_leading_array_index = nullptr);
1343 
1344  /*!
1345  * Returns the number of active attributes. Note that an array
1346  * of uniforms is classified as a single uniform. This function
1347  * should only be called either after use_program() has been called
1348  * or only when the GL context is current.
1349  */
1350  unsigned int
1351  number_active_attributes(void);
1352 
1353  /*!
1354  * Returns the indexed attribute. This function should only be
1355  * called either after use_program() has been called or only
1356  * when the GL context is current. The values are sorted in
1357  * alphabetical order of shader_variable_info::name().
1358  * \param I -ID- (not location) of attribute, if I is
1359  * not less than number_active_attributes(), returns
1360  * a shader_variable_info indicating no attribute (i.e.
1361  * shader_variable_info::name() is an empty string and
1362  * shader_variable_info::index() is -1).
1363  */
1365  active_attribute(unsigned int I);
1366 
1367  /*!
1368  * Returns the number of active transform feedbacks. Note that an
1369  * array of transform feedback is classified as a single element.
1370  * This will also include padding in the form of gl_SkipComponents1,
1371  * gl_SkipComponents2, gl_SkipComponents3 and gl_SkipComponents4.
1372  * In addition it will also include gl_NextBuffer to indicated
1373  * advancing to the next buffer. This function should only be called
1374  * either after use_program() has been called or only when the GL
1375  * context is current.
1376  */
1377  unsigned int
1378  number_transform_feedbacks(void);
1379 
1380  /*!
1381  * Returns the indexed transform-feedback. This function should only
1382  * be called either after use_program() has been called or only
1383  * when the GL context is current. The values are sorted in
1384  * alphabetical order of shader_variable_info::name().
1385  * \param I -ID- (not location or index) of transform feedbach,
1386  * if I is not less than number_transform_feedbacks(),
1387  * returns a shader_variable_info indicating null (i.e.
1388  * shader_variable_info::name() is an empty string and
1389  * shader_variable_info::index() is -1).
1390  */
1392  transform_feedback(unsigned int I);
1393 
1394  /*!
1395  * Returns the number of transform feedback buffers.
1396  */
1397  unsigned int
1398  number_transform_feedback_buffers(void);
1399 
1400  /*!
1401  * Returns the stride in bytes between each element in the
1402  * named transform feedback buffer.
1403  * \param B which transform feedback buffer
1404  */
1405  unsigned int
1406  transform_feedback_buffer_stride(unsigned int B);
1407 
1408  /*!
1409  * Searches active_attribute() to find the named attribute, including
1410  * named elements of an array. This function should only be called
1411  * either after use_program() has been called or only when the GL
1412  * context is current. Returns value -1 indicated that the attribute
1413  * could not be found.
1414  * \param attribute_name name of attribute to find
1415  */
1416  GLint
1417  attribute_location(c_string attribute_name);
1418 
1419  /*!
1420  * Returns the number of shaders of a given type attached to
1421  * the Program.
1422  * \param tp GL enumeration of the shader type, see Shader::shader_type()
1423  */
1424  unsigned int
1425  num_shaders(GLenum tp) const;
1426 
1427  /*!
1428  * Returns true if the source code string for a shader
1429  * attached to the Program compiled successfully.
1430  * \param tp GL enumeration of the shader type, see Shader::shader_type()
1431  * \param i which shader with 0 <= i < num_shaders(tp)
1432  */
1433  bool
1434  shader_compile_success(GLenum tp, unsigned int i) const;
1435 
1436  /*!
1437  * Returns the source code string for a shader attached to
1438  * the Program.
1439  * \param tp GL enumeration of the shader type, see Shader::shader_type()
1440  * \param i which shader with 0 <= i < num_shaders(tp)
1441  */
1442  c_string
1443  shader_src_code(GLenum tp, unsigned int i) const;
1444 
1445  /*!
1446  * Returns the compile log for a shader attached to
1447  * the Program.
1448  * \param tp GL enumeration of the shader type, see Shader::shader_type()
1449  * \param i which shader with 0 <= i < num_shaders(tp)
1450  */
1451  c_string
1452  shader_compile_log(GLenum tp, unsigned int i) const;
1453 
1454 private:
1455  void *m_d;
1456 };
1457 
1458 /*!
1459  * \brief
1460  * A UniformInitalizerBase is a base class for
1461  * initializing a uniform, the actual GL call to
1462  * set the uniform value is to be implemented by
1463  * a derived class in init_uniform().
1464  */
1466 {
1467 public:
1468  /*!
1469  * Ctor.
1470  * \param uniform_name name of uniform to initialize
1471  */
1472  UniformInitalizerBase(c_string uniform_name);
1473 
1475 
1476  virtual
1477  void
1478  perform_initialization(Program *pr, bool program_bound) const;
1479 
1480 protected:
1481 
1482  /*!
1483  * To be implemented by a derived class to make the GL call
1484  * to initialize a uniform in a GLSL shader.
1485  * \param program GL program
1486  * \param info information on uniform (name, type, location, etc)
1487  * \param array_index index into GLSL uniform if it is an array
1488  * \param program_bound true if and only if the program named
1489  * by program is bound (via glUseProgram).
1490  * If the program is not bound, then one
1491  * SHOULD not bind the program and instead
1492  * use the GL API points to set values of
1493  * the uniform(s) that do not rely on having
1494  * the program bound. One can also safely assume
1495  * that those API points are supported in
1496  * the case it is not bound (in particular
1497  * the function family ProgramUniform() can
1498  * be safely used).
1499  */
1500  virtual
1501  void
1502  init_uniform(GLuint program, Program::shader_variable_info info,
1503  unsigned int array_index, bool program_bound) const = 0;
1504 
1505 private:
1506  void *m_d;
1507 };
1508 
1509 /*!
1510  * \brief
1511  * Initialize a uniform via the templated
1512  * overloaded function fastuidraw::gl::Uniform().
1513  */
1514 template<typename T>
1516 {
1517 public:
1518  /*!
1519  * Ctor.
1520  * \param uniform_name name of uniform in GLSL to initialize
1521  * \param value value with which to set the uniform
1522  */
1523  UniformInitializer(c_string uniform_name, const T &value):
1524  UniformInitalizerBase(uniform_name),
1525  m_value(value)
1526  {}
1527 
1528 protected:
1529 
1530  virtual
1531  void
1533  unsigned int array_index, bool program_bound) const
1534  {
1535  if (program_bound)
1536  {
1537  Uniform(info.location(array_index), m_value);
1538  }
1539  else
1540  {
1541  ProgramUniform(program, info.location(array_index), m_value);
1542  }
1543  }
1544 
1545 private:
1546  T m_value;
1547 };
1548 
1549 /*!
1550  * \brief
1551  * Specialization for type c_array<const T> for \ref UniformInitializer
1552  * so that data behind the c_array is copied
1553  */
1554 template<typename T>
1556 {
1557 public:
1558  /*!
1559  * Ctor.
1560  * \param uniform_name name of uniform in GLSL to initialize
1561  * \param value value with which to set the uniform
1562  */
1563  UniformInitializer(c_string uniform_name, const c_array<const T> &value):
1564  UniformInitalizerBase(uniform_name),
1565  m_data(nullptr)
1566  {
1567  if (!value.empty())
1568  {
1569  m_data = FASTUIDRAWmalloc(sizeof(T) * value.size());
1570  for (unsigned int i = 0; i < value.size(); ++i)
1571  {
1572  new (&m_data[i]) T(value[i]);
1573  }
1574  m_value = c_array<const T>(m_data, value.size());
1575  }
1576  }
1577 
1579  {
1580  if (m_data != nullptr)
1581  {
1582  for (unsigned int i = 0; i < m_value.size(); ++i)
1583  {
1584  m_data[i].~T();
1585  }
1586  FASTUIDRAWfree(m_data);
1587  }
1588  }
1589 
1590 protected:
1591 
1592  virtual
1593  void
1595  unsigned int array_index, bool program_bound) const
1596  {
1597  if (program_bound)
1598  {
1599  Uniform(info.location(array_index), m_value);
1600  }
1601  else
1602  {
1603  ProgramUniform(program, info.location(array_index), m_value);
1604  }
1605  }
1606 
1607 private:
1608  T *m_data;
1609  c_array<const T> m_value;
1610 };
1611 
1612 /*!
1613  * \brief
1614  * Class to intialize the binding points of samplers.
1615  * If the uniform is an array, the first element will
1616  * be given the specified binding point and successive
1617  * elements in the array will be given successive
1618  * binding points.
1619  */
1621 {
1622 public:
1623  /*!
1624  * Ctor.
1625  * \param uniform_name name of uniform sampler2D in GLSL to
1626  * initialize
1627  * \param binding_point binding point to initialize the uniform to;
1628  * If the uniform is an array, the first element
1629  * will be given the specified binding point and
1630  * successive elements in the array will be given
1631  * successive binding points.
1632  */
1633  SamplerInitializer(c_string uniform_name, int binding_point):
1634  UniformInitalizerBase(uniform_name),
1635  m_value(binding_point)
1636  {}
1637 
1638 protected:
1639 
1640  virtual
1641  void
1642  init_uniform(GLuint program, Program::shader_variable_info info,
1643  unsigned int array_index, bool program_bound) const;
1644 
1645 private:
1646  int m_value;
1647 };
1648 
1649 /*!
1650  * \brief
1651  * A UniformBlockInitializer is used to initalize the binding point
1652  * used by a bindable uniform (aka Uniform buffer object, see the
1653  * GL spec on glGetUniformBlockIndex and glUniformBlockBinding.
1654  */
1656 {
1657 public:
1658  /*!
1659  * Ctor.
1660  * \param name name of uniform block in GLSL to initialize
1661  * \param binding_point_index value with which to set the uniform
1662  */
1663  UniformBlockInitializer(c_string name, int binding_point_index);
1664 
1666 
1667  virtual
1668  void
1669  perform_initialization(Program *pr, bool program_bound) const;
1670 
1671 private:
1672  void *m_d;
1673 };
1674 
1675 //////////////////////////////////////////////////
1676 // inlined methods that need above classes defined
1677 template<typename T>
1680 add_uniform_initializer(c_string uniform_name, const T &value)
1681 {
1682  return add(FASTUIDRAWnew UniformInitializer<T>(uniform_name, value));
1683 }
1684 
1685 inline
1688 add_sampler_initializer(c_string uniform_name, int value)
1689 {
1690  return add(FASTUIDRAWnew SamplerInitializer(uniform_name, value));
1691 }
1692 
1693 inline
1696 add_uniform_block_binding(c_string uniform_name, int value)
1697 {
1698  return add(FASTUIDRAWnew UniformBlockInitializer(uniform_name, value));
1699 }
1700 
1701 #ifndef FASTUIDRAW_GL_USE_GLES
1702 /*!
1703  * \brief
1704  * A ShaderStorageBlockInitializer is used to initalize the binding point
1705  * used by a shader storage block (see the GL spec on
1706  * glShaderStorageBlockBinding). Initializer is not supported
1707  * in OpenGL ES.
1708  */
1710 {
1711 public:
1712  /*!
1713  * Ctor.
1714  * \param name name of shader storage block in GLSL to initialize
1715  * \param binding_point_index value with which to set the uniform
1716  */
1717  ShaderStorageBlockInitializer(c_string name, int binding_point_index);
1718 
1720 
1721  virtual
1722  void
1723  perform_initialization(Program *pr, bool program_bound) const;
1724 
1725 private:
1726  void *m_d;
1727 };
1728 
1729 #endif
1730 /*! @} */
1731 
1732 
1733 } //namespace gl
1734 } //namespace fastuidraw
1735 
1736 #endif
A shader_variable_info holds the type, size and name of a uniform or an attribute of a GL program...
Definition: gl_program.hpp:632
A UniformBlockInitializer is used to initalize the binding point used by a bindable uniform (aka Unif...
shader_variable_src_t
Enumeration to describe the backing of a shader variable&#39;s value.
Definition: gl_program.hpp:568
block_info shader_storage_block(c_string shader_storage_block_name)
GLint location(unsigned int array_element=0) const
A ShaderSource represents the source code to a GLSL shader, specifying blocks of source code and macr...
Simple Shader utility class providing a simple interface to build GL shader objects using a glsl::Sha...
Definition: gl_program.hpp:58
Shader(const glsl::ShaderSource &src, GLenum pshader_type)
A block_info represents an object from which one can query the members of a uniform or shader storage...
Definition: gl_program.hpp:825
GLenum shader_type(void)
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
UniformInitializer(c_string uniform_name, const T &value)
A wrapper over a pointer to implement reference counting.
file gl_header.hpp
virtual void init_uniform(GLuint program, Program::shader_variable_info info, unsigned int array_index, bool program_bound) const
Initialize a uniform via the templated overloaded function fastuidraw::gl::Uniform().
bool empty(void) const
Definition: c_array.hpp:274
virtual void init_uniform(GLuint program, Program::shader_variable_info info, unsigned int array_index, bool program_bound) const
A ShaderStorageBlockInitializer is used to initalize the binding point used by a shader storage block...
size_type size(void) const
Definition: c_array.hpp:283
Class to intialize the binding points of samplers. If the uniform is an array, the first element will...
A BindAttribute inherits from PreLinkAction, it&#39;s purpose is to bind named attributes to named locati...
Definition: gl_program.hpp:192
file shader_source.hpp
ProgramInitializerArray & add_uniform_initializer(c_string uniform_name, const T &value)
void swap(reference_counted_ptr< T > &lhs, reference_counted_ptr< T > &rhs)
c_string source_code(void)
void Uniform(int location, GLsizei count, const vecN< T, N > &v)
Template version for setting array of uniforms.
Definition: gluniform.hpp:65
file util.hpp
file gluniform.hpp
SamplerInitializer(c_string uniform_name, int binding_point)
A TransformFeedbackVarying encapsulates a call to glTransformFeedbackVarying. Note that if there are ...
Definition: gl_program.hpp:268
Conveniance class to hold an array of handles of ProgramInitializer objects.
Definition: gl_program.hpp:451
#define FASTUIDRAWfree(ptr)
Class for creating and using GLSL programs.
Definition: gl_program.hpp:559
#define FASTUIDRAWnew
A UniformInitalizerBase is a base class for initializing a uniform, the actual GL call to set the uni...
A c_array is a wrapper over a C pointer with a size parameter to facilitate bounds checking and provi...
Definition: c_array.hpp:43
An atomic_buffer_info represents an object from which one can query the data of an atomic buffer...
Definition: gl_program.hpp:961
file vecN.hpp
Defines default reference counting base classes.
UniformInitializer(c_string uniform_name, const c_array< const T > &value)
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
ProgramInitializerArray & add_sampler_initializer(c_string uniform_name, int value)
block_info uniform_block(c_string uniform_block_name)
static c_string default_shader_version(void)
bool compile_success(void)
A ProgramSeparable inherits from PreLinkAction, its purpose is to set a GLSL program as separable...
Definition: gl_program.hpp:221
file string_array.hpp
A BindFragDataLocation inherits from PreLinkAction, its purpose is to bind a fragment shader out to a...
Definition: gl_program.hpp:238
c_string compile_log(void)
#define FASTUIDRAWmalloc(size)
static c_string gl_shader_type_label(GLenum ptype)
A ProgramInitializer is a functor object called the first time a Program is bound (i...
Definition: gl_program.hpp:424
void ProgramUniform(GLuint program, int location, GLsizei count, const vecN< T, N > &v)
Template version for setting array of uniforms,.
Definition: gluniform.hpp:204
file reference_counted.hpp
ProgramInitializerArray & add_uniform_block_binding(c_string uniform_name, int value)