FastUIDraw
painter_shader.hpp
Go to the documentation of this file.
1 /*!
2  * \file painter_shader.hpp
3  * \brief file painter_shader.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_SHADER_HPP
21 #define FASTUIDRAW_PAINTER_SHADER_HPP
23 
24 namespace fastuidraw
25 {
26  class PainterShaderRegistrar;
27 
28 /*!\addtogroup PainterShaders
29  * @{
30  */
31 
32  /*!
33  * \brief
34  * A PainterShader encapsulates how to draw or blend.
35  *
36  * The real meat of a PainterShader is dependent
37  * on the backend. Typically it is a shader source
38  * code -fragment- that is placed into a large uber-shader.
39  */
41  public reference_counted<PainterShader>::concurrent
42  {
43  public:
44  /*!
45  * \brief
46  * A Tag is how a PainterShader is described for
47  * and by a PainterShaderRegistrar.
48  */
49  class Tag
50  {
51  public:
52  /*!
53  * Ctor, initializes \ref m_ID and \ref m_group
54  * to 0.
55  */
56  Tag(void):
57  m_ID(0),
58  m_group(0)
59  {}
60 
61  /*!
62  * The ID of a PainterShader is unique.
63  * Typically, \ref m_ID is used in a switch
64  * statement of an uber-shader.
65  */
66  uint32_t m_ID;
67 
68  /*!
69  * The group of a PainterShader is
70  * used to classify PainterShader objects
71  * into groups for the cases when draw call breaks
72  * are needed either to improve performance (to
73  * prevent divergent branching in shaders) or to
74  * insert API state changes. The value 0 is used
75  * to indicate "default" shader group. The nullptr
76  * shader belongs to group 0.
77  */
78  uint32_t m_group;
79  };
80 
81  /*!
82  * Ctor for creating a PainterShader which has multiple
83  * sub-shaders. The purpose of sub-shaders is for the
84  * case where multiple shaders almost same code and those
85  * code differences can be realized by examining a sub-shader
86  * ID.
87  * \param num_sub_shaders number of sub-shaders
88  */
89  explicit
90  PainterShader(unsigned int num_sub_shaders = 1);
91 
92  /*!
93  * Ctor to create a PainterShader realized as a sub-shader
94  * of an existing PainterShader.
95  * \param parent parent PainterShader that has sub-shaders.
96  * \param sub_shader which sub-shader of the parent PainterShader
97  * The parent PainterShader MUST already be registered
98  * to a PainterShaderRegistrar.
99  */
101  unsigned int sub_shader);
102 
103  virtual
104  ~PainterShader();
105 
106  /*!
107  * Returns the number of sub-shaders the PainterShader
108  * supports.
109  */
110  unsigned int
111  number_sub_shaders(void) const;
112 
113  /*!
114  * If the PainterShader is a sub-shader returns the parent
115  * shader, otherwise returns nullptr.
116  */
118  parent(void) const;
119 
120  /*!
121  * Returns the sub-shader value as passed in ctor if
122  * a sub-shader, otherwise returns 0.
123  */
124  uint32_t
125  sub_shader(void) const;
126 
127  /*!
128  * Returns the ID of the shader, the shader
129  * must be registered to the passed \ref
130  * PainterShaderRegistrar to have an ID
131  * value for the passed registrar.
132  */
133  uint32_t
134  ID(const PainterShaderRegistrar&) const;
135 
136  /*!
137  * Returns the shader group to which the shader belongs.
138  * A different value in group() triggers a call to
139  * PainterDraw:draw_break() to note that the shader
140  * group changed. The shader must be registered to the
141  * passed \ref PainterShaderRegistrar to have a value
142  * from the registrar.
143  */
144  uint32_t
145  group(const PainterShaderRegistrar&) const;
146 
147  /*!
148  * Returns the Tag of the shader which holds
149  * the value for ID() in Tag::m_ID and group()
150  * in Tag::m_group. The shader must be registered
151  * to the passed \ref PainterShaderRegistrar to
152  * have a Tag value from the registrar.
153  */
154  Tag
155  tag(const PainterShaderRegistrar&) const;
156 
157  /*!
158  * Returns true if this shader has been registered
159  * the the passed \ref PainterShaderRegistrar.
160  */
161  bool
163 
164  private:
165  friend class PainterShaderRegistrar;
166 
167  /*!
168  * Called by a PainterShaderRegistrar to register the shader to it.
169  */
170  void
171  register_shader(Tag tg, const PainterShaderRegistrar &p);
172 
173  /*!
174  * Called by PainterShaderRegistrar to set the group for a shader.
175  */
176  void
177  set_group_of_sub_shader(const PainterShaderRegistrar &p, uint32_t group);
178 
179  void *m_d;
180  };
181 
182 /*! @} */
183 }
184 
185 #endif
uint32_t group(const PainterShaderRegistrar &) const
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A PainterShader encapsulates how to draw or blend.
A wrapper over a pointer to implement reference counting.
bool registered_to(const PainterShaderRegistrar &) const
PainterShader(unsigned int num_sub_shaders=1)
A Tag is how a PainterShader is described for and by a PainterShaderRegistrar.
A PainterShaderRegistrar is an interface that defines the assigning of PainterShader::ID() to a Paint...
uint32_t sub_shader(void) const
unsigned int number_sub_shaders(void) const
Defines default reference counting base classes.
uint32_t ID(const PainterShaderRegistrar &) const
const reference_counted_ptr< PainterShader > & parent(void) const
Tag tag(const PainterShaderRegistrar &) const
file reference_counted.hpp