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