3a361869b4f5040c7f776e70bbe02e2b4285ec84
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / renderer-impl.h
1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_RENDERER_H
3
4 /*
5  * Copyright (c) 2018 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/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/rendering/renderer.h> // Dali::Renderer
25 #include <dali/devel-api/rendering/renderer-devel.h>
26 #include <dali/internal/common/blending-options.h>
27 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
28 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
29 #include <dali/internal/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
30 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
31 #include <dali/internal/render/renderers/render-renderer.h> // Dali::Render::Renderer::StencilParameters
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 namespace SceneGraph
38 {
39 class Renderer;
40 }
41
42 class Renderer;
43 typedef IntrusivePtr<Renderer> RendererPtr;
44
45 /**
46  * Renderer is an object that can be used to show content by combining a Geometry with a shader and textures.
47  */
48 class Renderer : public Object
49 {
50 public:
51
52   /**
53    * Create a new Renderer.
54    * @return A smart-pointer to the newly allocated Renderer.
55    */
56   static RendererPtr New();
57
58   /**
59    * @copydoc Dali::Renderer::SetGeometry()
60    */
61   void SetGeometry( Geometry& geometry );
62
63   /**
64    * @copydoc Dali::Renderer::GetGeometry()
65    */
66   GeometryPtr GetGeometry() const;
67
68   /**
69    * @copydoc Dali::Renderer::SetTextures()
70    */
71   void SetTextures( TextureSet& textureSet );
72
73   /**
74    * @copydoc Dali::Renderer::GetTextures()
75    */
76   TextureSetPtr GetTextures() const;
77
78   /**
79    * @copydoc Dali::Renderer::SetShader()
80    */
81   void SetShader( Shader& shader );
82
83   /**
84    * @copydoc Dali::Renderer::GetShader()
85    */
86   ShaderPtr GetShader() const;
87
88   /**
89    * @copydoc Dali::Renderer::SetDepthIndex()
90    */
91   void SetDepthIndex( int32_t depthIndex );
92
93   /**
94    * @copydoc Dali::Renderer::GetDepthIndex()
95    */
96   int32_t GetDepthIndex() const;
97
98   /**
99    * @copydoc Dali::Renderer::SetBlendMode()
100    */
101   void SetBlendMode( BlendMode::Type mode );
102
103   /**
104    * @copydoc Dali::Renderer::GetBlendMode()
105    */
106   BlendMode::Type GetBlendMode() const;
107
108   /**
109    * @copydoc Dali::Renderer::SetBlendFunc()
110    */
111   void SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba );
112
113   /**
114    * @copydoc Dali::Renderer::SetBlendFunc()
115    */
116   void SetBlendFunc( BlendFactor::Type srcFactorRgb,   BlendFactor::Type destFactorRgb,
117                      BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
118
119   /**
120    * @copydoc Dali::Renderer::GetBlendFunc()
121    */
122   void GetBlendFunc( BlendFactor::Type& srcFactorRgb,   BlendFactor::Type& destFactorRgb,
123                     BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha ) const;
124
125   /**
126    * @copydoc Dali::Renderer::SetBlendEquation()
127    */
128   void SetBlendEquation( BlendEquation::Type equationRgba );
129
130   /**
131    * @copydoc Dali::Renderer::SetBlendEquation()
132    */
133   void SetBlendEquation( BlendEquation::Type equationRgb, BlendEquation::Type equationAlpha );
134
135   /**
136    * @copydoc Dali::Renderer::GetBlendEquation()
137    */
138   void GetBlendEquation( BlendEquation::Type& equationRgb, BlendEquation::Type& equationAlpha ) const;
139
140   /**
141    * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
142    */
143   void SetIndexedDrawFirstElement( uint32_t firstElement );
144
145   /**
146    * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
147    */
148   void SetIndexedDrawElementsCount( uint32_t elementsCount );
149
150   /**
151    * @brief Set whether the Pre-multiplied Alpha Blending is required
152    *
153    * @param[in] preMultipled whether alpha is pre-multiplied.
154    */
155   void EnablePreMultipliedAlpha( bool preMultipled );
156
157   /**
158    * @brief Query whether alpha is pre-multiplied.
159    *
160    * @return True is alpha is pre-multiplied, false otherwise.
161    */
162   bool IsPreMultipliedAlphaEnabled() const;
163
164   /**
165    * @brief Get the scene graph object
166    *
167    * @return the scene object
168    */
169   const SceneGraph::Renderer& GetRendererSceneObject() const;
170
171 public: // Default property extensions from Object
172
173   /**
174    * @copydoc Dali::Internal::Object::SetDefaultProperty()
175    */
176   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
177
178   /**
179    * @copydoc Dali::Internal::Object::GetDefaultProperty()
180    */
181   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
182
183   /**
184    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
185    */
186   virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
187
188    /**
189     * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
190     */
191    virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType );
192
193   /**
194    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
195    */
196   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
197
198   /**
199    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
200    */
201   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
202
203   /**
204    * @brief Adds a draw command to the Renderer.
205    * DrawCommands override Renderer's default behaviour.
206    *
207    * @param[in] command Valid reference to a DrawCommand objects
208    */
209   void AddDrawCommand( const Dali::DevelRenderer::DrawCommand& command );
210
211 private: // implementation
212
213   /**
214    * @brief Constructor.
215    *
216    * @param sceneObject the scene graph renderer
217    */
218   Renderer( const SceneGraph::Renderer* sceneObject );
219
220   /**
221    * @brief Sets the blend color.
222    * @param[in] blendColor The blend color to set.
223    */
224   void SetBlendColor( const Vector4& blendColor );
225
226   /**
227    * @brief Retrieves the blend-color.
228    * @return A const reference to the blend-color
229    */
230   const Vector4& GetBlendColor() const;
231
232   /**
233    * @brief Retrieves the cached event side value of a default property.
234    * @param[in]  index  The index of the property
235    * @param[out] value  Is set with the cached value of the property if found.
236    * @return True if value set, false otherwise.
237    */
238   bool GetCachedPropertyValue( Property::Index index, Property::Value& value ) const;
239
240   /**
241    * @brief Retrieves the current value of a default property from the scene-graph.
242    * @param[in]  index  The index of the property
243    * @param[out] value  Is set with the current scene-graph value of the property
244    * @return True if value set, false otherwise.
245    */
246   bool GetCurrentPropertyValue( Property::Index index, Property::Value& value  ) const;
247
248 protected:
249   /**
250    * A reference counted object may only be deleted by calling Unreference()
251    */
252   virtual ~Renderer();
253
254 private: // unimplemented methods
255   Renderer( const Renderer& );
256   Renderer& operator=( const Renderer& );
257
258 private: // data
259
260   GeometryPtr                         mGeometry;                   ///< Intrusive pointer to the geometry used by this renderer
261   TextureSetPtr                       mTextureSet;                 ///< Intrusive pointer to the texture set used by this renderer
262   ShaderPtr                           mShader;                     ///< Intrusive pointer to the shader used by this renderer
263
264   int32_t                             mDepthIndex;
265
266   uint32_t                            mIndexedDrawFirstElement;    ///< Offset of first element to draw from bound index buffer
267   uint32_t                            mIndexedDrawElementCount;    ///< Number of elements to draw
268
269   Render::Renderer::StencilParameters mStencilParameters;          ///< Struct containing all stencil related options
270   BlendingOptions                     mBlendingOptions;            ///< Local copy of blending options bitmask
271
272   float                               mOpacity;                    ///< Local copy of the opacity
273   DepthFunction::Type                 mDepthFunction:4;            ///< Local copy of the depth function
274   FaceCullingMode::Type               mFaceCullingMode:3;          ///< Local copy of the mode of face culling
275   BlendMode::Type                     mBlendMode:3;                ///< Local copy of the mode of blending
276   DepthWriteMode::Type                mDepthWriteMode:3;           ///< Local copy of the depth write mode
277   DepthTestMode::Type                 mDepthTestMode:3;            ///< Local copy of the depth test mode
278   DevelRenderer::Rendering::Type      mRenderingBehavior:2;        ///< The rendering behavior
279   bool                                mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
280
281   std::vector<Dali::DevelRenderer::DrawCommand> mDrawCommands;     ///< list of draw commands
282 };
283
284 } // namespace Internal
285
286 // Helpers for public-api forwarding methods
287 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
288 {
289   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
290
291   BaseObject& object = handle.GetBaseObject();
292
293   return static_cast<Internal::Renderer&>(object);
294 }
295
296 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
297 {
298   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
299
300   const BaseObject& object = handle.GetBaseObject();
301
302   return static_cast<const Internal::Renderer&>(object);
303 }
304
305 } // namespace Dali
306
307 #endif // DALI_INTERNAL_RENDERER_H