Merge "Added property to Renderer to specify the depth function" into devel/master
[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/devel-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
32 namespace Dali
33 {
34 namespace Internal
35 {
36 namespace SceneGraph
37 {
38 class Renderer;
39 }
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::SetFaceCullingMode()
100     */
101    void SetFaceCullingMode( FaceCullingMode::Type cullingMode );
102
103    /**
104     * @copydoc Dali::Renderer::GetFaceCullingMode()
105     */
106    FaceCullingMode::Type GetFaceCullingMode();
107
108    /**
109     * @copydoc Dali::Renderer::SetBlendMode()
110     */
111    void SetBlendMode( BlendMode::Type mode );
112
113    /**
114     * @copydoc Dali::Renderer::GetBlendMode()
115     */
116    BlendMode::Type GetBlendMode() const;
117
118    /**
119     * @copydoc Dali::Renderer::SetBlendFunc()
120     */
121    void SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba );
122
123    /**
124     * @copydoc Dali::Renderer::SetBlendFunc()
125     */
126    void SetBlendFunc( BlendFactor::Type srcFactorRgb,   BlendFactor::Type destFactorRgb,
127                       BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
128
129    /**
130     * @copydoc Dali::Renderer::GetBlendFunc()
131     */
132    void GetBlendFunc( BlendFactor::Type& srcFactorRgb,   BlendFactor::Type& destFactorRgb,
133                       BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha ) const;
134
135    /**
136     * @copydoc Dali::Renderer::SetBlendEquation()
137     */
138    void SetBlendEquation( BlendEquation::Type equationRgba );
139
140    /**
141     * @copydoc Dali::Renderer::SetBlendEquation()
142     */
143    void SetBlendEquation( BlendEquation::Type equationRgb, BlendEquation::Type equationAlpha );
144
145    /**
146     * @copydoc Dali::Renderer::GetBlendEquation()
147     */
148    void GetBlendEquation( BlendEquation::Type& equationRgb, BlendEquation::Type& equationAlpha ) const;
149
150    /**
151     * @copydoc Dali::Renderer::SetBlendColor()
152     */
153    void SetBlendColor( const Vector4& color );
154
155    /**
156     * @copydoc Dali::Renderer::GetBlendColor()
157     */
158    Vector4 GetBlendColor() const;
159
160    /**
161     * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
162     */
163    void SetIndexedDrawFirstElement( size_t firstElement );
164
165    /**
166     * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
167     */
168    void SetIndexedDrawElementsCount( size_t elementsCount );
169
170    /**
171     * @brief Set whether the Pre-multiplied Alpha Blending is required
172     *
173     * @param[in] preMultipled whether alpha is pre-multiplied.
174     */
175    void EnablePreMultipliedAlpha( bool preMultipled );
176
177    /**
178     * @brief Query whether alpha is pre-multiplied.
179     *
180     * @return True is alpha is pre-multiplied, false otherwise.
181     */
182    bool IsPreMultipliedAlphaEnabled() const;
183
184   /**
185    * @brief Get the scene graph object
186    *
187    * @return the scene object
188    */
189   SceneGraph::Renderer* GetRendererSceneObject();
190
191 public: // Default property extensions from Object
192
193   /**
194    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
195    */
196   virtual unsigned int GetDefaultPropertyCount() const;
197
198   /**
199    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
200    */
201   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
202
203   /**
204    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
205    */
206   virtual const char* GetDefaultPropertyName(Property::Index index) const;
207
208   /**
209    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
210    */
211   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
212
213   /**
214    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
215    */
216   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
217
218   /**
219    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
220    */
221   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
222
223   /**
224    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
225    */
226   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
227
228   /**
229    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
230    */
231   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
232
233   /**
234    * @copydoc Dali::Internal::Object::SetDefaultProperty()
235    */
236   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
237
238   /**
239    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
240    */
241   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
242
243   /**
244    * @copydoc Dali::Internal::Object::GetDefaultProperty()
245    */
246   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
247
248   /**
249    * @copydoc Dali::Internal::Object::GetPropertyOwner()
250    */
251   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
252
253   /**
254    * @copydoc Dali::Internal::Object::GetSceneObject()
255    */
256   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
257
258   /**
259    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
260    */
261   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
262
263   /**
264    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
265    */
266   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
267
268   /**
269    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
270    */
271   virtual int GetPropertyComponentIndex( Property::Index index ) const;
272
273 public: // Functions from Connectable
274   /**
275    * @copydoc Dali::Internal::Connectable::OnStage()
276    */
277   virtual bool OnStage() const;
278
279   /**
280    * @copydoc Dali::Internal::Connectable::Connect()
281    */
282   virtual void Connect();
283
284   /**
285    * @copydoc Dali::Internal::Connectable::Disconnect()
286    */
287   virtual void Disconnect();
288
289 private: // implementation
290   Renderer();
291
292   void Initialize();
293
294 protected:
295   /**
296    * A reference counted object may only be deleted by calling Unreference()
297    */
298   virtual ~Renderer();
299
300 private: // unimplemented methods
301   Renderer( const Renderer& );
302   Renderer& operator=( const Renderer& );
303
304 private: // data
305   SceneGraph::Renderer* mSceneObject;
306   Vector4* mBlendColor;                             ///< Local copy of blend color, pointer only as its rarely used
307   GeometryPtr mGeometry;                            ///< Connector that holds the geometry used by this renderer
308   ObjectConnector<TextureSet> mTextureSetConnector; ///< Connector that holds the texture set used by this renderer
309   IntrusivePtr<Shader> mShader;                     ///< Connector that holds the shader used by this renderer
310
311   int mDepthIndex;
312   int mOnStageCount;
313
314   size_t mIndexedDrawFirstElement;                  ///< Offset of first element to draw from bound index buffer
315   size_t mIndexedDrawElementCount;                  ///< Number of elements to draw
316
317   Dali::FaceCullingMode::Type mFaceCullingMode;     ///< Local copy of face culling mode
318   BlendMode::Type mBlendMode;                       ///< Local copy of blending mode
319   BlendingOptions mBlendingOptions;                 ///< Local copy of blending options bitmask
320   Dali::DepthWriteMode::Type mDepthWriteMode;       ///< Local copy of depth write mode
321   Dali::DepthFunction::Type mDepthFunction;         ///< Local copy of depth function
322
323   bool mPremultipledAlphaEnabled : 1;               ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
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