FastUIDraw
painter_image_brush_shader_data.hpp
1 /*!
2  * \file painter_image_brush_shader.hpp
3  * \brief file painter_image_brush_shader.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 #ifndef FASTUIDRAW_PAINTER_IMAGE_BRUSH_SHADER_DATA_HPP
20 #define FASTUIDRAW_PAINTER_IMAGE_BRUSH_SHADER_DATA_HPP
21 
22 #include <fastuidraw/image.hpp>
25 #include <fastuidraw/painter/painter_custom_brush.hpp>
27 
28 namespace fastuidraw
29 {
30 
31 /*!\addtogroup PainterShaderData
32  * @{
33  */
34 
35  /*!
36  * \brief
37  * A \ref PainterImageBrushShaderData defines the \ref
38  * PainterBrushShaderData that the shaders of a \ref
39  * PainterImageBrushShader consume. It specifies
40  * what \ref Image and what rectangular region within
41  * it from which to source image data.
42  */
45  public PainterBrushEnums
46  {
47  public:
48  /*!
49  * \brief
50  * Bit packing for an uvec2 value.
51  */
53  {
54  uvec2_x_num_bits = 16, /*!< number bits to encode x-coordinate */
55  uvec2_y_num_bits = 16, /*!< number bits to encode y-coordinate */
56 
57  uvec2_x_bit0 = 0, /*!< bit where x-coordinate is encoded */
58  uvec2_y_bit0 = uvec2_x_num_bits, /*!< bit where y-coordinate is encoded */
59  };
60 
61  /*!
62  * \brief
63  * Bit packing for the master index tile of a Image
64  */
66  {
67  atlas_location_x_num_bits = 8, /*!< number bits to encode Image::master_index_tile().x() */
68  atlas_location_y_num_bits = 8, /*!< number bits to encode Image::master_index_tile().y() */
69  atlas_location_z_num_bits = 16, /*!< number bits to encode Image::master_index_tile().z() */
70 
71  atlas_location_x_bit0 = 0, /*!< bit where Image::master_index_tile().x() is encoded */
72 
73  /*!
74  * bit where Image::master_index_tile().y() is encoded
75  */
77 
78  /*!
79  * bit where Image::master_index_tile().z() is encoded
80  */
82  };
83 
84  /*!
85  * \brief
86  * Offsets for image data packing. The offsets are in
87  * units of uint32_t, NOT units of \ref uvec4.
88  */
89  enum offset_t
90  {
91  /*!
92  * Width and height of the sub-rectangle of the \ref
93  * Image from which to source and encoded in a single
94  * uint32_t. The bits are packed as according to \ref
95  * uvec2_encoding. If there is no valid backing image,
96  * then the encoded value will be 0.
97  */
99 
100  /*!
101  * The minx-miny corener of the sub-rectangle of the \ref
102  * Image from which to source and encoded in a single
103  * uint32_t. The bits are packed as according to \ref
104  * uvec2_encoding.
105  */
107 
108  /*!
109  * Location of image (Image::master_index_tile()) in the image
110  * atlas is encoded in a single uint32. The bits are packed as
111  * according to \ref atlas_location_encoding. If the image
112  * is not of type Image::on_atlas, gives the high 32-bits of
113  * Image::handle().
114  */
116 
117  /*!
118  * Holds the amount the number of index looks ups, see \ref
119  * Image::number_index_lookups(). If the image is not of type
120  * Image::on_atlas, gives the low 32-bits of Image::handle().
121  */
123 
124  /*!
125  * Number of elements packed for image support
126  * for a brush
127  */
129 
130  /*!
131  * Offset to the high 32-bits of the handle value when the
132  * Image is of type Image::bindless_texture2d.
133  */
135 
136  /*!
137  * Offset to the low 32-bits of the handle value when the
138  * Image is of type Image::bindless_texture2d.
139  */
141  };
142 
143  /*!
144  * Ctor initializes to not source from any image data
145  */
147 
148  /*!
149  * Copy ctor.
150  */
152  m_image(obj.m_image),
153  m_image_xy(obj.m_image_xy),
154  m_image_wh(obj.m_image_wh)
155  {}
156 
157  /*!
158  * Assignment operator
159  */
162  {
163  m_image = rhs.m_image;
164  m_image_xy = rhs.m_image_xy;
165  m_image_wh = rhs.m_image_wh;
166  return *this;
167  }
168 
169  /*!
170  * Set to source from a sub-rectangle of a \ref Image
171  * \param im \ref Image from which to source
172  * \param xy minx-miny corner of sub-rectangle
173  * \param wh width and height of sub-rectangle
174  */
175  void
177  uvec2 xy, uvec2 wh);
178 
179  /*!
180  * Set to source from the entire contents of an
181  * \ref Image.
182  * \param im \ref Image from which to source
183  */
184  void
186 
187  /*!
188  * Returns the \ref Image from which to source
189  */
191  image(void) const
192  {
193  return m_image;
194  }
195 
196  void
197  pack_data(c_array<uvec4> dst) const override;
198 
199  unsigned int
200  data_size(void) const override;
201 
202  void
204 
205  unsigned int
206  number_resources(void) const override;
207 
209  bind_images(void) const override;
210 
211  private:
213  uvec2 m_image_xy, m_image_wh;
214  };
215 
216 /*! @} */
217 }
218 
219 #endif
unsigned int number_resources(void) const override
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
void save_resources(c_array< reference_counted_ptr< const resource_base > > dst) const override
A wrapper over a pointer to implement reference counting.
offset_t
Offsets for image data packing. The offsets are in units of uint32_t, NOT units of uvec4...
A PainterImageBrushShaderData defines the PainterBrushShaderData that the shaders of a PainterImageBr...
file painter_brush_shader.hpp
c_array< const reference_counted_ptr< const Image > > bind_images(void) const override
unsigned int data_size(void) const override
file painter_brush_shader_data.hpp
void pack_data(c_array< uvec4 > dst) const override
atlas_location_encoding
Bit packing for the master index tile of a Image.
Base class to hold custom data for custom brush shaders.
PainterImageBrushShaderData & operator=(const PainterImageBrushShaderData &rhs)
PainterImageBrushShaderData(const PainterImageBrushShaderData &obj)
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 painter_enums.hpp
void sub_image(const reference_counted_ptr< const Image > &im, uvec2 xy, uvec2 wh)
const reference_counted_ptr< const Image > & image(void) const
Class to contain various enumerations needed for describing a brush.
file image.hpp