FastUIDraw
painter_engine.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_engine.hpp
3  * \brief file painter_engine.hpp
4  *
5  * Copyright 2019 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_ENGINE_HPP
21 #define FASTUIDRAW_PAINTER_ENGINE_HPP
22 
24 #include <fastuidraw/util/rect.hpp>
30 
31 namespace fastuidraw
32 {
33 /*!\addtogroup PainterBackend
34  * @{
35  */
36 
37  /*!
38  * \brief
39  * A \ref PainterEngine provides an interface to create
40  * \ref PainterBackend derived objects.
41  */
42  class PainterEngine:public reference_counted<PainterEngine>::concurrent
43  {
44  public:
45  /*!
46  * \brief
47  * A ConfigurationBase holds properties common to all \ref PainterBackend
48  * objects returned by \ref PainterEngine::create_backend() from
49  * a fixed PainterEngine
50  */
52  {
53  public:
54  /*!
55  * Ctor.
56  */
57  ConfigurationBase(void);
58 
59  /*!
60  * Copy ctor.
61  */
63 
65 
66  /*!
67  * assignment operator
68  */
70  operator=(const ConfigurationBase &obj);
71 
72  /*!
73  * Swap operation
74  * \param obj object with which to swap
75  */
76  void
77  swap(ConfigurationBase &obj);
78 
79  /*!
80  * If true, indicates that the PainterBackend supports
81  * bindless texturing. Default value is false.
82  */
83  bool
84  supports_bindless_texturing(void) const;
85 
86  /*!
87  * Specify the return value to supports_bindless_texturing() const.
88  * Default value is false.
89  */
92 
93  /*!
94  * Returns the maximum number of simutaneously bound
95  * \ref Image object whose \ref Image::type() has the
96  * value \ref Image::context_texture2d.
97  */
98  unsigned int
99  number_context_textures(void) const;
100 
101  /*!
102  * Specify the return value to number_context_textures() const.
103  * Default value is false.
104  */
106  number_context_textures(unsigned int);
107 
108  private:
109  void *m_d;
110  };
111 
112  /*!
113  * \brief
114  * PerformanceHints provides miscellaneous data about \ref PainterBackend
115  * objects returned by \ref PainterEngine::create_backend() from
116  * a fixed PainterEngine
117  */
119  {
120  public:
121  /*!
122  * Ctor.
123  */
124  PerformanceHints(void);
125 
126  /*!
127  * Copy ctor.
128  */
130 
131  ~PerformanceHints();
132 
133  /*!
134  * assignment operator
135  */
137  operator=(const PerformanceHints &obj);
138 
139  /*!
140  * Swap operation
141  * \param obj object with which to swap
142  */
143  void
144  swap(PerformanceHints &obj);
145 
146  /*!
147  * Returns true if an implementation of PainterBackend
148  * clips triangles (for example by a hardware clipper
149  * or geometry shading) instead of discard to implement
150  * clipping as embodied by \ref PainterClipEquations.
151  */
152  bool
153  clipping_via_hw_clip_planes(void) const;
154 
155  /*!
156  * Set the value returned by
157  * clipping_via_hw_clip_planes(void) const,
158  * default value is true.
159  */
161  clipping_via_hw_clip_planes(bool v);
162 
163  /*!
164  * Gives the maximum z-value an implementation of
165  * PainterBackend support.
166  */
167  int
168  max_z(void) const;
169 
170  /*!
171  * Set the value returned by max_z(void) const,
172  * default value is 2^20.
173  */
175  max_z(int);
176 
177  private:
178  void *m_d;
179  };
180 
181  virtual
182  ~PainterEngine();
183 
184  /*!
185  * Returns the PainterShaderSet for the backend.
186  * Returned values will already be registered to
187  * the \ref PainterShaderRegistrar returned by
188  * \ref painter_shader_registrar().
189  */
190  const PainterShaderSet&
191  default_shaders(void) const;
192 
193  /*!
194  * Returns the PerformanceHints for the PainterBackend,
195  * may only be called after on_begin() has been called
196  * atleast once. The value returned is expected to stay
197  * constant once on_begin() has been called.
198  */
199  const PerformanceHints&
200  hints(void) const;
201 
202  /*!
203  * Returns a reference to the \ref GlyphAtlas of this
204  * \ref PainterEngine. All glyphs used by each \ref
205  * Painter made from this \ref PainterEngine must
206  * live on glyph_atlas().
207  */
208  GlyphAtlas&
209  glyph_atlas(void) const;
210 
211  /*!
212  * Returns a reference to the \ref ImageAtlas of this
213  * \ref PainterEngine. All images used by each \ref
214  * PainterBackend made from this \ref PainterEngine
215  * must live on image_atlas().
216  */
217  ImageAtlas&
218  image_atlas(void) const;
219 
220  /*!
221  * Returns a reference to the \ref ColorStopAtlas of this
222  * \ref PainterEngine. All color stops used by all brushes
223  * of each \ref PainterBackend made from this \ref
224  * PainterEngine must live on colorstop_atlas().
225  */
227  colorstop_atlas(void) const;
228 
229  /*!
230  * Returns a handle to the \ref GlyphCache made
231  * from glyph_atlas().
232  */
233  GlyphCache&
234  glyph_cache(void) const;
235 
236  /*!
237  * Returns the PainterShaderRegistrar of this PainterEngine.
238  * Use this return value to add custom shaders. NOTE: shaders
239  * added within a thread are not useable by a \ref PainterBackend
240  * made from this \ref PainterEngine within that thread
241  * until the next call to its PainterBackend::begin().
242  */
244  painter_shader_registrar(void) const;
245 
246  /*!
247  * Provided as a conveniance, equivalent to
248  * \code
249  * painter_shader_registrar().register_shader(v)
250  * \endcode
251  * \param v shade value to register to \ref painter_shader_registrar()
252  */
253  template<typename T>
254  void
255  register_shader(const T &v)
256  {
258  }
259 
260  /*!
261  * Returns the ConfigurationBase passed in the ctor.
262  */
263  const ConfigurationBase&
264  configuration_base(void) const;
265 
266  /*!
267  * To be implemented by a derived class to create a
268  * \ref PainterBackend object. All \ref PainterBackend
269  * objects created by create_backend() from the same
270  * \ref PainterEngine share the same
271  * - \ref PainterShaderRegistrar (see \ref painter_shader_registrar())
272  * - \ref GlyphAtlas (see \ref glyph_atlas())
273  * - \ref ImageAtlas (see \ref image_atlas())
274  * - \ref ColorStopAtlas (see \ref colorstop_atlas())
275  * but are otherwise independent of each other.
276  */
277  virtual
279  create_backend(void) const = 0;
280 
281  /*!
282  * To be implemented by a derived class to create a
283  * Surface with its own backing that is useable by
284  * any \ref PainterBackend object that this \ref
285  * PainterEngine returns in create_backend()
286  * \param dims the dimensions of the backing store of
287  * the returned Surface
288  * \param render_type the render type of the surface (i.e.
289  * is it a color buffer or deferred
290  * coverage buffer).
291  */
292  virtual
294  create_surface(ivec2 dims,
295  enum PainterSurface::render_type_t render_type) = 0;
296 
297  protected:
298  /*!
299  * Ctor.
300  * \param glyph_atlas GlyphAtlas for glyphs drawn by each \ref PainterBackend
301  * returned by \ref create_backend() of the created
302  * \ref PainterEngine
303  * \param image_atlas ImageAtlas for images drawn by each \ref PainterBackend
304  * returned by \ref create_backend() of the created
305  * \ref PainterEngine
306  * \param colorstop_atlas ColorStopAtlas for color stop sequences drawn by
307  * each \ref PainterBackend returned by \ref create_backend()
308  * of the created PainterEngine
309  * \param shader_registrar PainterShaderRegistrar used by each \ref PainterBackend
310  * returned by \ref create_backend() of the created
311  * \ref PainterEngine
312  * \param config \ref ConfigurationBase for each \ref PainterBackend returned by
313  * \ref create_backend() of the created \ref PainterEngine
314  * \param pdefault_shaders default shaders for each \ref PainterBackend returned
315  * by \ref create_backend() of the created \ref
316  * PainterEngine; shaders are registered at
317  * construction of the created \ref PainterEngine
318  */
323  const ConfigurationBase &config,
324  const PainterShaderSet &pdefault_shaders);
325 
326  /*!
327  * To be accessed by a derived class in its ctor
328  * to set the performance hint values for itself.
329  */
331  set_hints(void);
332 
333  private:
334  void *m_d;
335  };
336 /*! @} */
337 
338 }
339 
340 #endif
A GlyphAtlas is a common location to place glyph data of an application. Ideally, all glyph data is p...
file glyph_cache.hpp
A PainterEngine provides an interface to create Painter Backend derived objects.
render_type_t
Enumeration to specify the render target of a Surface.
GlyphAtlas & glyph_atlas(void) const
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
file painter_backend.hpp
void register_shader(PainterItemShader *shader)
A wrapper over a pointer to implement reference counting.
ImageAtlas & image_atlas(void) const
A GlyphCache represents a cache of glyphs and manages the uploading of the data to a GlyphAtlas...
Definition: glyph_cache.hpp:43
ColorStopAtlas & colorstop_atlas(void) const
virtual reference_counted_ptr< PainterBackend > create_backend(void) const =0
file blend_mode.hpp
unsigned int number_context_textures(void) const
file glyph_atlas.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).
const ConfigurationBase & configuration_base(void) const
const PerformanceHints & hints(void) const
A PainterShaderRegistrar is an interface that defines the assigning of PainterShader::ID() to a Paint...
PainterShaderRegistrar & painter_shader_registrar(void) const
A PainterShaderSet provides shaders for blending and drawing each of the item types glyphs...
virtual reference_counted_ptr< PainterSurface > create_surface(ivec2 dims, enum PainterSurface::render_type_t render_type)=0
ConfigurationBase & operator=(const ConfigurationBase &obj)
A ConfigurationBase holds properties common to all Painter Backend objects returned by PainterEngine:...
void register_shader(const T &v)
PainterEngine(reference_counted_ptr< GlyphAtlas > glyph_atlas, reference_counted_ptr< ImageAtlas > image_atlas, reference_counted_ptr< ColorStopAtlas > colorstop_atlas, reference_counted_ptr< PainterShaderRegistrar > shader_registrar, const ConfigurationBase &config, const PainterShaderSet &pdefault_shaders)
Defines default reference counting base classes.
file colorstop_atlas.hpp
An ImageAtlas is a common location to place images of an application.
const PainterShaderSet & default_shaders(void) const
PerformanceHints provides miscellaneous data about Painter Backend objects returned by PainterEngine:...
file image_atlas.hpp
PerformanceHints & set_hints(void)
GlyphCache & glyph_cache(void) const