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