New DepthTestMode API in Renderer
[platform/core/uifw/dali-core.git] / dali / internal / event / rendering / renderer-impl.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23 #include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
25 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
26 #include <dali/internal/event/common/property-input-impl.h>
27 #include <dali/internal/update/rendering/scene-graph-renderer.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/render/renderers/render-geometry.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 /**
40  *            |name                              |type     |writable|animatable|constraint-input|enum for index-checking|
41  */
42 DALI_PROPERTY_TABLE_BEGIN
43 DALI_PROPERTY( "depthIndex",                      INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_INDEX )
44 DALI_PROPERTY( "faceCullingMode",                 INTEGER,   true, false,  false, Dali::Renderer::Property::FACE_CULLING_MODE )
45 DALI_PROPERTY( "blendMode",                       INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_MODE )
46 DALI_PROPERTY( "blendEquationRgb",                INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
47 DALI_PROPERTY( "blendEquationAlpha",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
48 DALI_PROPERTY( "blendFactorSrcRgb",               INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
49 DALI_PROPERTY( "blendFactorDestRgb",              INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
50 DALI_PROPERTY( "blendFactorSrcAlpha",             INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
51 DALI_PROPERTY( "blendFactorDestAlpha",            INTEGER,   true, false,  false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
52 DALI_PROPERTY( "blendColor",                      VECTOR4,   true, false,  false, Dali::Renderer::Property::BLEND_COLOR )
53 DALI_PROPERTY( "blendPreMultipliedAlpha",         BOOLEAN,   true, false,  false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
54 DALI_PROPERTY( "indexRangeFirst",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
55 DALI_PROPERTY( "indexRangeCount",                 INTEGER,   true, false,  false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
56 DALI_PROPERTY( "depthWriteMode",                  INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
57 DALI_PROPERTY( "depthFunction",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_FUNCTION )
58 DALI_PROPERTY( "depthTestMode",                   INTEGER,   true, false,  false, Dali::Renderer::Property::DEPTH_TEST_MODE )
59 DALI_PROPERTY_TABLE_END( DEFAULT_OBJECT_PROPERTY_START_INDEX )
60
61 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
62
63 BaseHandle Create()
64 {
65   return Dali::BaseHandle();
66 }
67
68 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
69
70 } // unnamed namespace
71
72 RendererPtr Renderer::New()
73 {
74   RendererPtr rendererPtr( new Renderer() );
75   rendererPtr->Initialize();
76   return rendererPtr;
77 }
78
79 void Renderer::SetGeometry( Geometry& geometry )
80 {
81   mGeometry = &geometry;
82
83   const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
84   SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
85 }
86
87 Geometry* Renderer::GetGeometry() const
88 {
89   return mGeometry.Get();
90 }
91
92 void Renderer::SetTextures( TextureSet& textureSet )
93 {
94   mTextureSetConnector.Set( textureSet, OnStage() );
95   const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
96   SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
97 }
98
99 TextureSet* Renderer::GetTextures() const
100 {
101   return mTextureSetConnector.Get().Get();
102 }
103
104 void Renderer::SetShader( Shader& shader )
105 {
106   mShader = &shader;
107   SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
108   SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
109 }
110
111 Shader* Renderer::GetShader() const
112 {
113   return mShader.Get();
114 }
115
116 void Renderer::SetDepthIndex( int depthIndex )
117 {
118   if ( mDepthIndex != depthIndex )
119   {
120     mDepthIndex = depthIndex;
121     SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
122   }
123 }
124
125 int Renderer::GetDepthIndex() const
126 {
127   return mDepthIndex;
128 }
129
130 void Renderer::SetFaceCullingMode( FaceCullingMode::Type cullingMode )
131 {
132   if( mFaceCullingMode != cullingMode )
133   {
134     mFaceCullingMode = cullingMode;
135
136     SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, mFaceCullingMode );
137   }
138 }
139
140 FaceCullingMode::Type Renderer::GetFaceCullingMode()
141 {
142   return mFaceCullingMode;
143 }
144
145 void Renderer::SetBlendMode( BlendMode::Type mode )
146 {
147   if( mBlendMode != mode )
148   {
149     mBlendMode = mode;
150
151     SetBlendModeMessage( GetEventThreadServices(), *mSceneObject, mBlendMode );
152   }
153 }
154
155 BlendMode::Type Renderer::GetBlendMode() const
156 {
157   return mBlendMode;
158 }
159
160 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
161 {
162   mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
163   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
164 }
165
166 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
167                              BlendFactor::Type destFactorRgb,
168                              BlendFactor::Type srcFactorAlpha,
169                              BlendFactor::Type destFactorAlpha )
170 {
171   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
172   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
173 }
174
175 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
176                              BlendFactor::Type& destFactorRgb,
177                              BlendFactor::Type& srcFactorAlpha,
178                              BlendFactor::Type& destFactorAlpha ) const
179 {
180   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
181   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
182   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
183   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
184 }
185
186 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
187 {
188   mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
189   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
190 }
191
192 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
193                                  BlendEquation::Type equationAlpha )
194 {
195   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
196   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
197 }
198
199 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
200                                  BlendEquation::Type& equationAlpha ) const
201 {
202   // These are not animatable, the cached values are up-to-date.
203   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
204   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
205 }
206
207 void Renderer::SetBlendColor( const Vector4& color )
208 {
209   if( !mBlendColor )
210   {
211     mBlendColor = new Vector4();
212   }
213   if( *mBlendColor != color )
214   {
215     *mBlendColor = color;
216     SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
217   }
218 }
219
220 Vector4 Renderer::GetBlendColor() const
221 {
222   if( mBlendColor )
223   {
224     return *mBlendColor;
225   }
226   return Color::TRANSPARENT; // GL default
227 }
228
229 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
230 {
231   if( firstElement != mIndexedDrawFirstElement )
232   {
233     mIndexedDrawFirstElement = firstElement;
234     SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
235   }
236 }
237
238 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
239 {
240   if( elementsCount != mIndexedDrawElementCount )
241   {
242     mIndexedDrawElementCount = elementsCount;
243     SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
244   }
245 }
246
247
248 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
249 {
250   if(  mPremultipledAlphaEnabled != preMultipled )
251   {
252     if( preMultipled )
253     {
254       SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
255     }
256     mPremultipledAlphaEnabled = preMultipled;
257     SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
258   }
259 }
260
261 bool Renderer::IsPreMultipliedAlphaEnabled() const
262 {
263   return mPremultipledAlphaEnabled;
264 }
265
266 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
267 {
268   return mSceneObject;
269 }
270
271 unsigned int Renderer::GetDefaultPropertyCount() const
272 {
273   return RENDERER_IMPL.GetDefaultPropertyCount();
274 }
275
276 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
277 {
278   RENDERER_IMPL.GetDefaultPropertyIndices( indices );
279 }
280
281 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
282 {
283   return RENDERER_IMPL.GetDefaultPropertyName( index );
284 }
285
286 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
287 {
288   return RENDERER_IMPL.GetDefaultPropertyIndex( name );
289 }
290
291 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
292 {
293   return RENDERER_IMPL.IsDefaultPropertyWritable( index );
294 }
295
296 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
297 {
298   return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
299 }
300
301 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
302 {
303   return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
304 }
305
306 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
307 {
308   return RENDERER_IMPL.GetDefaultPropertyType( index );
309 }
310
311 void Renderer::SetDefaultProperty( Property::Index index,
312                                    const Property::Value& propertyValue )
313 {
314   switch( index )
315   {
316     case Dali::Renderer::Property::DEPTH_INDEX:
317     {
318       SetDepthIndex( propertyValue.Get<int>() );
319       break;
320     }
321     case Dali::Renderer::Property::FACE_CULLING_MODE:
322     {
323       int faceCullingMode;
324       if( propertyValue.Get( faceCullingMode ) )
325       {
326         SetFaceCullingMode( FaceCullingMode::Type( faceCullingMode ) );
327       }
328       break;
329     }
330     case Dali::Renderer::Property::BLEND_MODE:
331     {
332       int blendingMode;
333       if( propertyValue.Get( blendingMode ) )
334       {
335         SetBlendMode( BlendMode::Type( blendingMode ) );
336       }
337       break;
338     }
339     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
340     {
341       int blendingEquation;
342       if( propertyValue.Get( blendingEquation ) )
343       {
344         BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
345         mBlendingOptions.SetBlendEquation( static_cast<BlendEquation::Type>( blendingEquation ), alphaEquation );
346         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
347       }
348       break;
349     }
350     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
351     {
352       int blendingEquation;
353       if( propertyValue.Get( blendingEquation ) )
354       {
355         BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
356         mBlendingOptions.SetBlendEquation( rgbEquation, static_cast<BlendEquation::Type>( blendingEquation ) );
357         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
358       }
359       break;
360     }
361     case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
362     {
363       int blendingFactor;
364       if( propertyValue.Get( blendingFactor ) )
365       {
366         BlendFactor::Type srcFactorRgb;
367         BlendFactor::Type destFactorRgb;
368         BlendFactor::Type srcFactorAlpha;
369         BlendFactor::Type destFactorAlpha;
370         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
371         SetBlendFunc( static_cast<BlendFactor::Type>( blendingFactor ),
372             destFactorRgb,
373             srcFactorAlpha,
374             destFactorAlpha );
375       }
376       break;
377     }
378     case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
379     {
380       int blendingFactor;
381       if( propertyValue.Get( blendingFactor ) )
382       {
383         BlendFactor::Type srcFactorRgb;
384         BlendFactor::Type destFactorRgb;
385         BlendFactor::Type srcFactorAlpha;
386         BlendFactor::Type destFactorAlpha;
387         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
388         SetBlendFunc( srcFactorRgb,
389             static_cast<BlendFactor::Type>( blendingFactor ),
390             srcFactorAlpha,
391             destFactorAlpha );
392       }
393       break;
394     }
395     case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
396     {
397       int blendingFactor;
398       if( propertyValue.Get( blendingFactor ) )
399       {
400         BlendFactor::Type srcFactorRgb;
401         BlendFactor::Type destFactorRgb;
402         BlendFactor::Type srcFactorAlpha;
403         BlendFactor::Type destFactorAlpha;
404         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
405         SetBlendFunc( srcFactorRgb,
406             destFactorRgb,
407             static_cast<BlendFactor::Type>( blendingFactor ),
408             destFactorAlpha );
409       }
410       break;
411     }
412     case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
413     {
414       int blendingFactor;
415       if( propertyValue.Get( blendingFactor ) )
416       {
417         BlendFactor::Type srcFactorRgb;
418         BlendFactor::Type destFactorRgb;
419         BlendFactor::Type srcFactorAlpha;
420         BlendFactor::Type destFactorAlpha;
421         GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
422         SetBlendFunc( srcFactorRgb,
423             destFactorRgb,
424             srcFactorAlpha,
425             static_cast<BlendFactor::Type>( blendingFactor ) );
426       }
427       break;
428     }
429     case Dali::Renderer::Property::BLEND_COLOR:
430     {
431       Vector4 blendColor;
432       if( propertyValue.Get( blendColor ) )
433       {
434         SetBlendColor( blendColor );
435       }
436       break;
437     }
438     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
439     {
440       bool preMultipled;
441       if( propertyValue.Get( preMultipled ) )
442       {
443         EnablePreMultipliedAlpha( preMultipled );
444       }
445       break;
446     }
447     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
448     {
449       int firstElement;
450       if( propertyValue.Get( firstElement ) )
451       {
452         SetIndexedDrawFirstElement( firstElement );
453       }
454       break;
455     }
456     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
457     {
458       int elementsCount;
459       if( propertyValue.Get( elementsCount ) )
460       {
461         SetIndexedDrawElementsCount( elementsCount );
462       }
463       break;
464     }
465     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
466     {
467       int value;
468       propertyValue.Get( value );
469       DepthWriteMode::Type mode = static_cast<DepthWriteMode::Type>(value);
470       if( mode != mDepthWriteMode )
471       {
472         mDepthWriteMode = mode;
473         SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, mode );
474       }
475       break;
476     }
477     case Dali::Renderer::Property::DEPTH_FUNCTION:
478     {
479       int value;
480       propertyValue.Get( value );
481       DepthFunction::Type depthFunction = static_cast<DepthFunction::Type>(value);
482       if( depthFunction != mDepthFunction )
483       {
484         mDepthFunction = depthFunction;
485         SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, depthFunction );
486       }
487       break;
488     }
489     case Dali::Renderer::Property::DEPTH_TEST_MODE:
490     {
491       int value;
492       propertyValue.Get( value );
493       DepthTestMode::Type mode = static_cast<DepthTestMode::Type>(value);
494       if( mode != mDepthTestMode )
495       {
496         mDepthTestMode = mode;
497         SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, mode );
498       }
499       break;
500     }
501   }
502 }
503
504 void Renderer::SetSceneGraphProperty( Property::Index index,
505                                       const PropertyMetadata& entry,
506                                       const Property::Value& value )
507 {
508   RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
509   OnPropertySet(index, value);
510 }
511
512 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
513 {
514   Property::Value value;
515   switch( index )
516   {
517     case Dali::Renderer::Property::DEPTH_INDEX:
518     {
519       value = GetDepthIndex();
520       break;
521     }
522     case Dali::Renderer::Property::FACE_CULLING_MODE:
523     {
524       value = mFaceCullingMode;
525       break;
526     }
527     case Dali::Renderer::Property::BLEND_MODE:
528     {
529       value = mBlendMode;
530       break;
531     }
532     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
533     {
534       value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
535       break;
536     }
537     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
538     {
539       value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
540       break;
541     }
542     case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
543     {
544       BlendFactor::Type srcFactorRgb;
545       BlendFactor::Type destFactorRgb;
546       BlendFactor::Type srcFactorAlpha;
547       BlendFactor::Type destFactorAlpha;
548       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
549       value = static_cast<int>( srcFactorRgb );
550       break;
551     }
552     case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
553     {
554       BlendFactor::Type srcFactorRgb;
555       BlendFactor::Type destFactorRgb;
556       BlendFactor::Type srcFactorAlpha;
557       BlendFactor::Type destFactorAlpha;
558       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
559       value = static_cast<int>( destFactorRgb );
560       break;
561     }
562     case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
563     {
564       BlendFactor::Type srcFactorRgb;
565       BlendFactor::Type destFactorRgb;
566       BlendFactor::Type srcFactorAlpha;
567       BlendFactor::Type destFactorAlpha;
568       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
569       value = static_cast<int>( srcFactorAlpha );
570       break;
571     }
572     case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
573     {
574       BlendFactor::Type srcFactorRgb;
575       BlendFactor::Type destFactorRgb;
576       BlendFactor::Type srcFactorAlpha;
577       BlendFactor::Type destFactorAlpha;
578       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
579       value = static_cast<int>( destFactorAlpha );
580       break;
581     }
582     case Dali::Renderer::Property::BLEND_COLOR:
583     {
584       if( mBlendColor )
585       {
586         value = *mBlendColor;
587       }
588       else
589       {
590         value = Color::TRANSPARENT;
591       }
592       break;
593     }
594     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
595     {
596       value = IsPreMultipliedAlphaEnabled();
597       break;
598     }
599     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
600     {
601       value = static_cast<int>( mIndexedDrawFirstElement );
602       break;
603     }
604     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
605     {
606       value = static_cast<int>( mIndexedDrawElementCount );
607       break;
608     }
609     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
610     {
611       value = mDepthWriteMode;
612       break;
613     }
614     case Dali::Renderer::Property::DEPTH_FUNCTION:
615     {
616       value = mDepthFunction;
617       break;
618     }
619     case Dali::Renderer::Property::DEPTH_TEST_MODE:
620     {
621       value = mDepthTestMode;
622       break;
623     }
624   }
625   return value;
626 }
627
628 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
629 {
630   return mSceneObject;
631 }
632
633 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
634 {
635   return mSceneObject;
636 }
637
638 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
639 {
640   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
641   const SceneGraph::PropertyBase* property = NULL;
642
643   if( OnStage() )
644   {
645     property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
646       this,
647       &Renderer::FindAnimatableProperty,
648       &Renderer::FindCustomProperty,
649       index );
650   }
651
652   return property;
653 }
654
655 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
656 {
657   const PropertyInputImpl* property = NULL;
658
659   if( OnStage() )
660   {
661     const SceneGraph::PropertyBase* baseProperty =
662       RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
663                                                      &Renderer::FindAnimatableProperty,
664                                                      &Renderer::FindCustomProperty,
665                                                      index );
666     property = static_cast<const PropertyInputImpl*>( baseProperty );
667   }
668
669   return property;
670 }
671
672 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
673 {
674   return Property::INVALID_COMPONENT_INDEX;
675 }
676
677 bool Renderer::OnStage() const
678 {
679   return mOnStageCount > 0;
680 }
681
682 void Renderer::Connect()
683 {
684   if( mOnStageCount == 0 )
685   {
686     OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
687     mTextureSetConnector.OnStageConnect();
688   }
689   ++mOnStageCount;
690 }
691
692 void Renderer::Disconnect()
693 {
694   --mOnStageCount;
695   if( mOnStageCount == 0 )
696   {
697     OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
698     mTextureSetConnector.OnStageDisconnect();
699   }
700 }
701
702 Renderer::Renderer()
703 : mSceneObject (NULL ),
704   mBlendColor( NULL ),
705   mDepthIndex( 0 ),
706   mOnStageCount( 0 ),
707   mIndexedDrawFirstElement( 0 ),
708   mIndexedDrawElementCount( 0 ),
709   mFaceCullingMode( FaceCullingMode::NONE ),
710   mBlendMode( BlendMode::AUTO ),
711   mBlendingOptions(),
712   mDepthWriteMode( DepthWriteMode::AUTO ),
713   mDepthFunction( DepthFunction::LESS ),
714   mDepthTestMode( DepthTestMode::AUTO ),
715   mPremultipledAlphaEnabled( false )
716 {
717 }
718
719 void Renderer::Initialize()
720 {
721   EventThreadServices& eventThreadServices = GetEventThreadServices();
722   SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
723
724   mSceneObject = SceneGraph::Renderer::New();
725   AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
726
727   eventThreadServices.RegisterObject( this );
728 }
729
730 Renderer::~Renderer()
731 {
732   if( EventThreadServices::IsCoreRunning() )
733   {
734     EventThreadServices& eventThreadServices = GetEventThreadServices();
735     SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
736     RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
737
738     eventThreadServices.UnregisterObject( this );
739   }
740 }
741
742 } // namespace Internal
743 } // namespace Dali