FastUIDraw
arc_stroked_point.hpp
Go to the documentation of this file.
1 /*!
2  * \file arc_stroked_point.hpp
3  * \brief file arc_stroked_point.hpp
4  *
5  * Copyright 2018 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_ARC_STROKED_POINT_HPP
21 #define FASTUIDRAW_ARC_STROKED_POINT_HPP
22 
23 #include <fastuidraw/util/vecN.hpp>
24 #include <fastuidraw/util/util.hpp>
28 
29 namespace fastuidraw {
30 
31 /*!\addtogroup Paths
32  * @{
33  */
34 
35 /*!
36  * \brief
37  * An ArcStrokedPoint holds the data for a point of stroking
38  * where the segments can be arcs of a circle. The upshot
39  * is that a fragment shader will determine per-pixel coverage.
40  * In addition, the data is so that changing the stroking width
41  * or miter limit does not change the stroking data.
42  */
44 {
45 public:
46  /*!
47  * \brief
48  * Enumeration type to specify how to compute the location
49  * of an ArcStrokedPoint.
50  */
52  {
53  /*!
54  * A point of an arc. Indicates the point is part of
55  * an arc.
56  */
58 
59  /*!
60  * The point is part of a line-segment
61  */
63 
64  /*!
65  * Represents a point at the start or end of an edge.
66  * When performing dashed stroking with caps, these
67  * points can be expanded into quads to cover a cap
68  * induced by stroking at the start or end of an
69  * edge.
70  */
72 
73  /*!
74  * Number of offset types, not an actual offset type(!).
75  */
77  };
78 
79  /*!
80  * \brief
81  * Enumeration encoding of bits of \ref m_packed_data
82  * common to all offset types.
83  */
85  {
86  /*!
87  * Bit0 for holding the offset_type() value
88  * of the point.
89  */
91 
92  /*!
93  * number of bits needed to hold the
94  * offset_type() value of the point.
95  */
97 
98  /*!
99  * Bit indicates that the point in on the stroking
100  * boundary. Points with this bit down have that
101  * the vertex position after stroking is the same
102  * as \ref m_position.
103  */
105 
106  /*!
107  * Bit indicates that point is on the end of a
108  * segment.
109  */
111 
112  /*!
113  * Bit indicates that when doing dashed stroking that
114  * the value the distance value is the same for all
115  * points of a triangle, i.e. the dashed coverage
116  * computation can be done purely from the vertex
117  * shader
118  */
120 
121  /*!
122  * Bit indicates that the primitive formed is for a join
123  */
125 
126  /*!
127  * Bit0 for holding the depth() value
128  * of the point
129  */
131 
132  /*!
133  * number of bits needed to hold the
134  * depth() value of the point.
135  */
137 
138  /*!
139  * Number of bits used on common packed data
140  */
142  };
143 
144  /*!
145  * Enumeration of the bits of \ref m_packed_data
146  * for those with offset type \ref offset_arc_point
147  */
149  {
150  /*!
151  * Bit indicates that the point is a beyond stroking
152  * boundary bit. These points go beyond the stroking
153  * boundary to make sure that the triangles emitted
154  * contain the stroked arc.
155  */
157 
158  /*!
159  * If bit is up, then point is on the inside
160  * stroking boundary, otherwise the point is
161  * on the outside stroking boundary.
162  */
164 
165  /*!
166  * When this bit is up and the stroking radius exceeds
167  * the arc-radius, the point should be placed at the
168  * center of the arc.
169  */
171  };
172 
173  /*!
174  * Enumeration of the bits of \ref m_packed_data
175  * for those with offset type \ref offset_arc_point_dashed_capper
176  */
178  {
179  /*!
180  * if up, the point is to be moved in the direction
181  * of \ref m_data to cover an induced cap.
182  */
184  };
185 
186  /*!
187  * \brief
188  * Enumeration holding bit masks generated from
189  * values in \ref packed_data_bit_layout_common_t.
190  */
192  {
193  /*!
194  * Mask generated for \ref offset_type_bit0 and
195  * \ref offset_type_num_bits
196  */
198 
199  /*!
200  * Mask generated for \ref boundary_bit
201  */
203 
204  /*!
205  * Mask generated for \ref boundary_bit
206  */
208 
209  /*!
210  * Mask generated for \ref inner_stroking_bit
211  */
213 
214  /*!
215  * Mask generated for \ref move_to_arc_center_bit
216  */
218 
219  /*!
220  * Mask generated for \ref end_segment_bit
221  */
223 
224  /*!
225  * Mask generated for \ref distance_constant_on_primitive_bit
226  */
228 
229  /*!
230  * Mask generated for \ref join_bit
231  */
233 
234  /*!
235  * Mask generated for \ref extend_bit
236  */
238 
239  /*!
240  * Mask generated for \ref depth_bit0 and \ref depth_num_bits
241  */
243  };
244 
245  /*!
246  * Give the position of the point on the path.
247  */
249 
250  /*!
251  * Gives the unit vector in which to push the point.
252  * For those points that are arc's the location of
253  * the center is always given by
254  * \ref m_position - \ref radius() * \ref m_offset_direction
255  */
257 
258  /*!
259  * Meaning of \ref m_data depends on \ref offset_type(). If
260  * \ref offset_type() is \ref offset_line_segment, then
261  * \ref m_data holds the vector from this point to other
262  * point of the line segment. Otherwise, \ref m_data[0]
263  * holds the radius of the arc and \ref m_data[1] holds
264  * the angle difference from the end of the arc to the
265  * start of the arc.
266  */
268 
269  /*!
270  * Gives the distance of the point from the start
271  * of the -edge- on which the point resides.
272  */
274 
275  /*!
276  * Gives the distance of the point from the start
277  * of the -contour- on which the point resides.
278  */
280 
281  /*!
282  * Gives the length of the edge on which the
283  * point lies. This value is the same for all
284  * points along a fixed edge.
285  */
287 
288  /*!
289  * Gives the length of the contour on which the
290  * point lies. This value is the same for all
291  * points along a fixed contour.
292  */
294 
295  /*!
296  * Bit field with data packed.
297  */
298  uint32_t m_packed_data;
299 
300  /*!
301  * Provides the point type from a value of \ref m_packed_data.
302  * The return value is one of the enumerations of
303  * \ref offset_type_t.
304  * \param packed_data_value value suitable for \ref m_packed_data
305  */
306  static
307  enum offset_type_t
308  offset_type(uint32_t packed_data_value)
309  {
310  uint32_t v;
311  v = unpack_bits(offset_type_bit0, offset_type_num_bits, packed_data_value);
312  return static_cast<enum offset_type_t>(v);
313  }
314 
315  /*!
316  * Provides the point type for the point. The return value
317  * is one of the enumerations of \ref offset_type_t.
318  */
319  enum offset_type_t
320  offset_type(void) const
321  {
322  return offset_type(m_packed_data);
323  }
324 
325  /*!
326  * If a point from an arc-segment, gives the radius
327  * of the arc, equivalent to \ref m_data[0].
328  */
329  float
330  radius(void) const
331  {
332  return m_data[0];
333  }
334 
335  /*!
336  * If a point from an arc-segment, gives the radius
337  * of the arc, equivalent to \ref m_data[0].
338  */
339  float&
340  radius(void)
341  {
342  return m_data[0];
343  }
344 
345  /*!
346  * If a point from an arc-segment, gives the angle
347  * of the arc, equivalent to \ref m_data[1].
348  */
349  float
350  arc_angle(void) const
351  {
352  return m_data[1];
353  }
354 
355  /*!
356  * If a point from an arc-segment, gives the angle
357  * of the arc, equivalent to \ref m_data[1].
358  */
359  float&
360  arc_angle(void)
361  {
362  return m_data[1];
363  }
364 
365  /*!
366  * When stroking the data, the depth test to only
367  * pass when the depth value is -strictly- larger
368  * so that a fixed pixel is not stroked twice by
369  * a single path. The value returned by depth() is
370  * a relative z-value for a vertex. The points
371  * drawn first have the largest z-values.
372  */
373  uint32_t
374  depth(void) const
375  {
376  return unpack_bits(depth_bit0, depth_num_bits, m_packed_data);
377  }
378 
379  /*!
380  * Set the value returned by depth().
381  */
382  void
383  depth(const uint32_t v)
384  {
385  m_packed_data &= ~depth_mask;
386  m_packed_data |= pack_bits(depth_bit0, depth_num_bits, v);
387  }
388 
389  /*!
390  * Pack the data of this \ref ArcStrokedPoint into a \ref
391  * PainterAttribute. The packing is as follows:
392  * - PainterAttribute::m_attrib0 .xy -> \ref m_position (float)
393  * - PainterAttribute::m_attrib0 .zw -> \ref m_offset_direction (float)
394  * - PainterAttribute::m_attrib1 .x -> \ref m_distance_from_edge_start (float)
395  * - PainterAttribute::m_attrib1 .y -> \ref m_distance_from_contour_start (float)
396  * - PainterAttribute::m_attrib1 .zw -> \ref m_data (float)
397  * - PainterAttribute::m_attrib2 .x -> \ref m_packed_data (uint)
398  * - PainterAttribute::m_attrib2 .y -> \ref m_edge_length (float)
399  * - PainterAttribute::m_attrib2 .z -> \ref m_contour_length (float)
400  * - PainterAttribute::m_attrib2 .w (free)
401  *
402  * \param dst PainterAttribute to which to pack
403  */
404  void
405  pack_point(PainterAttribute *dst) const;
406 
407  /*!
408  * Unpack an \ref ArcStrokedPoint from a \ref PainterAttribute.
409  * \param dst point to which to unpack data
410  * \param src PainterAttribute from which to unpack data
411  */
412  static
413  void
415 };
416 
417 /*!
418  * \brief
419  * Namespce to encompass packing values and functions of
420  * path data for stroking using \ref ArcStrokedPoint
421  */
422 namespace ArcStrokedPointPacking
423 {
424  enum
425  {
426  arcs_per_cap = 4,
427 
428  /*!
429  * Number of attributes needed for realizing a rounded
430  * cap with packed \ref ArcStrokedPoint values.
431  */
432  num_attributes_per_cap = 3 * arcs_per_cap + 2,
433 
434  /*!
435  * Number of indices needed for realizing a rounded
436  * cap with packed \ref ArcStrokedPoint values.
437  */
438  num_indices_per_cap = 9 * arcs_per_cap
439  };
440 
441  /*!
442  * Returns the number of attributes realized with \ref
443  * ArcStrokedPoint needed to pack a join (to be drawn with
444  * he join style \ref PainterEnums::rounded_joins).
445  * \param join join to realize a packed data
446  * \param num_attributes location to which to write the needed
447  * number of attributes
448  * \param num_indices location to which to write the needed
449  * number of indices
450  */
451  void
453  unsigned int *num_attributes,
454  unsigned int *num_indices);
455 
456  /*!
457  * Pack a join into attribute data and index data
458  * realized with \ref ArcStrokedPoint.
459  * \param join join data to pack
460  * \param depth the value for \ref ArcStrokedPoint::depth() of the
461  * packed \ref ArcStrokedPoint values
462  * \param dst_attribs location to which to place the attributes,
463  * the size of dst_attribs must be as indicated
464  * by \ref pack_join_size().
465  * \param dst_indices location to which to place the indices,
466  * the size of dst_indices must be as indicated
467  * by \ref pack_join_size().
468  * \param index_adjust value by which to increment the written
469  * index values
470  */
471  void
472  pack_join(const TessellatedPath::join &join,
473  unsigned int depth,
474  c_array<PainterAttribute> dst_attribs,
475  c_array<PainterIndex> dst_indices,
476  unsigned int index_adjust);
477 
478  /*!
479  * Pack a cap into attribute data and index data
480  * realized with \ref ArcStrokedPoint.
481  * \param cap cap data to pack
482  * \param depth the value for \ref ArcStrokedPoint::depth() of the
483  * packed \ref ArcStrokedPoint values
484  * \param dst_attribs location to which to place the attributes,
485  * the size of dst_attribs must be \ref
486  * num_attributes_per_cap
487  * \param dst_indices location to which to place the indices,
488  * the size of dst_indices must be \ref
489  * num_indices_per_cap.
490  * \param index_adjust value by which to increment the written
491  * index values
492  */
493  void
494  pack_cap(const TessellatedPath::cap &cap,
495  unsigned int depth,
496  c_array<PainterAttribute> dst_attribs,
497  c_array<PainterIndex> dst_indices,
498  unsigned int index_adjust);
499 
500  /*!
501  * Computes the number of indices and attributes necessary to pack
502  * an array of \ref TessellatedPath::segment_chain values.
503  * \param chains segment chain to query amount room needed to pack
504  * realized by \ref ArcStrokedPoint
505  * \param depth_range_size location to which to write the depth range needed
506  * to pack the segment chain.
507  * \param num_attributes location to which to write the needed
508  * number of attributes
509  * \param num_indices location to which to write the needed
510  * number of indices
511  */
512  void
514  unsigned int *depth_range_size,
515  unsigned int *num_attributes,
516  unsigned int *num_indices);
517 
518  /*!
519  * Computes the number of indices and attributes necessary to pack
520  * a single \ref TessellatedPath::segment_chain value.
521  * \param chain segment chain to query amount room needed to pack
522  * realized by \ref StrokedPoint
523  * \param depth_range_size location to which to write the depth range needed
524  * to pack the segment chain.
525  * \param num_attributes location to which to write the needed
526  * number of attributes
527  * \param num_indices location to which to write the needed
528  * number of indices
529  */
530  void
532  unsigned int *depth_range_size,
533  unsigned int *num_attributes,
534  unsigned int *num_indices);
535 
536  /*!
537  * Pack an array of segments chains realized as \ref ArcStrokedPoint
538  * \param chains segment chain to pack
539  * \param depth_start value the lowest depth value for the attributes;
540  * the packed \ref ArcStrokedPoint values will have
541  * depth_start <= \ref ArcStrokedPoint::depth() and
542  * \ref ArcStrokedPoint::depth() < depth_start + depth_range_size
543  * where depth_range_size is as indicated by
544  * \ref pack_segment_chain_size().
545  * \param dst_attribs location to which to place the attributes, the
546  * size of dst_attribs must be as indicated by \ref
547  * pack_segment_chain_size().
548  * \param dst_indices location to which to place the indices, the
549  * size of dst_indices must be as indicated by
550  * \ref pack_segment_chain_size().
551  * \param index_adjust value by which to increment the written
552  * index values
553  */
554  void
556  unsigned int depth_start,
557  c_array<PainterAttribute> dst_attribs,
558  c_array<PainterIndex> dst_indices,
559  unsigned int index_adjust);
560 
561  /*!
562  * Pack a single segment chain realized as \ref ArcStrokedPoint
563  * \param chain segment chain to pack
564  * \param depth_start value the lowest depth value for the attributes;
565  * the packed \ref StrokedPoint values will have
566  * depth_start <= \ref StrokedPoint::depth() and \ref
567  * StrokedPoint::depth() < depth_start + depth_range_size
568  * where depth_range_size is as indicated by
569  * \ref pack_segment_chain_size().
570  * \param dst_attribs location to which to place the attributes, the
571  * size of dst_attribs must be as indicated by \ref
572  * pack_segment_chain_size().
573  * \param dst_indices location to which to place the indices, the
574  * size of dst_indices must be as indicated by \ref
575  * pack_segment_chain_size().
576  * \param index_adjust value by which to increment the written
577  * index values
578  */
579  void
581  unsigned int depth_start,
582  c_array<PainterAttribute> dst_attribs,
583  c_array<PainterIndex> dst_indices,
584  unsigned int index_adjust);
585 }
586 
587 /*! @} */
588 
589 }
590 
591 #endif
An ArcStrokedPoint holds the data for a point of stroking where the segments can be arcs of a circle...
#define FASTUIDRAW_MASK(BIT0, NUMBITS)
Definition: util.hpp:59
uint32_t unpack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Definition: util.hpp:328
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
Represents the geometric data for a join.
file tessellated_path.hpp
Represents the geometric data for a cap.
void pack_cap(const TessellatedPath::cap &cap, unsigned int depth, c_array< PainterAttribute > dst_attribs, c_array< PainterIndex > dst_indices, unsigned int index_adjust)
void pack_segment_chain_size(const TessellatedPath::segment_chain &chain, unsigned int *depth_range_size, unsigned int *num_attributes, unsigned int *num_indices)
file c_array.hpp
void pack_join(const TessellatedPath::join &join, unsigned int depth, c_array< PainterAttribute > dst_attribs, c_array< PainterIndex > dst_indices, unsigned int index_adjust)
void pack_join_size(const TessellatedPath::join &join, unsigned int *num_attributes, unsigned int *num_indices)
The attribute data generated/filled by Painter. Attribute data is sent to 3D API as raw bits with the...
file util.hpp
void pack_segment_chain(const TessellatedPath::segment_chain &chain, unsigned int depth_start, c_array< PainterAttribute > dst_attribs, c_array< PainterIndex > dst_indices, unsigned int index_adjust)
void depth(const uint32_t v)
enum offset_type_t offset_type(void) const
packed_data_bit_masks_t
Enumeration holding bit masks generated from values in packed_data_bit_layout_common_t.
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
offset_type_t
Enumeration type to specify how to compute the location of an ArcStrokedPoint.
file vecN.hpp
uint32_t pack_bits(uint32_t bit0, uint32_t num_bits, uint32_t value)
Definition: util.hpp:294
packed_data_bit_layout_common_t
Enumeration encoding of bits of m_packed_data common to all offset types.
file painter_attribute.hpp
static void unpack_point(ArcStrokedPoint *dst, const PainterAttribute &src)
void pack_point(PainterAttribute *dst) const