FastUIDraw
painter_blend_shader_glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_blend_shader_glsl.hpp
3  * \brief file painter_blend_shader_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 
20 #ifndef FASTUIDRAW_PAINTER_BLEND_SHADER_GLSL_HPP
21 #define FASTUIDRAW_PAINTER_BLEND_SHADER_GLSL_HPP
22 
23 #include <fastuidraw/util/vecN.hpp>
27 
28 namespace fastuidraw
29 {
30  namespace glsl
31  {
32 /*!\addtogroup GLSL
33  * @{
34  */
35  /*!
36  * \brief
37  * A PainterBlendShaderGLSL is a PainterBlendShader whose
38  * shader code fragment is via GLSL.
39  *
40  * The code to implement is dependent on the PainterBlendShader::type()
41  * of the created PainterBlendShaderGLSL.
42  * - PainterBlendShader::type() == PainterBlendShader::single_src
43  * The shader code fragment must provide the function
44  * \code
45  * void
46  * fastuidraw_gl_compute_blend_value(in uint sub_shader, inout uint shader_data_block,
47  * in vec4 in_src, out vec4 out_src)
48  * \endcode
49  * where in_src is the output of the item fragment shader modulated by the
50  * current brush with alpha applied to rgb and out_src is the value for the
51  * fragment shader to emit.
52  *
53  * - PainterBlendShader::type() == PainterBlendShader::dual_src
54  * The shader code fragment must provide the function
55  * \code
56  * void
57  * fastuidraw_gl_compute_blend_factors(in uint sub_shader, inout uint shader_data_block,
58  * in vec4 in_src, out vec4 out_src0, out vec4 out_src1)
59  * \endcode
60  * where in_src is the output of the item fragment shader modulated by the
61  * current brush with alpha applied to rgb, out_src0 is the value for the
62  * fragment shader to emit for GL_SRC_COLOR and out_src1 is the value for
63  * the fragment shader to emit value for GL_SRC1_COLOR.
64  *
65  * - PainterBlendShader::type() == PainterBlendShader::framebuffer_fetch
66  * The shader code fragment must provide the function
67  * \code
68  * void
69  * fastuidraw_gl_compute_post_blended_value(in uint sub_shader, inout uint shader_data_block,
70  * in vec4 in_src, in vec4 in_fb, out vec4 out_src)
71  * \endcode
72  * where in_src is the output of the item fragment shader modulated by the
73  * current brush with alpha applied to rgb, in_fb is the value of the
74  * framebuffer at the location and out_src is the value for the fragment
75  * shader to emit.
76  *
77  * The GLSL elements in the modules \ref GLSLVertFragCode and
78  * \ref GLSLFragCode are available for use.
79  *
80  * For both stages, the value of the argument of shader_data_block is
81  * which 128-bit block into the data store (PainterDraw::m_store) of the
82  * shader data to be read with the GLSL macro \ref fastuidraw_fetch_data.
83  * On exit, this value must be updated to the location just past the
84  * shader data of the shader.
85  *
86  * For both stages, the value of the argument of sub_shader() is the
87  * value of \ref PainterShader::sub_shader() of the active shader.
88  *
89  * The value of the argument of shader_data_block is which 128-bit block
90  * into the data store (PainterDraw::m_store) of the custom shader data
91  * to be read with the GLSL macro \ref fastuidraw_fetch_data.
92  *
93  * Also, if one defines macros in any of the passed ShaderSource objects,
94  * those macros MUST be undefined at the end. In addition, if one
95  * has local helper functions, to avoid global name collision, those
96  * function names should be wrapped in the macro FASTUIDRAW_LOCAL()
97  * to make sure that the function is given a unique global name within
98  * the uber-shader.
99  *
100  * Lastly, one can use the class \ref UnpackSourceGenerator to generate
101  * shader code to unpack values from the data in the data store buffer.
102  * That machine generated code uses the macro fastuidraw_fetch_data().
103  */
105  {
106  public:
107  /*!
108  * \brief
109  * If one wishes to make use of other \ref PainterBlendShaderGLSL
110  * fastuidraw_gl_compute_blend_value(), fastuidraw_gl_compute_blend_factors()
111  * or fastuidraw_gl_compute_post_blended_value() routines of other shaders
112  * (for example to have a simple shader that adds on to a previous shader),
113  * a DependencyList provides the means to do so.
114  *
115  * Each such used shader is given a name by which the caller will use it.
116  */
118  {
119  public:
120  /*!
121  * Ctor.
122  */
123  DependencyList(void);
124 
125  /*!
126  * Copy ctor.
127  * \param obj value from which to copy
128  */
129  DependencyList(const DependencyList &obj);
130 
131  ~DependencyList();
132 
133  /*!
134  * Assignment operator
135  * \param rhs value from which to copy
136  */
138  operator=(const DependencyList &rhs);
139 
140  /*!
141  * Swap operation
142  * \param obj object with which to swap
143  */
144  void
145  swap(DependencyList &obj);
146 
147  /*!
148  * Add a shader to the DependencyList's list.
149  * \param name name by which to call the shader
150  * \param shader shader to add to this DependencyList
151  */
153  add_shader(c_string name,
155 
156  private:
157  friend class PainterBlendShaderGLSL;
158  void *m_d;
159  };
160 
161  /*!
162  * Ctor.
163  * \param tp blend shader type
164  * \param src GLSL code fragment for blend shading
165  * \param num_sub_shaders the number of sub-shaders it supports
166  * \param dependencies list of other \ref PainterBlendShaderGLSL
167  * that are used directly.
168  */
169  PainterBlendShaderGLSL(enum shader_type tp, const ShaderSource &src,
170  unsigned int num_sub_shaders = 1,
171  const DependencyList &dependencies = DependencyList());
172 
173  ~PainterBlendShaderGLSL(void);
174 
175  /*!
176  * Return the GLSL source of the blend shader
177  */
178  const glsl::ShaderSource&
179  blend_src(void) const;
180 
181  /*!
182  * Return the list of shaders on which this shader is dependent.
183  */
185  dependency_list_shaders(void) const;
186 
187  /*!
188  * Returns the names that each shader listed in \ref
189  * dependency_list_shaders() is referenced by, i.e.
190  * the i'th element of dependency_list_shaders() is
191  * referenced as the i'th element of \ref
192  * dependency_list_names().
193  */
195  dependency_list_names(void) const;
196 
197  private:
198  void *m_d;
199  };
200 /*! @} */
201 
202  }
203 }
204 
205 #endif
A ShaderSource represents the source code to a GLSL shader, specifying blocks of source code and macr...
DependencyList & operator=(const DependencyList &rhs)
A PainterBlendShader represents a shader for performing blending operations.
DependencyList & add_shader(c_string name, const reference_counted_ptr< const PainterBlendShaderGLSL > &shader)
c_array< const c_string > dependency_list_names(void) const
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
c_array< const reference_counted_ptr< const PainterBlendShaderGLSL > > dependency_list_shaders(void) const
file blend_mode.hpp
A PainterBlendShaderGLSL is a PainterBlendShader whose shader code fragment is via GLSL...
file shader_source.hpp
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
file vecN.hpp
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
shader_type
Enumeration to specify how blend shader operates.
If one wishes to make use of other PainterBlendShaderGLSL fastuidraw_gl_compute_blend_value(), fastuidraw_gl_compute_blend_factors() or fastuidraw_gl_compute_post_blended_value() routines of other shaders (for example to have a simple shader that adds on to a previous shader), a DependencyList provides the means to do so.
const glsl::ShaderSource & blend_src(void) const
file painter_blend_shader.hpp