Merge branch 'devel/master (1.2.0)' into tizen
[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) 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/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/internal/common/blending-options.h>
26 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
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   Geometry* GetGeometry() const;
67
68   /**
69    * @copydoc Dali::Renderer::SetTextures()
70    */
71   void SetTextures( TextureSet& textureSet );
72
73   /**
74    * @copydoc Dali::Renderer::GetTextures()
75    */
76   TextureSet* GetTextures() const;
77
78   /**
79    * @copydoc Dali::Renderer::SetShader()
80    */
81   void SetShader( Shader& shader );
82
83   /**
84    * @copydoc Dali::Renderer::GetShader()
85    */
86   Shader* GetShader() const;
87
88   /**
89    * @copydoc Dali::Renderer::SetDepthIndex()
90    */
91   void SetDepthIndex( int depthIndex );
92
93   /**
94    * @copydoc Dali::Renderer::GetDepthIndex()
95    */
96   int 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::SetBlendColor()
142     */
143    void SetBlendColor( const Vector4& color );
144
145    /**
146     * @copydoc Dali::Renderer::GetBlendColor()
147     */
148    Vector4 GetBlendColor() const;
149
150    /**
151     * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
152     */
153    void SetIndexedDrawFirstElement( size_t firstElement );
154
155    /**
156     * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
157     */
158    void SetIndexedDrawElementsCount( size_t elementsCount );
159
160    /**
161     * @brief Set whether the Pre-multiplied Alpha Blending is required
162     *
163     * @param[in] preMultipled whether alpha is pre-multiplied.
164     */
165    void EnablePreMultipliedAlpha( bool preMultipled );
166
167    /**
168     * @brief Query whether alpha is pre-multiplied.
169     *
170     * @return True is alpha is pre-multiplied, false otherwise.
171     */
172    bool IsPreMultipliedAlphaEnabled() const;
173
174    /**
175     * Returns state of batching mode
176     * @return batching mode state ( true if enabled )
177     */
178    bool IsBatchingEnabled() const;
179
180    /**
181     * @brief Get the scene graph object
182     *
183     * @return the scene object
184     */
185    SceneGraph::Renderer* GetRendererSceneObject();
186
187 public: // Default property extensions from Object
188
189   /**
190    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
191    */
192   virtual unsigned int GetDefaultPropertyCount() const;
193
194   /**
195    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
196    */
197   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
198
199   /**
200    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
201    */
202   virtual const char* GetDefaultPropertyName(Property::Index index) const;
203
204   /**
205    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
206    */
207   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
208
209   /**
210    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
211    */
212   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
213
214   /**
215    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
216    */
217   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
218
219   /**
220    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
221    */
222   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
223
224   /**
225    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
226    */
227   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
228
229   /**
230    * @copydoc Dali::Internal::Object::SetDefaultProperty()
231    */
232   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
233
234   /**
235    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
236    */
237   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
238
239   /**
240    * @copydoc Dali::Internal::Object::GetDefaultProperty()
241    */
242   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
243
244   /**
245    * @copydoc Dali::Internal::Object::GetPropertyOwner()
246    */
247   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
248
249   /**
250    * @copydoc Dali::Internal::Object::GetSceneObject()
251    */
252   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
253
254   /**
255    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
256    */
257   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
258
259   /**
260    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
261    */
262   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
263
264   /**
265    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
266    */
267   virtual int GetPropertyComponentIndex( Property::Index index ) const;
268
269 public: // Functions from Connectable
270   /**
271    * @copydoc Dali::Internal::Connectable::OnStage()
272    */
273   virtual bool OnStage() const;
274
275   /**
276    * @copydoc Dali::Internal::Connectable::Connect()
277    */
278   virtual void Connect();
279
280   /**
281    * @copydoc Dali::Internal::Connectable::Disconnect()
282    */
283   virtual void Disconnect();
284
285 private: // implementation
286   Renderer();
287
288   void Initialize();
289
290 protected:
291   /**
292    * A reference counted object may only be deleted by calling Unreference()
293    */
294   virtual ~Renderer();
295
296 private: // unimplemented methods
297   Renderer( const Renderer& );
298   Renderer& operator=( const Renderer& );
299
300 private: // data
301   SceneGraph::Renderer* mSceneObject;
302   Vector4* mBlendColor;                                       ///< Local copy of blend color, pointer only as its rarely used
303   GeometryPtr mGeometry;                                      ///< Connector that holds the geometry used by this renderer
304   ObjectConnector<TextureSet> mTextureSetConnector;           ///< Connector that holds the texture set used by this renderer
305   IntrusivePtr<Shader> mShader;                               ///< Connector that holds the shader used by this renderer
306
307   int mDepthIndex;
308   int mOnStageCount;
309
310   size_t mIndexedDrawFirstElement;                            ///< Offset of first element to draw from bound index buffer
311   size_t mIndexedDrawElementCount;                            ///< Number of elements to draw
312
313   Render::Renderer::StencilParameters mStencilParameters;     ///< Struct containing all stencil related options
314   BlendingOptions              mBlendingOptions;              ///< Local copy of blending options bitmask
315
316   DepthFunction::Type          mDepthFunction:3;              ///< Local copy of the depth function
317   FaceCullingMode::Type        mFaceCullingMode:2;            ///< Local copy of the mode of face culling
318   BlendMode::Type              mBlendMode:2;                  ///< Local copy of the mode of blending
319   DepthWriteMode::Type         mDepthWriteMode:2;             ///< Local copy of the depth write mode
320   DepthTestMode::Type          mDepthTestMode:2;              ///< Local copy of the depth test mode
321   bool                         mWriteToColorBuffer:1;         ///< Local copy of the write to color buffer flag
322   bool                         mPremultipledAlphaEnabled:1;   ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
323   bool                         mBatchingEnabled : 1;          ///< Flag indicating whether render is batchable or not
324 };
325
326 } // namespace Internal
327
328 // Helpers for public-api forwarding methods
329 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
330 {
331   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
332
333   BaseObject& object = handle.GetBaseObject();
334
335   return static_cast<Internal::Renderer&>(object);
336 }
337
338 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
339 {
340   DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
341
342   const BaseObject& object = handle.GetBaseObject();
343
344   return static_cast<const Internal::Renderer&>(object);
345 }
346
347 } // namespace Dali
348
349 #endif // DALI_INTERNAL_RENDERER_H