FastUIDraw
painter_image_brush_shader.hpp
Go to the documentation of this file.
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_HPP
20 #define FASTUIDRAW_PAINTER_IMAGE_BRUSH_SHADER_HPP
21 
22 #include <fastuidraw/painter/painter_custom_brush.hpp>
23 #include <fastuidraw/painter/shader_data/painter_image_brush_shader_data.hpp>
25 
26 namespace fastuidraw
27 {
28 
29 /*!\addtogroup PainterShaders
30  * @{
31  */
32 
33  /*!
34  * \brief
35  * A \ref PainterImageBrushShader represents a single \ref
36  * PainterBrushShader together with sub-shaders of it that
37  * can be used to apply an \ref Image. The sub-shader ID is
38  * used to describe the \ref Image::type(), \ref Image::format(),
39  * what filtering and mipmapping to apply to the image data.
40  */
42  public reference_counted<PainterImageBrushShader>::concurrent,
43  public PainterBrushEnums
44  {
45  public:
46  /*!
47  * \brief
48  * Enumeration describing the roles of the bits for
49  * the sub-shader ID's.
50  */
52  {
53  /*!
54  * Number of bits needed to encode filter for image.
55  * A value of 0 indicates no image applied, a non-zero
56  * value indicates an image applied and the value
57  * specifies what filter via the enumeration \ref
58  * PainterBrushEnums::filter_t.
59  */
61 
62  /*!
63  * Number of bits used to encode number of mipmap
64  * levels (when an image is present).
65  */
67 
68  /*!
69  * Number of bits needed to encode the image type
70  * (when an image is present). The possible values
71  * are given by the enumeration \ref Image::type_t.
72  */
74 
75  /*!
76  * Number of bits needed to encode the value of
77  * Image::format().
78  */
80 
81  /*!
82  * first bit for if image is present on the brush and if so, what filter
83  */
85 
86  /*!
87  * first bit to indicate maximum mipmap level to use
88  */
90 
91  /*!
92  * First bit to hold the type of image present if an image is present;
93  * the value is the enumeration in \ref Image::type_t
94  */
96 
97  /*!
98  * First bit to encode \ref Image::format_t
99  */
101 
102  /*!
103  * The total number of bits needed to specify the sub-shader IDs.
104  */
106 
107  /*!
108  * the total number of sub-shaders
109  */
111  };
112 
113  /*!
114  * Various bit-mask values derived from \ref sub_shader_bits
115  */
117  {
118  /*!
119  * mask generated from \ref filter_bit0 and \ref filter_num_bits
120  */
122 
123  /*!
124  * mask generated from \ref mipmap_bit0 and \ref mipmap_num_bits
125  */
127 
128  /*!
129  * mask generated from \ref type_bit0 and \ref type_num_bits
130  */
132 
133  /*!
134  * mask generated from \ref format_bit0 and \ref format_num_bits
135  */
137  };
138 
139  /*!
140  * Ctor.
141  * \param parent_shader the parent \ref PainterBrushShader that implements
142  * image-brush shading and has \ref number_sub_shaders
143  * that implement brush shading where the I'th sub-shader
144  * implement brush shading as described by extracting
145  * from the bits of I the values as encoded by \ref
146  * sub_shader_bits
147  */
148  explicit
150 
152 
153  /*!
154  * \param image \ref Image from which the brush-image
155  * will source; a nullptr value indicates
156  * no image and the brush-image will emit
157  * constant color white fully opaque
158  * \param image_filter filtering to apply to image
159  * \param mip_mapping mipmapping to apply to image
160  */
162  sub_shader(const Image *image,
163  enum filter_t image_filter,
164  enum mipmap_t mip_mapping) const;
165 
166  /*!
167  * returns all the sub-shaders of the \ref PainterImageBrushShader
168  */
170  sub_shaders(void) const;
171 
172  /*!
173  * Create a \ref PainterCustomBrush with packed data to brush
174  * by sourcing from a sub-rectangle of an Image.
175  * \param pool \ref PainterPackedValuePool used to create the packed value
176  * \param image \ref Image from which to source
177  * \param xy minx-miny corner of sub-rectangle
178  * \param wh width and height of sub-rectangle
179  * \param image_filter filtering to apply to image
180  * \param mip_mapping mipmapping to apply to image
181  */
185  uvec2 xy, uvec2 wh,
186  enum filter_t image_filter = filter_linear,
187  enum mipmap_t mip_mapping = apply_mipmapping) const;
188 
189  /*!
190  * Create a \ref PainterCustomBrush with packed data to brush
191  * by sourcing from the entirity of an Image.
192  * \param pool \ref PainterPackedValuePool used to create the packed value
193  * \param image \ref Image from which to source
194  * \param image_filter filtering to apply to image
195  * \param mip_mapping mipmapping to apply to image
196  */
200  enum filter_t image_filter = filter_linear,
201  enum mipmap_t mip_mapping = apply_mipmapping) const;
202 
203  /*!
204  * Produce the sub-shader ID from what \ref Image
205  * and how to sample from the image.
206  * \param image \ref Image from which the brush-image
207  * will source; a nullptr value indicates
208  * no image and the brush-image will emit
209  * constant color white fully opaque
210  * \param image_filter filtering to apply to image
211  * \param mip_mapping mipmapping to apply to image
212  */
213  static
214  uint32_t
215  sub_shader_id(const Image *image,
216  enum filter_t image_filter,
217  enum mipmap_t mip_mapping);
218 
219  private:
220  void *m_d;
221  };
222 
223 /*! @} */
224 }
225 
226 #endif
#define FASTUIDRAW_MASK(BIT0, NUMBITS)
Definition: util.hpp:59
A PainterPackedValuePool can be used to create PainterPackedValue objects.
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
A PainterImageBrushShader represents a single PainterBrushShader together with sub-shaders of it that...
file painter_brush_shader.hpp
An Image represents an image comprising of RGBA8 values. The texel values themselves are stored in a ...
Definition: image.hpp:44
sub_shader_bits
Enumeration describing the roles of the bits for the sub-shader ID&#39;s.
A PainterCustomBrush is just a conveniance to wrap a pointer to a PainterBrushShader together with a ...
static uint32_t sub_shader_id(const Image *image, enum filter_t image_filter, enum mipmap_t mip_mapping)
PainterCustomBrush create_brush(PainterPackedValuePool &pool, const reference_counted_ptr< const Image > &image, uvec2 xy, uvec2 wh, enum filter_t image_filter=filter_linear, enum mipmap_t mip_mapping=apply_mipmapping) const
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
c_array< const reference_counted_ptr< PainterBrushShader > > sub_shaders(void) const
Defines default reference counting base classes.
filter_t
Enumeration specifying what filter to apply to an image.
PainterImageBrushShader(const reference_counted_ptr< PainterBrushShader > &parent_shader)
const reference_counted_ptr< PainterBrushShader > & sub_shader(const Image *image, enum filter_t image_filter, enum mipmap_t mip_mapping) const
Class to contain various enumerations needed for describing a brush.