[dali_1.1.39] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / devel-api / rendering / renderer.h
1 #ifndef DALI_RENDERER_H
2 #define DALI_RENDERER_H
3
4 /*
5  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/handle.h> // Dali::Handle
23 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_OBJECT_PROPERTY_START_INDEX
24 #include <dali/devel-api/rendering/geometry.h> // Dali::Geometry
25 #include <dali/devel-api/rendering/texture-set.h> // Dali::TextureSet
26
27 namespace Dali
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 class Renderer;
33 }
34
35 namespace FaceCullingMode
36 {
37
38 /**
39  * @brief Set face culling mode.
40  * @SINCE_1_1.33
41  */
42 enum Type
43 {
44   NONE,                ///< None of the faces should be culled
45   FRONT,               ///< Cull front face, back face should never be shown
46   BACK,                ///< Cull back face, back face should never be shown
47   FRONT_AND_BACK,      ///< Cull front and back faces; if the geometry is composed of triangles none of the faces will be shown
48 };
49
50 } // namespace FaceCullingMode
51
52 namespace BlendMode
53 {
54
55 /**
56  * @brief Blend mode.
57  * @SINCE_1_1.33
58  */
59 enum Type
60 {
61   OFF,  ///< Blending is disabled. @SINCE_1_1.33
62   AUTO, ///< Blending is enabled if there is alpha channel. This is the default mode. @SINCE_1_1.33
63   ON    ///< Blending is enabled. @SINCE_1_1.33
64 };
65
66 } // namespace BlendMode
67
68 namespace BlendEquation
69 {
70 /**
71  * @brief Blend Equation.
72  *
73  * @SINCE_1_0.0
74  * @remarks This is an experimental feature and might not be supported in the next release.
75  * We do recommend not to use it.
76  */
77 enum Type
78 {
79   ADD              = 0x8006,  ///< The source and destination colors are added to each other. @SINCE_1_0.0
80   SUBTRACT         = 0x800A,  ///< Subtracts the destination from the source. @SINCE_1_0.0
81   REVERSE_SUBTRACT = 0x800B  ///< Subtracts the source from the destination. @SINCE_1_0.0
82 };
83
84 } // namespace BlendEquation
85
86 namespace BlendFactor
87 {
88 /**
89  * @brief Blend Factor.
90  *
91  * @SINCE_1_0.0
92  * @remarks This is an experimental feature and might not be supported in the next release.
93  * We do recommend not to use it.
94  */
95 enum Type
96 {
97   ZERO                     = 0,  ///< ZERO @SINCE_1_0.0
98   ONE                      = 1,  ///< ONE @SINCE_1_0.0
99   SRC_COLOR                = 0x0300,  ///< SRC_COLOR @SINCE_1_0.0
100   ONE_MINUS_SRC_COLOR      = 0x0301,  ///< ONE_MINUS_SRC_COLOR @SINCE_1_0.0
101   SRC_ALPHA                = 0x0302,  ///< SRC_ALPHA @SINCE_1_0.0
102   ONE_MINUS_SRC_ALPHA      = 0x0303,  ///< ONE_MINUS_SRC_ALPHA @SINCE_1_0.0
103   DST_ALPHA                = 0x0304,  ///< DST_ALPHA @SINCE_1_0.0
104   ONE_MINUS_DST_ALPHA      = 0x0305,  ///< ONE_MINUS_DST_ALPHA @SINCE_1_0.0
105   DST_COLOR                = 0x0306,  ///< DST_COLOR @SINCE_1_0.0
106   ONE_MINUS_DST_COLOR      = 0x0307,  ///< ONE_MINUS_DST_COLOR @SINCE_1_0.0
107   SRC_ALPHA_SATURATE       = 0x0308,  ///< SRC_ALPHA_SATURATE @SINCE_1_0.0
108   CONSTANT_COLOR           = 0x8001,  ///< CONSTANT_COLOR @SINCE_1_0.0
109   ONE_MINUS_CONSTANT_COLOR = 0x8002,  ///< ONE_MINUS_CONSTANT_COLOR @SINCE_1_0.0
110   CONSTANT_ALPHA           = 0x8003,  ///< CONSTANT_ALPHA @SINCE_1_0.0
111   ONE_MINUS_CONSTANT_ALPHA = 0x8004  ///< ONE_MINUS_CONSTANT_ALPHA @SINCE_1_0.0
112 };
113
114 } // namespace BlendFactor
115
116 namespace DepthWriteMode
117 {
118
119 /**
120  * @brief Depth buffer write modes
121  */
122 enum Type
123 {
124   OFF,  ///< Renderer doesn't write to the depth buffer
125   AUTO, ///< Renderer only writes to the depth buffer if it's opaque
126   ON    ///< Renderer writes to the depth buffer
127 };
128
129 } // namespace DepthWriteMode
130
131 namespace DepthTestMode
132 {
133
134 /**
135  * @brief Depth buffer test (reading) modes.
136  */
137 enum Type
138 {
139   OFF,  ///< Renderer does not read from the depth buffer @SINCE_1_1.38
140   AUTO, ///< Renderer only reads from the depth buffer if in a 3D layer @SINCE_1_1.38
141   ON    ///< Renderer reads from the depth buffer based on the DepthFunction @SINCE_1_1.38
142 };
143
144 } // namespace DepthTestMode
145
146 namespace DepthFunction
147 {
148
149 /**
150  * @brief Depth functions
151  */
152 enum Type
153 {
154   NEVER,        ///< Depth test never passes
155   ALWAYS,       ///< Depth test always passes
156   LESS,         ///< Depth test passes if the incoming depth value is less than the stored depth value
157   GREATER,      ///< Depth test passes if the incoming depth value is greater than the stored depth value
158   EQUAL,        ///< Depth test passes if the incoming depth value is equal to the stored depth value
159   NOT_EQUAL,    ///< Depth test passes if the incoming depth value is not equal to the stored depth value
160   LESS_EQUAL,   ///< Depth test passes if the incoming depth value is less than or equal to the stored depth value
161   GREATER_EQUAL ///< Depth test passes if the incoming depth value is greater than or equal to the stored depth value
162 };
163
164 } // namespace DepthFunction
165
166 /**
167  * @brief Renderer is a handle to an object used to show content by combining a Geometry, a TextureSet and a shader
168  */
169 class DALI_IMPORT_API Renderer : public Handle
170 {
171 public:
172
173   /**
174    * @brief An enumeration of properties belonging to the Renderer class.
175    */
176   struct Property
177   {
178     enum
179     {
180       /**
181        * @brief name "depthIndex", type INTEGER
182        * @note The default value is 0
183        */
184       DEPTH_INDEX = DEFAULT_OBJECT_PROPERTY_START_INDEX,
185
186       /**
187        * @brief name "faceCullingMode", type INTEGER
188        * @note The default value is FaceCullingMode::NONE
189        */
190       FACE_CULLING_MODE,
191
192       /**
193        * @brief name "blendMode", type INTEGER
194        * @note The default value is BlendMode::AUTO
195        */
196       BLEND_MODE,
197
198       /**
199        * @brief name "blendEquationRgb", type INTEGER
200        * @note The default value is BlendEquation::ADD
201        */
202       BLEND_EQUATION_RGB,
203
204       /**
205        * @brief name "blendEquationAlpha", type INTEGER
206        * @note The default value is BlendEquation::ADD
207        */
208       BLEND_EQUATION_ALPHA,
209
210       /**
211        * @brief name "blendFactorSrcRgb", type INTEGER
212        * @note The default value is BlendFactor::SRC_ALPHA
213        */
214       BLEND_FACTOR_SRC_RGB,
215
216       /**
217        * @brief name "blendFactorDestRgb", type INTEGER
218        * @note The default value is BlendFactor::ONE_MINUS_SRC_ALPHA
219        */
220       BLEND_FACTOR_DEST_RGB,
221
222       /**
223        * @brief name "blendFactorSrcAlpha", type INTEGER
224        * @note The default value is BlendFactor::ONE
225        */
226       BLEND_FACTOR_SRC_ALPHA,
227
228       /**
229        * @brief name "blendFactorDestAlpha", type INTEGER
230        * @note The default value is BlendFactor::ONE_MINUS_SRC_ALPHA
231        */
232       BLEND_FACTOR_DEST_ALPHA,
233
234       /**
235        * @brief name "blendColor", type VECTOR4
236        * @note The default value is Color::TRANSPARENT
237        */
238       BLEND_COLOR,
239
240       /**
241        * @brief name "blendPreMultipledAlpha", type BOOLEAN
242        * @note The default value is false
243        */
244       BLEND_PRE_MULTIPLIED_ALPHA,
245
246       /**
247        * @brief name "indexRangeFirst", type INTEGER
248        * @note The default value is 0
249        */
250       INDEX_RANGE_FIRST,
251
252       /**
253        * @brief name "indexRangeCount", type INTEGER
254        * @note The default (0) means that whole range of indices will be used
255        */
256       INDEX_RANGE_COUNT,
257
258       /**
259        * @brief name "depthWriteMode", type INTEGER
260        * @see DepthWriteMode
261        * @note The default value is DepthWriteMode::AUTO
262        */
263       DEPTH_WRITE_MODE,
264
265       /**
266        * @brief name "depthFunction", type INTEGER
267        * @see DepthFunction
268        * @note The default value is DepthFunction::LESS
269        */
270       DEPTH_FUNCTION,
271
272       /**
273        * @brief name "depthTestMode", type INTEGER
274        * @see DepthTestMode
275        * @note The default value is DepthTestMode::AUTO
276        * @SINCE_1_1.38
277        */
278       DEPTH_TEST_MODE
279     };
280   };
281
282   /**
283    * @brief Creates a new Renderer object
284    *
285    * @param[in] geometry Geometry to be used by this renderer
286    * @param[in] shader Shader to be used by this renderer
287    */
288   static Renderer New( Geometry& geometry, Shader& shader );
289
290   /**
291    * @brief Default constructor, creates an empty handle
292    */
293   Renderer();
294
295   /**
296    * @brief Destructor
297    */
298   ~Renderer();
299
300   /**
301    * @brief Copy constructor, creates a new handle to the same object
302    *
303    * @param[in] handle Handle to an object
304    */
305   Renderer( const Renderer& handle );
306
307   /**
308    * @brief Downcast to a renderer handle.
309    *
310    * If not a renderer the returned renderer handle is left uninitialized.
311    * @param[in] handle to an object
312    * @return renderer handle or an uninitialized handle
313    */
314   static Renderer DownCast( BaseHandle handle );
315
316   /**
317    * @brief Assignment operator, changes this handle to point at the same object
318    *
319    * @param[in] handle Handle to an object
320    * @return Reference to the assigned object
321    */
322   Renderer& operator=( const Renderer& handle );
323
324   /**
325    * @brief Sets the geometry to be used by this renderer
326    *
327    * @param[in] geometry The geometry to be used by this renderer
328    */
329   void SetGeometry( Geometry& geometry );
330
331   /**
332    * @brief Gets the geometry used by this renderer
333    *
334    * @return The geometry used by the renderer
335    */
336   Geometry GetGeometry() const;
337
338   /**
339    * @brief Sets effective range of indices to draw from bound index buffer
340    * @param [in] firstElement first element to draw
341    * @param [in] elementsCount number of elements to draw
342    */
343   inline void SetIndexRange( int firstElement, int elementsCount )
344   {
345     SetProperty( Property::INDEX_RANGE_FIRST, firstElement );
346     SetProperty( Property::INDEX_RANGE_COUNT, elementsCount );
347   }
348
349   /**
350    * @brief Sets the texture set to be used by this renderer
351    *
352    * @param[in] textureSet The texture set to be used by this renderer
353    */
354   void SetTextures( TextureSet& textureSet );
355
356   /**
357    * @brief Gets the texture set used by this renderer
358    *
359    * @return The texture set used by the renderer
360    */
361   TextureSet GetTextures() const;
362
363   /**
364    * @brief Set the shader used by this renderer
365    * @param[in] shader The shader to be used by this renderer
366    */
367   void SetShader( Shader& shader );
368
369   /**
370    * @brief Get the shader used by this renderer
371    * @return THe shader used by the renderer
372    */
373   Shader GetShader() const;
374
375 public:
376   /**
377    * @brief The constructor
378    *
379    * @param [in] pointer A pointer to a newly allocated Renderer
380    */
381   explicit DALI_INTERNAL Renderer( Internal::Renderer* pointer );
382 };
383
384 } //namespace Dali
385
386 #endif // DALI_RENDERER_H