FastUIDraw
main.doxy
Go to the documentation of this file.
1 /*!
2  \file main.doxy
3  \brief main.doxy
4  */
5 
6 /*!
7 \defgroup Utility Utility
8 @{
9 \brief
10 Utility provides simple utility classes, the most important and
11 commonly used ones being \ref reference_counted_ptr, \ref vecN,
12 and \ref c_array. Part of the main library libFastUIDraw.
13 @}
14 
15 \defgroup Glyph Glyph
16 @{
17 \brief
18 \ref Glyph provides the interfaces to realizing glyph data for rendering
19 glyphs. The big classes being \ref Glyph, \ref GlyphCache, \ref
20 GlyphAtlas and \ref FontBase. Part of the main library libFastUIDraw.
21 @}
22 
23 \defgroup Paths Paths
24 @{
25 \brief
26 Path provides the interface to realize paths, the main entry point
27 for applications is the object \ref Path.
28 @}
29 
30 \defgroup Imaging Imaging
31 @{
32 \brief
33 Imaging provides the interface to realize images
34 and color gradients.
35 @}
36 
37 \defgroup GLSL GLSL
38 @{
39 \brief
40 Utility module to assist in creating GLSL shaders and also provides
41 \ref fastuidraw::glsl::PainterShaderRegistrarGLSL which provides
42 shader assembly and default shaders via GLSL shaders. The GL backend
43 via the class \ref fastuidraw::gl::PainterEngineGL builds off of
44 \ref fastuidraw::glsl::PainterShaderRegistrarGLSL in that its
45 \ref fastuidraw::PainterEngine::painter_shader_registrar() method
46 returns an object derived from \ref fastuidraw::glsl::PainterShaderRegistrarGLSL.
47 Part of the main library libFastUIDraw.
48 @}
49 
50 \defgroup GLSLVertFragCode GLSL Vertex Fragment Code
51 @{
52 \brief
53 This group documents the GLSL functions fastuidraw makes available
54 to GLSL code fragments for both vertex and fragment shading for
55 custom shading as embodied by the classes \ref
56 fastuidraw::glsl::PainterItemShaderGLSL, \ref
57 fastuidraw::glsl::PainterBlendShaderGLSL and \ref
58 fastuidraw::glsl::PainterBrushShaderGLSL.
59 @}
60 
61 \defgroup GLSLVertCode GLSL Vertex Code
62 @{
63 \brief
64 This group documents the GLSL functions fastuidraw makes available
65 to GLSL code fragments for only vertex shading for custom shading
66 as embodied by the classes \ref fastuidraw::glsl::PainterItemShaderGLSL,
67 \ref fastuidraw::glsl::PainterBlendShaderGLSL and \ref
68 fastuidraw::glsl::PainterBrushShaderGLSL.
69 @}
70 
71 \defgroup GLSLFragCode GLSL Fragment Code
72 @{
73 \brief
74 This group documents the GLSL functions fastuidraw makes available
75 to GLSL code fragments for only fragment shader for custom shading
76 as embodied by the classes \ref fastuidraw::glsl::PainterItemShaderGLSL,
77 \ref fastuidraw::glsl::PainterBlendShaderGLSL and \ref
78 fastuidraw::glsl::PainterBrushShaderGLSL.
79 @}
80 
81 \defgroup GLSLBuiltInShaders GLSL Built in Shaders
82 @{
83 \brief
84 This group documents the symbols and varyings of the built in shaders
85 provided by the GLSL module (which is used by both the GL and GLES
86 backends.
87 
88 The following symbols are available as keyed by the values within
89 a \ref fastuidraw::PainterShaderSet.
90 
91 For \ref fastuidraw::PainterShaderSet::stroke_shader() and each \ref
92 fastuidraw::PainterStrokeShader of \ref fastuidraw::PainterShaderSet::dashed_stroke_shader(),
93 there is the following. For the vertex shaders there are the public symbols:
94 - fastuidraw_stroking_distance gives the distance from the start of the contour along the path
95 - fastuidraw_stroking_contour_length gives the length of the contour
96 - fastuidraw_stroking_edge_length gives the length of the edge
97 - fastuidraw_stroking_edge_start gives how far along the path the start of the edge is
98 The non anti-aliased shaders (i.e. \ref fastuidraw::PainterStrokeShader::non_aa_shader),
99 have the following symbols in the fragment shader exposed:
100 - fastuidraw_stroking_distance the distance from the start of the contour along the path
101 - fastuidraw_stroking_distance_fwidth fwidth of fastuidraw_stroking_distance. Use this value to
102  perform anti-aliasing coverage computations
103 - fastuidraw_stroking_relative_distance_from_center this value is 0.0 on the path and grows to 1.0
104  at the stroking boundary
105 - fastuidraw_stroking_distance_fwidth fwidth of fastuidraw_stroking_relative_distance_from_center.
106  Use this value to perform anti-aliasing coverage computations
107 The anti-aliasing shaders (i.e. \ref fastuidraw::PainterStrokeShader::aa_shader) are two pass
108 shaders where the coverage shader (i.e. \ref fastuidraw::PainterItemShader::coverage_shader()) has
109 the above symbols in fragment shader (and also the vertex symbols in the vertex shader), but the
110 item shader only has the vertex shader symbols but not the fragment shader symbols.
111 
112 Each shader present in \ref fastuidraw::PainterShaderSet::brush_shaders() has the two varyings:
113 - fastuidraw_brush_p_x which gives the x-coordinate of the brush
114 - fastuidraw_brush_p_y which gives the y-coordinate of the brush
115 The \ref fastuidraw::PainterGradientBrushShader::linear_sub_shader() has the varyings:
116 - fastuidraw_brush_gradient_p0_x the x-coordinate of the start position of the linear gradient
117 - fastuidraw_brush_gradient_p0_y the y-coordinate of the start position of the linear gradient
118 - fastuidraw_brush_gradient_p1_x the x-coordinate of the end position of the linear gradient
119 - fastuidraw_brush_gradient_p1_y the y-coordinate of the end position of the linear gradient
120 The \ref fastuidraw::PainterGradientBrushShader::radial_sub_shader() has the varyings:
121 - fastuidraw_brush_gradient_p0_x the x-coordinate of the start position of the radial gradient
122 - fastuidraw_brush_gradient_p0_y the y-coordinate of the start position of the radial gradient
123 - fastuidraw_brush_gradient_r0 the start radius of the radial gradient
124 - fastuidraw_brush_gradient_p1_x the x-coordinate of the end position of the radial gradient
125 - fastuidraw_brush_gradient_p1_y the y-coordinate of the end position of the radial gradient
126 - fastuidraw_brush_gradient_r1 the end radius of the radial gradient
127 The \ref fastuidraw::PainterGradientBrushShader::sweep_sub_shader() has the varyings:
128 - fastuidraw_brush_gradient_sweep_point_x the x-coordinate of the sweep point
129 - fastuidraw_brush_gradient_sweep_point_y the y-coordinate of the sweep point
130 - fastuidraw_brush_gradient_sweep_angle the start angle of the sweep gradient
131 - fastuidraw_brush_gradient_sweep_sign_factor the signed multiplier of the sweep gradient.
132 The \ref fastuidraw::PainterGradientBrushShader::sub_shader() has all of the above varyings
133 (since it encompasses all of the gradients) either directly or realized as aliases.
134 
135 The standard brush, \ref fastuidraw::PainterBrushShaderSet::standard_brush(), is itself
136 realized as a chain shader with the image of the brush accessible via its dependee named
137 image_brush, and the gradient via the dependee name gradient_brush.
138 
139 
140 @}
141 
142 \defgroup Painter Painter
143 @{
144 \brief
145 Painter provides the interface for Canvas drawing, the most important class
146 being Painter. Part of the main library libFastUIDraw.
147 @}
148 
149 \defgroup PainterAttribute Painter Attribute
150 @{
151 \brief
152 Painter Attribute provides the interface to define the attribute data
153 to be used by shaders. This includes how glyphs, stroked paths and filled
154 paths are realized as attribute data.
155 
156 The class \ref fastuidraw::PainterAttribute represents a single attribute
157 (the what to draw). FastUIDraw works -exclusively- in drawing triangles
158 and the indices of the what to draw are realized as \ref fastuidraw::PainterIndex.
159 The class \ref fastuidraw::PainterAttributeData represents a collection
160 of attribute and indices to draw.
161 
162 If the attribute and/or index data needs to be dynamic (but the CPU cost
163 should be low), the class \ref fastuidraw::PainterAttributeWriter
164 can be used. One example of its use is \ref fastuidraw::GlyphRun which
165 uses it to select what sub-range of indices to feed to draw only a portion
166 of text.
167 @}
168 
169 \defgroup PainterShaders Painter Shaders
170 @{
171 \brief
172 \ref PainterShaders defines the interface how to specify shaders used by
173 \ref Painter to render items.
174 
175 There are four types of shaders
176 - \ref fastuidraw::PainterItemShader represents the shader code to
177  perform vertex and fragment processing on an item.
178 - \ref fastuidraw::PainterBrush and \ref fastuidraw::PainterCustomBrush
179  represent the shader code to compute the color that that brush
180  applies
181 - \ref fastuidraw::PainterBlendShader represents the shader code to
182  perform blending.
183 - \ref fastuidraw::PainterItemCoverageShader is an auxiliary shader
184  that can be used by a \ref fastuidraw::PainterItemShader to compute
185  a coverage value for the purpose of two-pass rendering.
186 
187 Each of these shaders can fetch shader-data to modify their processing
188 (for example an item shader for stroking a path would fetch the stroking
189 width in the vertex shader). The classes for realizing the shader-data
190 are
191 - \ref fastuidraw::PainterItemShaderData for both \ref fastuidraw::PainterItemShader
192  and \ref fastuidraw::PainterItemCoverageShader
193 - \ref fastuidraw::PainterBlendShaderData for \ref fastuidraw::PainterBlendShader
194 - \ref fastuidraw::PainterBrush for the built-in brush of FastUIDraw
195 - \ref fastuidraw::PainterBrushShaderData for \ref fastuidraw::PainterBrushShader
196  for custom brushes
197 
198 Each of these objects can be passed to a \ref fastuidraw::Painter drawing method
199 by address with the class \ref fastuidraw::PainterData. In addition, if a value
200 is to be reused in several drawing calls to \ref fastuidraw::Painter, one can use
201 the interface of \ref fastuidraw::PainterPackedValuePool (fetched from \ref
202 fastuidraw::Painter::packed_value_pool()) to realize a \ref fastuidraw::PainterPackedValue
203 which represents the value immutably packed for the GPU in such a way that its packing
204 into the GPU can be dramatically reused within a frame.
205 @}
206 
207 \defgroup PainterShaderData Painter Shader Data
208 @{
209 \brief
210 \ref PainterShaderData defines the interface for providing
211 to shaders a small amount of data that is constant across
212 all vertices and pixels of a drawn item.
213 
214 Each of the data classes is paired with a shader classes:
215 - \ref fastuidraw::PainterItemShaderData for both \ref fastuidraw::PainterItemShader
216  and \ref fastuidraw::PainterItemCoverageShader
217 - \ref fastuidraw::PainterBlendShaderData for \ref fastuidraw::PainterBlendShader
218 - \ref fastuidraw::PainterBrush for the built-in brush of FastUIDraw
219 - \ref fastuidraw::PainterBrushShaderData for \ref fastuidraw::PainterBrushShader
220  for custom brushes
221 
222 The data is passed to \ref fastuidraw::Painter methods through the class
223 \ref fastuidraw::PainterData. Shader data can also be pre-packed by a
224 caller for reuse through the immutable class \ref fastuidraw::PainterPackedValue.
225 Using \ref fastuidraw::PainterPackedValue for when the same shader data values
226 are used is a big win because that class provides the means for
227 FastUIDraw to upload that shader data far fewer times (usually once for
228 an entire frame instead once per use).
229 
230 @}
231 
232 \defgroup PainterBackend Painter Backend
233 @{
234 \brief
235 If one is making a painter backend, then this group provides the
236 information, see particularly the enumerations in fastuidraw::PainterHeader,
237 fastuidraw::PainterItemMatrix, fastuidraw::PainterClipEquations
238 for how data is packed by fastuidraw::Painter. Part of the main library
239 libFastUIDraw.
240 
241 \section Overview
242 The class fastuidraw::Painter implements canvas rendering using an implementation
243 of the backend interface fastuidraw::PainterBackend to send data to a 3D API.
244 The class fastuidraw::Painter packs data that is used by multiple triangles
245 into fastuidraw::PainterDrawCommand::m_store (for example the current transformation).
246 In implementing a backend, the shader fed to the GPU needs to correctly unpack
247 this data. The location of the header of the data is stored in the attribute
248 from the value fastuidraw::PainterDrawCommand::m_header_attributes. The header
249 consists of fastuidraw::PainterHeader::header_size uint32_t values whose location
250 relative to the start of the header and meaning are enumerated by
251 fastuidraw::PainterHeader::offset_t. The header contains shader ID's
252 and additional offsets to more data packed for a shader to unpack.
253 
254 @}
255 
256 \defgroup GLBackend GL Backend
257 @{
258 \brief
259 Implementation of a backend using the OpenGL (or OpenGL ES) GPU API.
260 @}
261 
262 \defgroup GLUtility GL Utility
263 @{
264 \brief
265 Collection of utility interfaces used by \ref GLBackend that an application
266 may wish to use as well.
267 @}
268 */
269 
270 /*!
271  \brief all classes and functions of FastUIDraw are in the
272  namespace fastuidraw.
273  */
274 namespace fastuidraw {
275 
276 /*!\addtogroup GLSL
277  @{
278  */
279  /*!
280  \brief Namespace to encapsulate shader building to GLSL
281  shaders, part of the main library libFastUIDraw.
282  */
283  namespace glsl
284  {
285  }
286 /*! @} */
287 
288  /*!
289  \brief Namespace to encapsulate GL backend end implementation,
290  utility functions and utility classes. Part of the GL
291  backend libraries, libFastUIDrawGL and libFastUIDrawGLES.
292  */
293  namespace gl
294  {
295 
296 /*!\addtogroup GLUtility
297  @{
298  */
299  /*!
300  \brief Template version for setting an of uniform values
301  \param location location of uniform, i.e. return value
302  of glGetUniformLocation
303  \param v array of values
304  \param count number of elements from the array v to use.
305  */
306  template<typename T>
307  void
308  Uniform(int location, GLsizei count, const T *v);
309 
310  /*!
311  \brief Template version for setting an array of matrix uniform values.
312  \param location location of uniform, i.e. return value
313  of glGetUniformLocation
314  \param v value
315  \param count number of elements from the array v to use.
316  \param transposed set to tue true if GL should interpret the matrices as transposed
317  */
318  template<typename T, size_t N, size_t M>
319  void
320  Uniform(int location, GLsizei count, const matrixNxM<T, N, M> *v, bool transposed = false);
321 
322  /*!
323  \brief Template version for setting a single uniform value.
324  \param location location of uniform, i.e. return value
325  of glGetUniformLocation
326  \param v value
327  */
328  template<typename T, size_t N>
329  void
330  Uniform(int location, const vecN<T, N> &v);
331 
332  /*!
333  \brief Template version for setting a single matrix uniform value.
334  \param location location of uniform, i.e. return value
335  of glGetUniformLocation
336  \param v value
337  \param transposed set to tue true if GL should interpret the matrices as transposed
338  */
339  template<typename T, size_t N, size_t M>
340  void
341  Uniform(int location, const matrixNxM<T, N, M> &v, bool transposed = false);
342 
343  /*!
344  \brief Template version for setting an of uniform values
345  \param program GL name of program to which uniform(s) belong
346  \param location location of uniform, i.e. return value
347  of glGetUniformLocation
348  \param v array of values
349  \param count number of elements from the array v to use.
350  */
351  template<typename T>
352  void
353  ProgramUniform(GLuint program, int location, GLsizei count, const T *v);
354 
355  /*!
356  \brief Template version for setting an array of matrix uniform values.
357  \param program GL name of program to which uniform(s) belong
358  \param location location of uniform, i.e. return value
359  of glGetUniformLocation
360  \param v value
361  \param count number of elements from the array v to use.
362  \param transposed set to tue true if GL should interpret the matrices as transposed
363  */
364  template<typename T, size_t N, size_t M>
365  void
366  ProgramUniform(GLuint program, int location, GLsizei count, const matrixNxM<T, N, M> *v, bool transposed = false);
367 
368  /*!
369  \brief Template version for setting a single uniform value.
370  \param program GL name of program to which uniform(s) belong
371  \param location location of uniform, i.e. return value
372  of glGetUniformLocation
373  \param v value
374  */
375  template<typename T, size_t N>
376  void
377  ProgramUniform(GLuint program, int location, const vecN<T, N> &v);
378 
379  /*!
380  \brief Template version for setting a single matrix uniform value.
381  \param program GL name of program to which uniform(s) belong
382  \param location location of uniform, i.e. return value
383  of glGetUniformLocation
384  \param v value
385  \param transposed set to tue true if GL should interpret the matrices as transposed
386  */
387  template<typename T, size_t N, size_t M>
388  void
389  ProgramUniform(GLuint program, int location, const matrixNxM<T, N, M> &v, bool transposed = false);
390 
391  /*! @} */
392  }
393 }
394 
395 /*! \mainpage FastUIDraw
396 
397  \section Purpose
398 
399  FastUIDraw is a library that provides a higher performance Canvas interface.
400  It is designed so that it always draws using a GPU.
401 
402  In contrast to many common implementations of Canvas drawing, FastUIDraw
403  has that changes in clipping are very cheap and optimized for GPU's. In
404  addition, FastUIDraw has, with the GL backend, very few pipeline states.
405  Indeed an API trace of an application using FastUIDraw will see only a
406  handful of draw calls per frame, even under high Canvas state trashing,
407  and high clip state changes. Indeed, for the GL backend, only one Canvas
408  state change invokes a pipeline state change: changing the blend mode.
409 
410  The class to execute drawing is \ref fastuidraw::Painter which supplies
411  the expected standard drawing features: stroking and filling paths,
412  drawing text, applying a brush (image and/or gradient), blending (including
413  all Porter-Duff modes), a 3x3 transformation allowing for perspective
414  drawing, clipping in by a rectangle or filled path and clipping out by
415  a filled path.
416 
417  In addition, FastUIDraw gives an application the ability to make their
418  own shaders for custom drawing.
419 
420  \section Drawing Concepts
421 
422  If one needs to create its own custom way of drawing, one needs
423  to know the drawing concepts in FastUIDraw. There are three distinct
424  ingredients of drawing in FastUIDraw:
425  - Attribute and index data processed by the GPU. This data should be
426  immutable to be created/calculated once and reused greatly.
427  At the very bottom of this stack is \ref fastuidraw::PainterIndex
428  to represent an index and \ref fastuidraw::PainterAttribute to
429  represent an attribute. A \ref fastuidraw::PainterAttributeData
430  represents a collection of attribute and index chunks. The classes,
431  \ref fastuidraw::StrokedPath, \ref fastuidraw::FilledPath, \ref
432  fastuidraw::GlyphRun and \ref fastuidraw::GlyphSequence hold \ref
433  fastuidraw::PainterAttributeData objects ready for drawing. For
434  futher reading, see \ref PainterAttribute.
435  - The shader to draw the attribute and index data. FastUIDraw has
436  three shader types in its vertex and fragment pipeline (defined
437  in the module \ref PainterShaders).
438  - An item shader is represented by \ref fastuidraw::PainterItemShader.
439  This shader represents how the attribute and index data are
440  processed.
441  - A brush shader is represented by \ref fastuidraw::PainterBrushShader.
442  This shader represents computing a per-pixel color, for example
443  an image or gradient applied.
444  - A blend shader is represented by \ref fastuidraw::PainterBlendShader.
445  This shader represents how blending is performed (for example the
446  Porter-Duff modes).
447  - A small amount of data that is cheap to recalculate that is constant
448  for all vertices and pixels of an item. Each of the shader stages has
449  their own data classes (defined in the module \ref PainterShaderData).
450  - For item shading, the class \ref fastuidraw::PainterItemShaderData
451  is used to hold values that are constant for all attributes across
452  an item. One example are stroking paremeters such as stroking
453  width and miter-limit to apply to stroking as realized by \ref
454  fastuidraw::PainterStrokeParams and \ref fastuidraw::PainterDashedStrokeParams.
455  - For brush shading, the class \ref fastuidraw::PainterBrushShaderData
456  is used to hold values that are constant for the purpose of appliying
457  a brush. The main example is \ref fastuidraw::PainterBrush which holds
458  all the data needed to apply a standard brush consisting of an image,
459  gradient, repeat pattern and brush transformation.
460  - For blend shading, the class \ref fastuidraw::PainterBlendShaderData
461  is used to hold constants values for doing blending.
462 
463  The GL/GLES backends of FastUIDraw represents shaders as portions of GLSL
464  shader code, see the classes \ref fastuidraw::glsl::PainterItemShaderGLSL,
465  \ref fastuidraw::glsl::PainterBlendShaderGLSL and \ref
466  fastuidraw::glsl::PainterBrushShaderGLSL for the shader class types and their
467  interfaces.
468 
469  \section Examples
470  - See \ref ex_framework for the example framework to get started with the examples.
471  - See \ref ex_initialization for the how to create a \ref fastuidraw::Painter.
472  - See \ref ex_text for an example of using \ref fastuidraw::GlyphSequence to draw text with \ref fastuidraw::Painter.
473  - See \ref ex_gradient for an example of using \ref fastuidraw::PainterBrush to render gradients.
474  - See \ref ex_image for an example of using \ref fastuidraw::PainterBrush to render an image.
475  - See \ref ex_custom_brush for an example of creating a custom brush
476  - See \ref ex_path for an example of using \ref fastuidraw::Path to stroke and fill paths.
477  - See \ref ex_path2 for creating a \ref fastuidraw::Path with the operator<< overloads and filling it with a custom fill rule.
478  - See \ref ex_packed_value for an example of using \ref fastuidraw::PainterPackedValue and coordinate transformations of \ref fastuidraw::Painter.
479  - See \ref ex_custom_stroking_shader for an example of using shader chaining to create an animated wave-effect of stroking via shader chaining
480 */
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
void Uniform(int location, const matrixNxM< T, N, M > &v, bool transposed=false)
Template version for setting a single matrix uniform value.
void ProgramUniform(GLuint program, int location, const matrixNxM< T, N, M > &v, bool transposed=false)
Template version for setting a single matrix uniform value.