FastUIDraw
painter_shader_registrar_glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_shader_registrar_glsl.hpp
3  * \brief file painter_shader_registrar_glsl.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
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@gmail.com>
16  *
17  */
18 
19 #ifndef FASTUIDRAW_PAINTER_SHADER_REGISTRAR_GLSL_HPP
20 #define FASTUIDRAW_PAINTER_SHADER_REGISTRAR_GLSL_HPP
21 
28 
29 namespace fastuidraw
30 {
31  namespace glsl
32  {
33 /*!\addtogroup GLSL
34  * @{
35  */
36  /*!
37  * Conveniance class to hold types from which to inherit
38  */
40  {
41  public:
42  /*!
43  * \brief
44  * Enumeration to specify how the data store filled by
45  * \ref PainterDraw::m_store is realized.
46  */
48  {
49  /*!
50  * Data store is accessed by a usamplerBuffer
51  * (i.e. a texture a buffer object).
52  */
54 
55  /*!
56  * Data store is backed by a uniform buffer object
57  * that is an array of uvec4.
58  */
60 
61  /*!
62  * Data store is backed by a shader storage buffer object
63  * that is an array of uvec4.
64  */
66  };
67 
68  /*!
69  * Enumeration specifying how the uber-shaders will
70  * perform clipping against the clip-planes of \ref
71  * PainterClipEquations
72  */
74  {
75  /*!
76  * Clipping is performed in the vertex-shader
77  * using gl_ClipDistance[i] for 0 <= i < 4.
78  */
80 
81  /*!
82  * Clipping is performed by passing the distance
83  * to each clip-plane and performing discard in
84  * the fragment shader.
85  */
87 
88  /*!
89  * Clipping is performed by passing the distance
90  * to each clip-plane and (virtually) skipping the
91  * color write. This is active if the active \ref
92  * PainterBlendShader has PainterBlendShader::type()
93  * as \ref PainterBlendShader::framebuffer_fetch.
94  * For other blend-types, this is the same as \ref
95  * clipping_via_discard.
96  */
98  };
99 
100  /*!
101  * \brief
102  * Enumeration to specify how to perform framebuffer-fetch blending
103  */
105  {
106  /*!
107  * Indicates that framebuffer-fetch blending is not supported.
108  */
110 
111  /*!
112  * Use framebuffer fetch (i.e. the out of the fragment shader
113  * is an inout).
114  */
116 
117  /*!
118  * Have the color buffer realized as an image2D and use
119  * fragment shader interlock to get blending order correct.
120  */
122  };
123 
124  /*!
125  * \brief
126  * Enumeration to specify how to access the backing store
127  * of the glyph data stored in GlyphAtlas::store()
128  */
130  {
131  /*!
132  * Use a samplerBuffer to access the data
133  */
135 
136  /*!
137  * Use a sampler2DArray to access the data
138  */
140 
141  /*!
142  * Use a buffer block to access the data
143  */
145  };
146 
147  /*!
148  * \brief
149  * Enumeration to specify how to access the backing store
150  * of a color stop atlas store in ColorStopAtlas::backing_store().
151  */
153  {
154  /*!
155  * Color stop backing store is realized as a
156  * 1D texture array.
157  */
159 
160  /*!
161  * Color stop backing store is realized as a
162  * 2D texture array.
163  */
165  };
166 
167  /*!
168  * \brief
169  * Enumeration to specify the convention for a 3D API
170  * for its normalized device coordinate in z.
171  */
173  {
174  /*!
175  * Specifies that the normalized device coordinate
176  * for z goes from -1 to 1.
177  */
179 
180  /*!
181  * Specifies that the normalized device coordinate
182  * for z goes from 0 to 1.
183  */
185  };
186 
187  /*!
188  * \brief
189  * Enumeration to describe vertex shader input
190  * slot layout.
191  */
193  {
194  /*!
195  * Slot for the values of PainterAttribute::m_attrib0
196  * of PainterDraw::m_attributes
197  */
199 
200  /*!
201  * Slot for the values of PainterAttribute::m_attrib1
202  * of PainterDraw::m_attributes
203  */
205 
206  /*!
207  * Slot for the values of PainterAttribute::m_attrib2
208  * of PainterDraw::m_attributes
209  */
211 
212  /*!
213  * Slot for the values of PainterDraw::m_header_attributes
214  */
216  };
217 
218  /*!
219  * \brief
220  * An UberShaderParams specifies how to construct an uber-shader.
221  * Note that the usage of HW clip-planes is specified by
222  * ConfigurationGLSL, NOT UberShaderParams.
223  */
225  {
226  public:
227  /*!
228  * Ctor.
229  */
230  UberShaderParams(void);
231 
232  /*!
233  * Copy ctor.
234  * \param obj value from which to copy
235  */
237 
238  ~UberShaderParams();
239 
240  /*!
241  * Assignment operator
242  * \param rhs value from which to copy
243  */
245  operator=(const UberShaderParams &rhs);
246 
247  /*!
248  * Swap operation
249  * \param obj object with which to swap
250  */
251  void
252  swap(UberShaderParams &obj);
253 
254  /*!
255  * Returns the preferred way to implement blend shaders, i.e.
256  * if a shader can be implemented with this blending type
257  * it will be.
258  */
260  preferred_blend_type(void) const;
261 
262  /*!
263  * Specify the return value to preferred_blend_type() const.
264  * Default value is \ref PainterBlendShader::dual_src
265  * \param tp blend shader type
266  */
269 
270  /*!
271  * Returns how the painter will perform blending.
272  */
274  fbf_blending_type(void) const;
275 
276  /*!
277  * Specify the return value to fbf_blending_type() const.
278  * Default value is \ref fbf_blending_not_supported
279  * \param tp blend shader type
280  */
283 
284  /*!
285  * If true, indicates that the PainterRegistrar supports
286  * bindless texturing. Default value is false.
287  */
288  bool
289  supports_bindless_texturing(void) const;
290 
291  /*!
292  * Specify the return value to supports_bindless_texturing() const.
293  * Default value is false.
294  */
297 
298  /*!
299  * Specifies how the uber-shader will perform clipping.
300  */
301  enum clipping_type_t
302  clipping_type(void) const;
303 
304  /*!
305  * Set the value returned by clipping_type(void) const.
306  * Default value is \ref clipping_via_gl_clip_distance.
307  */
310 
311  /*!
312  * Specifies the normalized device z-coordinate convention
313  * that the shader is to use.
314  */
316  z_coordinate_convention(void) const;
317 
318  /*!
319  * Set the value returned by normalized_device_z_coordinate_convention(void) const.
320  * Default value is z_minus_1_to_1.
321  */
324 
325  /*!
326  * if true, assign the slot location of the vertex shader
327  * inputs (via layout(location =) in GLSL). The layout
328  * locations are defined by the enumeration
329  * vertex_shader_in_layout.
330  */
331  bool
333 
334  /*!
335  * Set the value returned by assign_layout_to_vertex_shader_inputs(void) const.
336  * Default value is true.
337  */
340 
341  /*!
342  * If true, assign the slot locations (via layout(location = ) in GLSL)
343  * for the varyings of the uber-shaders.
344  */
345  bool
346  assign_layout_to_varyings(void) const;
347 
348  /*!
349  * Set the value returned by assign_layout_to_varyings(void) const.
350  * Default value is true.
351  */
354 
355  /*!
356  * If true, assign binding points (via layout(binding = ) in GLSL)
357  * to the buffers and surfaces of the uber-shaders. The values
358  * for the binding are set by binding_points(const BindingPoints&).
359  */
360  bool
361  assign_binding_points(void) const;
362 
363  /*!
364  * Set the value returned by assign_binding_points(void) const.
365  * Default value is true.
366  */
368  assign_binding_points(bool);
369 
370  /*!
371  * If true, use a switch() in the uber-vertex shader to
372  * dispatch to the PainterItemShader.
373  */
374  bool
375  vert_shader_use_switch(void) const;
376 
377  /*!
378  * Set the value returned by vert_shader_use_switch(void) const.
379  * Default value is false.
380  */
383 
384  /*!
385  * If true, use a switch() in the uber-fragment shader to
386  * dispatch to the PainterItemShader.
387  */
388  bool
389  frag_shader_use_switch(void) const;
390 
391  /*!
392  * Set the value returned by frag_shader_use_switch(void) const.
393  * Default value is false.
394  */
397 
398  /*!
399  * If true, use a switch() in the uber-fragment shader to
400  * dispatch to the PainterBlendShader.
401  */
402  bool
403  blend_shader_use_switch(void) const;
404 
405  /*!
406  * Set the value returned by blend_shader_use_switch(void) const.
407  * Default value is false.
408  */
411 
412  /*!
413  * Specify how to access the data in PainterDraw::m_store
414  * from the GLSL shader.
415  */
417  data_store_backing(void) const;
418 
419  /*!
420  * Set the value returned by data_store_backing(void) const.
421  * Default value is data_store_tbo.
422  */
425 
426  /*!
427  * Only needed if data_store_backing(void) const
428  * has value data_store_ubo. Gives the size in
429  * blocks of PainterDraw::m_store which
430  * is PainterDraw::m_store.size().
431  */
432  int
433  data_blocks_per_store_buffer(void) const;
434 
435  /*!
436  * Set the value returned by data_blocks_per_store_buffer(void) const
437  * Default value is -1.
438  */
441 
442  /*!
443  * Specifies how the glyph data (GlyphAtlas::store())
444  * is accessed from the uber-shaders.
445  */
447  glyph_data_backing(void) const;
448 
449  /*!
450  * Set the value returned by glyph_data_backing(void) const.
451  * Default value is glyph_data_tbo.
452  */
455 
456  /*!
457  * Only used if glyph_data_backing(void) const has value
458  * glyph_data_texture_array. Gives the log2 of the
459  * width and height of the texture array backing the
460  * glyph data (GlyphAtlas::store()).
461  * Note: it must be that the width and height of the backing
462  * 2D texture array are powers of 2.
463  */
464  ivec2
465  glyph_data_backing_log2_dims(void) const;
466 
467  /*!
468  * Set the value returned by glyph_data_backing_log2_dims(void) const.
469  * Default value is (-1, -1).
470  */
473 
474  /*!
475  * Specifies how the bakcing store to the color stop atlas
476  * (ColorStopAtlas::backing_store()) is accessed from the
477  * uber-shaders.
478  */
480  colorstop_atlas_backing(void) const;
481 
482  /*!
483  * Set the value returned by colorstop_atlas_backing(void) const.
484  * Default value is colorstop_texture_1d_array.
485  */
488 
489  /*!
490  * If true, use a UBO to back the uniforms of the
491  * uber-shader. If false, use an array of uniforms
492  * instead. The name of the UBO block is
493  * fastuidraw_uniforms and the name of the
494  * uniform is fastuidraw_uniforms. In both cases,
495  * the buffer can be filled by the function
496  * PainterShaderRegistrarGLSL::fill_uniform_buffer().
497  * For the non-UBO case, the uniforms are realized
498  * as an array of floats in GLSL.
499  */
500  bool
501  use_ubo_for_uniforms(void) const;
502 
503  /*!
504  * Set the value returned by use_ubo_for_uniforms(void) const.
505  * Default value is true.
506  */
508  use_ubo_for_uniforms(bool);
509 
510  /*!
511  * If the PainterShaderRegistrarGLSL has bindless texturing enabled,
512  * (see supports_bindless_texturing()) then have that the
513  * handles to create sampler2D object is a uvec2. If false,
514  * use uint64_t as the handle type in the GLSL source code.
515  * Default value is true.
516  */
517  bool
518  use_uvec2_for_bindless_handle(void) const;
519 
520  /*!
521  * Set the value returned by use_uvec2_for_bindless_handle(void) const.
522  * Default value is true.
523  */
526 
527  /*!
528  * Returns the number of external textures (realized as
529  * sampler2D uniforms) the uber-shader is to have.
530  */
531  unsigned int
532  number_context_textures(void) const;
533 
534  /*!
535  * Set the value returned by number_context_textures(void) const.
536  * Default value is 1.
537  */
539  number_context_textures(unsigned int);
540 
541  /*!
542  * If true, use the GLSL built-in unpackHalf2x16(), otherwise
543  * use an implementation based off of bit-twiddling.
544  */
545  bool
546  use_glsl_unpack_fp16(void) const;
547 
548  /*!
549  * Set the value returned by use_glsl_unpack_fp16(void) const.
550  * Default value is true.
551  */
553  use_glsl_unpack_fp16(bool);
554 
555  /*!
556  * If true add shader code that gives default precision qualifiers
557  * to the types used by the produced shaders. This is required for
558  * shaders to be fed to GLES3 and WebGL2.
559  */
560  bool
562 
563  /*!
564  * Set the value returned by add_default_precision_qualifiers(void) const.
565  * Default value is false.
566  */
569 
570  /*!
571  * Returns the binding point for ColorStopAtlas::backing_store()
572  * derived from the current value of this UberShaderParams.
573  * The data type for the uniform is decided from the value
574  * colorstop_atlas_backing():
575  * - sampler1DArray if value is colorstop_texture_1d_array
576  * - sampler2DArray if value is colorstop_texture_2d_array
577  */
578  int
579  colorstop_atlas_binding(void) const;
580 
581  /*!
582  * Returns the binding point for the sampler2DArray
583  * derived from the current value of this UberShaderParams
584  * with nearest filtering backed by ImageAtlas::color_store().
585  */
586  int
588 
589  /*!
590  * Returns the binding point for the sampler2DArray
591  * derived from the current value of this UberShaderParams
592  * with linear filtering backed by ImageAtlas::color_store().
593  */
594  int
596 
597  /*!
598  * Returns the binding point for the usampler2DArray
599  * derived from the current value of this UberShaderParams
600  * backed by ImageAtlas::index_store().
601  */
602  int
604 
605  /*!
606  * Returns the binding point for the \ref GlyphAtlas
607  * derived from the current value of this UberShaderParams.
608  */
609  int
610  glyph_atlas_store_binding(void) const;
611 
612  /*!
613  * Returns the binding point of the data store buffer
614  * derived from the current value of this UberShaderParams.
615  */
616  int
617  data_store_buffer_binding(void) const;
618 
619  /*!
620  * Returns the binding point of the first external texture
621  * in their binding points; subsequence external textures
622  * immediately follow the 1st.
623  * derived from the current value of this UberShaderParams.
624  */
625  int
626  context_texture_binding(void) const;
627 
628  /*!
629  * Returns the binding point of the named external texture
630  * derived from the current value of this UberShaderParams.
631  */
632  int
633  context_texture_binding(unsigned int v) const
634  {
636  return context_texture_binding() + v;
637  }
638 
639  /*!
640  * Returns the binding point of the deferred coverage
641  * buffer (ala PainterSurface::deferred_coverage_buffer_type)
642  * for reading.
643  */
644  int
646 
647  /*!
648  * Specifies the binding point for the image2D (rgba8)
649  * color buffer; derived from the current value only
650  * active of this UberShaderParams; A return value of
651  * -1 indicates that the color buffer does not use any
652  * binding point.
653  */
654  int
656 
657  /*!
658  * Returns the binding point of the UBO for uniforms
659  * derived from the current value of this UberShaderParams.
660  * A return value of -1 indicates that the uniforms
661  * does not use any binding points.
662  */
663  int
664  uniforms_ubo_binding(void) const;
665 
666  /*!
667  * Returns the number of UBO binding units used derived
668  * from the current values of this UberShaderParams; the
669  * units used are 0, 1, ..., num_ubo_units() - 1.
670  */
671  unsigned int
672  num_ubo_units(void) const;
673 
674  /*!
675  * Returns the number of SSBO binding units used derived
676  * from the current values of this UberShaderParams; the
677  * units used are 0, 1, ..., num_ssbo_units() - 1.
678  */
679  unsigned int
680  num_ssbo_units(void) const;
681 
682  /*!
683  * Returns the number of texture binding units used derived
684  * from the current values of this UberShaderParams; the
685  * units used are 0, 1, ..., num_texture_units() - 1.
686  */
687  unsigned int
688  num_texture_units(void) const;
689 
690  /*!
691  * Returns the number of image binding units used derived
692  * from the current values of this UberShaderParams; the
693  * units used are 0, 1, ..., num_image_units() - 1.
694  */
695  unsigned int
696  num_image_units(void) const;
697 
698  /*!
699  * Returns a PainterShaderSet derived from the current values
700  * of this UberShaderParams.
701  */
703  default_shaders(void) const;
704 
705  private:
706  void *m_d;
707  };
708 
709  /*!
710  * A BackendConstants stores constants coming from a backend
711  * implementation that change the GLSL uber-shaders made by
712  * PainterShaderRegisterGLSL::construct_shader().
713  */
715  {
716  public:
717  /*!
718  * Ctor.
719  * \param p if non-null, set all values from the passed \ref
720  * PainterEngine object,
721  * otherwise set all values as 0.
722  */
723  BackendConstants(PainterEngine *p = nullptr);
724 
725  /*!
726  * Copy ctor.
727  * \param obj value from which to copy
728  */
730 
731  ~BackendConstants();
732 
733  /*!
734  * Assignment operator
735  * \param rhs value from which to copy
736  */
738  operator=(const BackendConstants &rhs);
739 
740  /*!
741  * Swap operation
742  * \param obj object with which to swap
743  */
744  void
745  swap(BackendConstants &obj);
746 
747  /*!
748  * Should be the same value as AtlasColorBackingStoreBase::dimensions() .x()
749  * of ImageAtlas::color_store(). A value of zero indicates that sourcing
750  * from an \ref Image with \ref Image::type() having value \ref Image::on_atlas
751  * is not supported (i.e. there is no image-atlasing).
752  */
753  int
754  image_atlas_color_store_width(void) const;
755 
756  /*!
757  * Set the value returned by image_atlas_color_store_width(void) const.
758  */
760  image_atlas_color_store_width(int);
761 
762  /*!
763  * Should be the same value as AtlasColorBackingStoreBase::dimensions() .y()
764  * of ImageAtlas::color_store(). A value of zero indicates that sourcing
765  * from an \ref Image with \ref Image::type() having value \ref Image::on_atlas
766  * is not supported (i.e. there is no image-atlasing).
767  */
768  int
769  image_atlas_color_store_height(void) const;
770 
771  /*!
772  * Set the value returned by image_atlas_color_store_height(void) const.
773  */
775  image_atlas_color_store_height(int);
776 
777  /*!
778  * Should be the same as ImageAtlas::index_tile_size() and must be a power
779  * of 2. A value of zero indicates that sourcing from an \ref Image with
780  * \ref Image::type() having value \ref Image::on_atlas is not supported
781  * (i.e. there is no image-atlasing).
782  */
783  int
784  image_atlas_index_tile_size(void) const;
785 
786  /*!
787  * Set the value returned by image_atlas_index_tile_size(void) const.
788  */
790  image_atlas_index_tile_size(int);
791 
792  /*!
793  * Should be the same as ImageAtlas::color_tile_size() and must be a power
794  * of 2. A value of zero indicates that sourcing from an \ref Image with
795  * \ref Image::type() having value \ref Image::on_atlas is not supported
796  * (i.e. there is no image-atlasing).
797  */
798  int
799  image_atlas_color_tile_size(void) const;
800 
801  /*!
802  * Set the value returned by image_atlas_color_tile_size(void) const.
803  */
805  image_atlas_color_tile_size(int);
806 
807  /*!
808  * Should be the same value as ColorStopBackingStore::dimensions().x()
809  * of ColorStopAtlas::backing_store()
810  */
811  int
812  colorstop_atlas_store_width(void) const;
813 
814  /*!
815  * Set the value returned by color_atlas_store_width(void) const.
816  */
818  colorstop_atlas_store_width(int);
819 
820  /*!
821  * Set all values of this BackendConstant by taking values
822  * from a \ref PainterEngine.
823  */
825  set_from_backend(PainterEngine *p);
826 
827  /*!
828  * Set all values of this BackendConstant by taking values
829  * from a PainterBackend.
830  */
832  set_from_atlas(ImageAtlas &p);
833 
834  /*!
835  * Set all values of this BackendConstant by taking values
836  * from a PainterBackend.
837  */
839  set_from_atlas(ColorStopAtlas &p);
840 
841  private:
842  void *m_d;
843  };
844 
845  /*!
846  * \brief
847  * An ShaderFilter is used to specify whether or not
848  * to include a named shader when creating an uber-shader.
849  * \tparam ShaderType should be \ref PainterItemShaderGLSL
850  * or \ref PainterItemCoverageShaderGLSL
851  */
852  template<typename ShaderType>
854  {
855  public:
856  virtual
857  ~ShaderFilter(void)
858  {}
859 
860  /*!
861  * To be implemented by a derived class to return true
862  * if the named shader should be included in the uber-shader.
863  */
864  virtual
865  bool
866  use_shader(const reference_counted_ptr<ShaderType> &shader) const = 0;
867  };
868  };
869 
870  /*!
871  * \brief
872  * A PainterShaderRegistrarGLSL is an implementation of PainterRegistrar
873  * that assembles the shader source code of PainterItemShaderGLSL
874  * and PainterBlendShaderGLSL into an uber-shader.
875  */
877  public PainterShaderRegistrar,
879  {
880  public:
881 
882  /*!
883  * Ctor.
884  */
885  explicit
887 
889 
890  /*!
891  * Add GLSL code that is to be visible to all vertex
892  * shaders. The code can define functions or macros.
893  * \param src shader source to add
894  */
895  void
896  add_vertex_shader_util(const ShaderSource &src);
897 
898  /*!
899  * Add GLSL code that is to be visible to all vertex
900  * shaders. The code can define functions or macros.
901  * \param src shader source to add
902  */
903  void
904  add_fragment_shader_util(const ShaderSource &src);
905 
906  /*!
907  * Add the uber-vertex and fragment shaders to given ShaderSource values.
908  * The \ref Mutex mutex() is NOT locked during this call, a caller should
909  * lock the mutex before calling it. This way a derived class can use the
910  * same lock as used by the PainterShaderRegistrarGLSL. A backend will
911  * need to define the the functions (or macros) in their
912  * GLSL preamble:
913  * - fastuidraw_begin_interlock() which is called before access
914  * - fastuidraw_end_interlock() which is called after access
915  * if UberShaderParams::ffb_blending_type() is \ref fbf_blending_interlock.
916  * \param tp blend type of \ref PainterBlendShader objects to include in the uber-shader
917  * \param backend_constants constant values that affect the created uber-shader.
918  * \param out_vertex ShaderSource to which to add uber-vertex shader
919  * \param out_fragment ShaderSource to which to add uber-fragment shader
920  * \param construct_params specifies how to construct the uber-shaders.
921  * \param item_shader_filter pointer to \ref PainterShaderRegistrarGLSLTypes::ShaderFilter
922  * to use to filter which shaders to place into the uber-shader.
923  * A value of nullptr indicates to add all item shaders to the
924  * uber-shader.
925  * \param discard_macro_value macro-value definintion for the macro
926  * FASTUIDRAW_DISCARD. PainterItemShaderGLSL
927  * fragment sources use FASTUIDRAW_DISCARD
928  * instead of discard.
929  */
930  void
931  construct_item_uber_shader(enum PainterBlendShader::shader_type tp,
932  const BackendConstants &backend_constants,
933  ShaderSource &out_vertex,
934  ShaderSource &out_fragment,
935  const UberShaderParams &construct_params,
936  const ShaderFilter<PainterItemShaderGLSL> *item_shader_filter = nullptr,
937  c_string discard_macro_value = "discard");
938 
939  /*!
940  * Add the uber-vertex and fragment shaders to given ShaderSource values.
941  * The \ref Mutex mutex() is NOT locked during this call, a caller should
942  * lock the mutex before calling it. This way a derived class can use the
943  * same lock as used by the PainterShaderRegistrarGLSL.
944  * \param backend_constants constant values that affect the created uber-shader.
945  * \param out_vertex ShaderSource to which to add uber-vertex shader
946  * \param out_fragment ShaderSource to which to add uber-fragment shader
947  * \param construct_params specifies how to construct the uber-shaders.
948  * \param item_shader_filter pointer to \ref PainterShaderRegistrarGLSLTypes::ShaderFilter
949  * to use to filter which shaders to place into the uber-shader.
950  * A value of nullptr indicates to add all item coverage shaders
951  * to the uber-shader.
952  */
953  void
954  construct_item_uber_coverage_shader(const BackendConstants &backend_constants,
955  ShaderSource &out_vertex,
956  ShaderSource &out_fragment,
957  const UberShaderParams &construct_params,
958  const ShaderFilter<PainterItemCoverageShaderGLSL> *item_shader_filter = nullptr);
959 
960  /*!
961  * Add the vertex and fragment shaders of a specific item shader to given
962  * ShaderSource values. The \ref Mutex mutex() is NOT locked during this call,
963  * a caller should lock the mutex before calling it. This way a derived class
964  * can use the same lock as used by the PainterShaderRegistrarGLSL.
965  * \param tp blend type of \ref PainterBlendShader objects to include in the uber-shader
966  * \param backend_constants constant values that affect the created uber-shader.
967  * \param out_vertex ShaderSource to which to add uber-vertex shader
968  * \param out_fragment ShaderSource to which to add uber-fragment shader
969  * \param construct_params specifies how to construct the uber-shaders.
970  * \param shader_id item shader ID, i.e. PainterItemShader::ID().
971  * \param discard_macro_value macro-value definintion for the macro
972  * FASTUIDRAW_DISCARD. PainterItemShaderGLSL
973  * fragment sources use FASTUIDRAW_DISCARD
974  * instead of discard.
975  */
976  void
977  construct_item_shader(enum PainterBlendShader::shader_type tp,
978  const BackendConstants &backend_constants,
979  ShaderSource &out_vertex,
980  ShaderSource &out_fragment,
981  const UberShaderParams &construct_params,
982  unsigned int shader_id,
983  c_string discard_macro_value = "discard");
984 
985  /*!
986  * Add the vertex and fragment shaders of a specific item shader to given
987  * ShaderSource values. The \ref Mutex mutex() is NOT locked during this call,
988  * a caller should lock the mutex before calling it. This way a derived class
989  * can use the same lock as used by the PainterShaderRegistrarGLSL.
990  * \param backend_constants constant values that affect the created uber-shader.
991  * \param out_vertex ShaderSource to which to add uber-vertex shader
992  * \param out_fragment ShaderSource to which to add uber-fragment shader
993  * \param construct_params specifies how to construct the uber-shaders.
994  * \param shader_id item shader ID, i.e. PainterItemShader::ID().
995  */
996  void
997  construct_item_coverage_shader(const BackendConstants &backend_constants,
998  ShaderSource &out_vertex,
999  ShaderSource &out_fragment,
1000  const UberShaderParams &construct_params,
1001  unsigned int shader_id);
1002 
1003  /*!
1004  * Returns the total number of shaders (item and blend)
1005  * registered to this PainterShaderRegistrarGLSL; a derived class
1006  * should track this count value and use it to determine
1007  * when it needs to reconstruct its uber-shader. The mutex()
1008  * is NOT locked for the duration of the function.
1009  */
1010  unsigned int
1011  registered_shader_count(void);
1012 
1013  /*!
1014  * Returns the number of blend shaders registered to this
1015  * PainterShaderRegistrarGLSL; a derived class
1016  * should track this count value and use it to determine
1017  * when it needs to reconstruct its shaders. The mutex()
1018  * is NOT locked for the duration of the function.
1019  */
1020  unsigned int
1021  registered_blend_shader_count(enum PainterBlendShader::shader_type tp);
1022 
1023  /*!
1024  * Fill a buffer to hold the values used by the uber-shader.
1025  * The buffer must be that p.size() is atleast ubo_size().
1026  * \param vwp current PainterSurface::Viewport to which is being rendered
1027  * \param p buffer to which to fill uniform data
1028  */
1029  void
1030  fill_uniform_buffer(const PainterSurface::Viewport &vwp,
1031  c_array<uint32_t> p);
1032 
1033  /*!
1034  * Total size of UBO for uniforms in units of
1035  * uint32_t, see also fill_uniform_ubo().
1036  */
1037  static
1038  uint32_t
1039  ubo_size(void);
1040 
1041  protected:
1042 
1043  /*!
1044  * To be optionally implemented by a derived class to
1045  * compute the shader group of a PainterItemShader.
1046  * The passed shader may or may not be a sub-shader.
1047  * The mutex() is locked for the duration of the function.
1048  * Default implementation is to return 0.
1049  * \param tag The value of PainterShader::tag() that PainterShaderRegistrarGLSL
1050  * will assign to the shader. Do NOT access PainterShader::tag(),
1051  * PainterShader::ID() or PainterShader::group() as they are
1052  * not yet assgined.
1053  * \param shader shader whose group is to be computed
1054  */
1055  virtual
1056  uint32_t
1057  compute_item_shader_group(PainterShader::Tag tag,
1059 
1060  /*!
1061  * To be optionally implemented by a derived class to
1062  * compute the shader group of a PainterItemCoverageShader.
1063  * The passed shader may or may not be a sub-shader.
1064  * The mutex() is locked for the duration of the function.
1065  * Default implementation is to return 0.
1066  * \param tag The value of PainterShader::tag() that PainterShaderRegistrarGLSL
1067  * will assign to the shader. Do NOT access PainterShader::tag(),
1068  * PainterShader::ID() or PainterShader::group() as they are
1069  * not yet assgined.
1070  * \param shader shader whose group is to be computed
1071  */
1072  virtual
1073  uint32_t
1074  compute_item_coverage_shader_group(PainterShader::Tag tag,
1076 
1077  /*!
1078  * To be optionally implemented by a derived class to
1079  * compute the shader group of a PainterBlendShader.
1080  * The passed shader may or may not be a sub-shader.
1081  * The mutex() is locked for the duration of the function.
1082  * Default implementation is to return 0.
1083  * \param tag The value of PainterShader::tag() that PainterShaderRegistrarGLSL
1084  * will assign to the shader. Do NOT access PainterShader::tag(),
1085  * PainterShader::ID() or PainterShader::group() as they are
1086  * not yet assgined.
1087  * \param shader shader whose group is to be computed
1088  */
1089  virtual
1090  uint32_t
1091  compute_blend_shader_group(PainterShader::Tag tag,
1093 
1094  /*!
1095  * To be optionally implemented by a derived class to
1096  * compute the shader group of a PainterBrushShader.
1097  * The passed shader may or may not be a sub-shader.
1098  * The mutex() is locked for the duration of the function.
1099  * Default implementation is to return 0.
1100  * \param tag The value of PainterShader::tag() that PainterShaderRegistrarGLSL
1101  * will assign to the shader. Do NOT access PainterShader::tag(),
1102  * PainterShader::ID() or PainterShader::group() as they are
1103  * not yet assgined.
1104  * \param shader shader whose group is to be computed
1105  */
1106  virtual
1107  uint32_t
1108  compute_custom_brush_shader_group(PainterShader::Tag tag,
1110 
1111  virtual
1113  absorb_item_shader(const reference_counted_ptr<PainterItemShader> &shader) final override;
1114 
1115  virtual
1116  uint32_t
1117  compute_item_sub_shader_group(const reference_counted_ptr<PainterItemShader> &shader) final override;
1118 
1119  virtual
1121  absorb_item_coverage_shader(const reference_counted_ptr<PainterItemCoverageShader> &shader) final override;
1122 
1123  virtual
1124  uint32_t
1125  compute_item_coverage_sub_shader_group(const reference_counted_ptr<PainterItemCoverageShader> &shader) final override;
1126 
1127  virtual
1129  absorb_blend_shader(const reference_counted_ptr<PainterBlendShader> &shader) final override;
1130 
1131  virtual
1132  uint32_t
1133  compute_blend_sub_shader_group(const reference_counted_ptr<PainterBlendShader> &shader) final override;
1134 
1135  virtual
1137  absorb_custom_brush_shader(const reference_counted_ptr<PainterBrushShader> &shader) final override;
1138 
1139  virtual
1140  uint32_t
1141  compute_custom_brush_sub_shader_group(const reference_counted_ptr<PainterBrushShader> &shader) final override;
1142 
1143  private:
1144  void *m_d;
1145  };
1146 
1147 /*! @} */
1148 
1149  }
1150 }
1151 
1152 #endif
An ShaderFilter is used to specify whether or not to include a named shader when creating an uber-sha...
enum PainterBlendShader::shader_type preferred_blend_type(void) const
A ShaderSource represents the source code to a GLSL shader, specifying blocks of source code and macr...
A PainterEngine provides an interface to create Painter Backend derived objects.
colorstop_backing_t
Enumeration to specify how to access the backing store of a color stop atlas store in ColorStopAtlas:...
file painter_surface.hpp
file painter_blend_shader_glsl.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
glyph_data_backing_t
Enumeration to specify how to access the backing store of the glyph data stored in GlyphAtlas::store(...
A wrapper over a pointer to implement reference counting.
file painter_engine.hpp
file shader_source.hpp
A ColorStopAtlas is a common location to all color stop data of an application. Ideally, all color stop sequences are placed into a single ColorStopAtlas (changes of ColorStopAtlas force draw-call breaks).
An UberShaderParams specifies how to construct an uber-shader. Note that the usage of HW clip-planes ...
A Tag is how a PainterShader is described for and by a PainterShaderRegistrar.
A PainterShaderRegistrar is an interface that defines the assigning of PainterShader::ID() to a Paint...
data_store_backing_t
Enumeration to specify how the data store filled by PainterDraw::m_store is realized.
A PainterShaderSet provides shaders for blending and drawing each of the item types glyphs...
enum z_coordinate_convention_t z_coordinate_convention(void) const
UberShaderParams & operator=(const UberShaderParams &rhs)
vertex_shader_in_layout
Enumeration to describe vertex shader input slot layout.
file painter_item_shader_glsl.hpp
An ImageAtlas is a common location to place images of an application.
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
fbf_blending_type_t
Enumeration to specify how to perform framebuffer-fetch blending.
file painter_shader_registrar.hpp
shader_type
Enumeration to specify how blend shader operates.
A PainterShaderRegistrarGLSL is an implementation of PainterRegistrar that assembles the shader sourc...
#define FASTUIDRAWassert(X)
Definition: util.hpp:99
z_coordinate_convention_t
Enumeration to specify the convention for a 3D API for its normalized device coordinate in z...