FastUIDraw
painter_draw.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_draw.hpp
3  * \brief file painter_draw.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_DRAW_HPP
21 #define FASTUIDRAW_PAINTER_DRAW_HPP
22 
24 #include <fastuidraw/util/vecN.hpp>
32 
33 namespace fastuidraw
34 {
35 /*!\addtogroup PainterBackend
36  * @{
37  */
38 
39  /*!
40  * \brief
41  * Store for attributes, indices of items and shared data of
42  * items for items to draw. Indices (stored in \ref m_indices)
43  * are -ALWAYS- in groups of three where each group is a single
44  * triangle and each index is an index into \ref m_attributes.
45  * The PainterDraw object is NOT thread safe, neither is its
46  * reference count. A PainterDraw object is used \ref Painter
47  * to send attributer and index data to a \ref PainterBackend.
48  */
49  class PainterDraw:
50  public reference_counted<PainterDraw>::non_concurrent
51  {
52  public:
53  /*!
54  * \brief
55  * A delayed action is an action that is to be called
56  * just before the buffers of a \ref PainterDraw are to
57  * be unmapped. Typically, this is used to write values
58  * using information that is ready after the original
59  * values are written by \ref Painter. A fixed \ref
60  * DelayedAction object may only be added to one \ref
61  * PainterDraw object, but a single \ref PainterDraw
62  * can have many \ref DelayedAction objects added to it.
63  */
64  class DelayedAction:public reference_counted<DelayedAction>::non_concurrent
65  {
66  public:
67  /*!
68  * Ctor.
69  */
70  DelayedAction(void);
71 
72  ~DelayedAction();
73 
74  /*!
75  * Perform the action of this DelayedAction object
76  * and remove it from the list of delayed actions of
77  * the PainterDraw.
78  */
79  void
80  perform_action(void);
81 
82  protected:
83  /*!
84  * To be implemented by a derived class to execute its delayed action.
85  * \param h handle to PainterDraw on which the action has
86  * been placed
87  */
88  virtual
89  void
91 
92  private:
93  friend class PainterDraw;
94  void *m_d;
95  };
96 
97  /*!
98  * Location to which to place attribute data,
99  * the store is understood to be write only.
100  */
102 
103  /*!
104  * Location to which to place the attribute data
105  * storing the header _locations_ in \ref m_store.
106  * The size of \ref m_header_attributes must be the
107  * same as the size of \ref m_attributes, the store
108  * is understood to be write only.
109  */
111 
112  /*!
113  * Location to which to place index data. Values
114  * are indices into m_attributes,
115  * the store is understood to be write only.
116  */
118 
119  /*!
120  * Generic store for data that is shared between
121  * vertices within an item and possibly between
122  * items. The store is understood to be write
123  * only.
124  */
126 
127  /*!
128  * Ctor, a derived class will set \ref m_attributes,
129  * \ref m_header_attributes, \ref m_indices and
130  * \ref m_store.
131  */
132  PainterDraw(void);
133 
134  ~PainterDraw();
135 
136  /*!
137  * Called to indicate a change in value to the
138  * painter header that this PainterDraw needs
139  * to record. The most common case is to insert API
140  * state changes (or just break a draw) for when a
141  * \ref PainterBackend cannot accomodate a Painter
142  * state change without changing the 3D API state.
143  * \param render_type the render target type of the rendering
144  * \param old_groups PainterShaderGroup before state change
145  * \param new_groups PainterShaderGroup after state change
146  * \param indices_written total number of indices written to m_indices -before- the change
147  * \returns true if the \ref PainterShaderGroup resulted in a draw break
148  */
149  virtual
150  bool
151  draw_break(enum PainterSurface::render_type_t render_type,
152  const PainterShaderGroup &old_groups,
153  const PainterShaderGroup &new_groups,
154  unsigned int indices_written) = 0;
155 
156  /*!
157  * Called to execute an action (and thus also cause a draw-call break).
158  * Implementations are to assume that \ref PainterDrawBreakAction reference
159  * is non-null. Implementations are to return true if the draw_break triggers
160  * a break in the draw call.
161  * \param action action to execute
162  * \param indices_written total number of indices written to \ref m_indices
163  * -before- the break
164  */
165  virtual
166  bool
168  unsigned int indices_written) = 0;
169 
170  /*!
171  * Adds a delayed action to the action list.
172  * \param h handle to action to add.
173  */
174  void
176 
177  /*!
178  * Signals this PainterDraw to be unmapped.
179  * Actual unmapping is delayed until all actions that
180  * have been added with add_action() have been
181  * called.
182  * \param attributes_written number of elements written to \ref
183  * m_attributes and \ref m_header_attributes.
184  * \param indices_written number of elements written to \ref m_indices
185  * \param data_store_written number of elements written to \ref m_store
186  */
187  void
188  unmap(unsigned int attributes_written,
189  unsigned int indices_written,
190  unsigned int data_store_written);
191 
192  /*!
193  * Returns true if and only if this PainterDraw
194  * is unmapped.
195  */
196  bool
197  unmapped(void) const;
198 
199  /*!
200  * To be implemented by a derived class to draw the
201  * contents. Must be performed after unmap() is called.
202  * In addition, may only be called within a
203  * PainterBackend::on_pre_draw() /
204  * PainterBackend::on_post_draw() pair of the \ref
205  * PainterBackend whose PainterBackend::map_draw()
206  * created this object.
207  */
208  virtual
209  void
210  draw(void) const = 0;
211 
212  protected:
213 
214  /*!
215  * To be implemented by a derived class to unmap
216  * the arrays m_store, m_attributes
217  * and m_indices. Once unmapped, the store
218  * can no longer be written to.
219  * \param attributes_written only the range [0,floats_written) of
220  * m_attributes must be uploaded to
221  * 3D API
222  * \param indices_written only the range [0,uints_written) of
223  * m_indices specify indices to use.
224  * \param data_store_written only the range [0,data_store_written) of
225  * m_store must be uploaded to 3D API
226  */
227  virtual
228  void
229  unmap_implement(unsigned int attributes_written,
230  unsigned int indices_written,
231  unsigned int data_store_written) = 0;
232 
233  private:
234 
235  void
236  complete_unmapping(void);
237 
238  void *m_d;
239  };
240 /*! @} */
241 
242 }
243 
244 #endif
virtual void draw(void) const =0
void unmap(unsigned int attributes_written, unsigned int indices_written, unsigned int data_store_written)
file painter_draw_break_action.hpp
file painter_surface.hpp
render_type_t
Enumeration to specify the render target of a Surface.
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A delayed action is an action that is to be called just before the buffers of a PainterDraw are to be...
A wrapper over a pointer to implement reference counting.
void add_action(const reference_counted_ptr< DelayedAction > &h) const
bool unmapped(void) const
A PainterShaderGroup gives to what groups the active shaders of a Painter belong. ...
c_array< PainterAttribute > m_attributes
c_array< uint32_t > m_header_attributes
file c_array.hpp
file gpu_dirty_state.hpp
Store for attributes, indices of items and shared data of items for items to draw. Indices (stored in m_indices) are -ALWAYS- in groups of three where each group is a single triangle and each index is an index into m_attributes. The PainterDraw object is NOT thread safe, neither is its reference count. A PainterDraw object is used Painter to send attributer and index data to a Painter Backend.
c_array< uvec4 > m_store
c_array< PainterIndex > m_indices
virtual void unmap_implement(unsigned int attributes_written, unsigned int indices_written, unsigned int data_store_written)=0
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
Defines default reference counting base classes.
file painter_attribute.hpp
virtual bool draw_break(enum PainterSurface::render_type_t render_type, const PainterShaderGroup &old_groups, const PainterShaderGroup &new_groups, unsigned int indices_written)=0
file painter_shader_group.hpp
virtual void action(const reference_counted_ptr< const PainterDraw > &h)=0
file reference_counted.hpp