Renderer property enum clean-up
[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/actors/blending.h> // Dali::BlendingMode, Dali::BlendingEquation, Dali::BlendingFactor
23 #include <dali/public-api/object/handle.h> // Dali::Handle
24 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_OBJECT_PROPERTY_START_INDEX
25 #include <dali/devel-api/rendering/geometry.h> // Dali::Geometry
26 #include <dali/devel-api/rendering/texture-set.h> // Dali::TextureSet
27
28 namespace Dali
29 {
30
31 namespace Internal DALI_INTERNAL
32 {
33 class Renderer;
34 }
35
36 /**
37  * @brief Renderer is a handle to an object used to show content by combining a Geometry, a TextureSet and a shader
38  */
39 class DALI_IMPORT_API Renderer : public Handle
40 {
41 public:
42
43   /**
44    * @brief Set face culling mode.
45    */
46   enum FaceCullingMode
47   {
48     NONE,                     ///< None of the faces should be culled
49     CULL_FRONT,               ///< Cull front face, back face should never be shown
50     CULL_BACK,                ///< Cull back face, back face should never be shown
51     CULL_BACK_AND_FRONT,      ///< Cull back and front faces, if the geometry is composed of triangles none of the faces will be shown
52   };
53
54   /**
55    * @brief An enumeration of properties belonging to the Renderer class.
56    */
57   struct Property
58   {
59     enum
60     {
61       DEPTH_INDEX = DEFAULT_OBJECT_PROPERTY_START_INDEX,  ///< name "depthIndex",                     type INTEGER
62       FACE_CULLING_MODE,                                  ///< name "faceCullingMode",                type INTEGER
63       BLENDING_MODE,                                      ///< name "blendingMode",                   type INTEGER
64       BLEND_EQUATION_RGB,                                 ///< name "blendEquationRgb",               type INTEGER
65       BLEND_EQUATION_ALPHA,                               ///< name "blendEquationAlpha",             type INTEGER
66       BLENDING_SRC_FACTOR_RGB,                            ///< name "sourceBlendFactorRgb",           type INTEGER
67       BLENDING_DEST_FACTOR_RGB,                           ///< name "destinationBlendFactorRgb",      type INTEGER
68       BLENDING_SRC_FACTOR_ALPHA,                          ///< name "sourceBlendFactorAlpha",         type INTEGER
69       BLENDING_DEST_FACTOR_ALPHA,                         ///< name "destinationBlendFactorAlpha",    type INTEGER
70       BLENDING_COLOR,                                     ///< name "blendingColor",                  type VECTOR4
71       BLEND_PRE_MULTIPLIED_ALPHA,                         ///< name "blendPreMultipledAlpha",         type BOOLEAN
72       INDEX_RANGE_FIRST,                                  ///< name "indexRangeFirst",                type INTEGER
73       INDEX_RANGE_COUNT                                   ///< name "indexRangeCount",                type INTEGER
74     };
75   };
76
77   /**
78    * @brief Creates a new Renderer object
79    *
80    * @param[in] geometry Geometry to be used by this renderer
81    * @param[in] shader Shader to be used by this renderer
82    */
83   static Renderer New( Geometry& geometry, Shader& shader );
84
85   /**
86    * @brief Default constructor, creates an empty handle
87    */
88   Renderer();
89
90   /**
91    * @brief Destructor
92    */
93   ~Renderer();
94
95   /**
96    * @brief Copy constructor, creates a new handle to the same object
97    *
98    * @param[in] handle Handle to an object
99    */
100   Renderer( const Renderer& handle );
101
102   /**
103    * @brief Downcast to a renderer handle.
104    *
105    * If not a renderer the returned renderer handle is left uninitialized.
106    * @param[in] handle to an object
107    * @return renderer handle or an uninitialized handle
108    */
109   static Renderer DownCast( BaseHandle handle );
110
111   /**
112    * @brief Assignment operator, changes this handle to point at the same object
113    *
114    * @param[in] handle Handle to an object
115    * @return Reference to the assigned object
116    */
117   Renderer& operator=( const Renderer& handle );
118
119   /**
120    * @brief Sets the geometry to be used by this renderer
121    *
122    * @param[in] geometry The geometry to be used by this renderer
123    */
124   void SetGeometry( Geometry& geometry );
125
126   /**
127    * @brief Gets the geometry used by this renderer
128    *
129    * @return The geometry used by the renderer
130    */
131   Geometry GetGeometry() const;
132
133   /**
134    * @brief Sets effective range of indices to draw from bound index buffer
135    * @param [in] firstElement first element to draw
136    * @param [in] elementsCount number of elements to draw
137    */
138   inline void SetIndexRange( int firstElement, int elementsCount )
139   {
140     SetProperty( Property::INDEX_RANGE_FIRST, firstElement );
141     SetProperty( Property::INDEX_RANGE_COUNT, elementsCount );
142   }
143
144   /**
145    * @brief Sets the texture set to be used by this renderer
146    *
147    * @param[in] textureSet The texture set to be used by this renderer
148    */
149   void SetTextures( TextureSet& textureSet );
150
151   /**
152    * @brief Gets the texture set used by this renderer
153    *
154    * @return The texture set used by the renderer
155    */
156   TextureSet GetTextures() const;
157
158   /**
159    * @brief Set the shader used by this renderer
160    * @param[in] shader The shader to be used by this renderer
161    */
162   void SetShader( Shader& shader );
163
164   /**
165    * @brief Get the shader used by this renderer
166    * @return THe shader used by the renderer
167    */
168   Shader GetShader() const;
169
170   /**
171    * @brief Specify the pixel arithmetic used when the actor is blended.
172    *
173    * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
174    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
175    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
176    * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
177    *
178    * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
179    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
180    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
181    * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
182    */
183   void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
184
185   /**
186    * @brief Specify the pixel arithmetic used when the actor is blended.
187    *
188    * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
189    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
190    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
191    * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
192    *
193    * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
194    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
195    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
196    * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
197    *
198    * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
199    * The options are the same as for srcFactorRgb.
200    *
201    * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
202    * The options are the same as for destFactorRgb.
203    */
204   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
205                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
206
207   /**
208    * @brief Query the pixel arithmetic used when the actor is blended.
209    *
210    * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
211    * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
212    * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
213    * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
214    */
215   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
216                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
217
218   /**
219    * @brief Specify the equation used when the actor is blended.
220    *
221    * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
222    * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
223    */
224   void SetBlendEquation( BlendingEquation::Type equationRgba );
225
226   /**
227    * @brief Specify the equation used when the actor is blended.
228    *
229    * @param[in] equationRgb The equation used for combining red, green, and blue components.
230    * @param[in] equationAlpha The equation used for combining the alpha component.
231    * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
232    */
233   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
234
235   /**
236    * @brief Query the equation used when the actor is blended.
237    *
238    * @param[out] equationRgb The equation used for combining red, green, and blue components.
239    * @param[out] equationAlpha The equation used for combining the alpha component.
240    */
241   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
242
243 public:
244   /**
245    * @brief The constructor
246    *
247    * @param [in] pointer A pointer to a newly allocated Renderer
248    */
249   explicit DALI_INTERNAL Renderer( Internal::Renderer* pointer );
250 };
251
252 } //namespace Dali
253
254 #endif // DALI_RENDERER_H