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