[3.0] Clipping API feature in Actor
[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/devel-api/scripting/scripting.h>
23 #include <dali/public-api/object/type-registry.h>
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/render/renderers/render-geometry.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/rendering/scene-graph-renderer.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35
36 namespace
37 {
38
39 /**
40  * Properties: |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( "renderMode",                      INTEGER,   true, false,  false, Dali::Renderer::Property::RENDER_MODE )
60 DALI_PROPERTY( "stencilFunction",                 INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION )
61 DALI_PROPERTY( "stencilFunctionMask",             INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
62 DALI_PROPERTY( "stencilFunctionReference",        INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
63 DALI_PROPERTY( "stencilMask",                     INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_MASK )
64 DALI_PROPERTY( "stencilOperationOnFail",          INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
65 DALI_PROPERTY( "stencilOperationOnZFail",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
66 DALI_PROPERTY( "stencilOperationOnZPass",         INTEGER,   true, false,  false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
67 DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
68
69 // Property string to enumeration tables:
70
71 DALI_ENUM_TO_STRING_TABLE_BEGIN( FACE_CULLING_MODE )
72 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, NONE )
73 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT )
74 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, BACK )
75 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT_AND_BACK )
76 DALI_ENUM_TO_STRING_TABLE_END( FACE_CULLING_MODE )
77
78 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_MODE )
79 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, OFF )
80 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, AUTO )
81 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, ON )
82 DALI_ENUM_TO_STRING_TABLE_END( BLEND_MODE )
83
84 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_EQUATION )
85 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, ADD )
86 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, SUBTRACT )
87 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, REVERSE_SUBTRACT )
88 DALI_ENUM_TO_STRING_TABLE_END( BLEND_EQUATION )
89
90 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_FACTOR )
91 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ZERO )
92 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE )
93 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_COLOR )
94 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_COLOR )
95 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA )
96 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_ALPHA )
97 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_ALPHA )
98 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_ALPHA )
99 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_COLOR )
100 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_COLOR )
101 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA_SATURATE )
102 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_COLOR )
103 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_COLOR )
104 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_ALPHA )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_ALPHA )
106 DALI_ENUM_TO_STRING_TABLE_END( BLEND_FACTOR )
107
108 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_WRITE_MODE )
109 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, OFF )
110 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, AUTO )
111 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, ON )
112 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_WRITE_MODE )
113
114 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_TEST_MODE )
115 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, OFF )
116 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, AUTO )
117 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, ON )
118 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_TEST_MODE )
119
120 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_FUNCTION )
121 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NEVER )
122 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, ALWAYS )
123 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS )
124 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER )
125 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, EQUAL )
126 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NOT_EQUAL )
127 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS_EQUAL )
128 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER_EQUAL )
129 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_FUNCTION )
130
131 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_FUNCTION )
132 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NEVER )
133 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS )
134 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, EQUAL )
135 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS_EQUAL )
136 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER )
137 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NOT_EQUAL )
138 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER_EQUAL )
139 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, ALWAYS )
140 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_FUNCTION )
141
142 DALI_ENUM_TO_STRING_TABLE_BEGIN( RENDER_MODE )
143 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, NONE )
144 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, AUTO )
145 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR )
146 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, STENCIL )
147 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR_STENCIL )
148 DALI_ENUM_TO_STRING_TABLE_END( RENDER_MODE )
149
150 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_OPERATION )
151 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, ZERO )
152 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, KEEP )
153 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, REPLACE )
154 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT )
155 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT )
156 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INVERT )
157 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT_WRAP )
158 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT_WRAP )
159 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_OPERATION )
160
161 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
162
163 BaseHandle Create()
164 {
165   return Dali::BaseHandle();
166 }
167
168 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
169
170 } // unnamed namespace
171
172 RendererPtr Renderer::New()
173 {
174   RendererPtr rendererPtr( new Renderer() );
175   rendererPtr->Initialize();
176   return rendererPtr;
177 }
178
179 void Renderer::SetGeometry( Geometry& geometry )
180 {
181   mGeometry = &geometry;
182
183   const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
184   SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
185 }
186
187 Geometry* Renderer::GetGeometry() const
188 {
189   return mGeometry.Get();
190 }
191
192 void Renderer::SetTextures( TextureSet& textureSet )
193 {
194   mTextureSetConnector.Set( textureSet, OnStage() );
195   const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
196   SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
197 }
198
199 TextureSet* Renderer::GetTextures() const
200 {
201   return mTextureSetConnector.Get().Get();
202 }
203
204 void Renderer::SetShader( Shader& shader )
205 {
206   mShader = &shader;
207   SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
208   SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
209 }
210
211 Shader* Renderer::GetShader() const
212 {
213   return mShader.Get();
214 }
215
216 void Renderer::SetDepthIndex( int depthIndex )
217 {
218   if ( mDepthIndex != depthIndex )
219   {
220     mDepthIndex = depthIndex;
221     SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
222   }
223 }
224
225 int Renderer::GetDepthIndex() const
226 {
227   return mDepthIndex;
228 }
229
230 void Renderer::SetBlendMode( BlendMode::Type mode )
231 {
232   if( mBlendMode != mode )
233   {
234     mBlendMode = mode;
235
236     SetBlendModeMessage( GetEventThreadServices(), *mSceneObject, mBlendMode );
237   }
238 }
239
240 BlendMode::Type Renderer::GetBlendMode() const
241 {
242   return mBlendMode;
243 }
244
245 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
246 {
247   mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
248   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
249 }
250
251 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
252                              BlendFactor::Type destFactorRgb,
253                              BlendFactor::Type srcFactorAlpha,
254                              BlendFactor::Type destFactorAlpha )
255 {
256   mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
257   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
258 }
259
260 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
261                              BlendFactor::Type& destFactorRgb,
262                              BlendFactor::Type& srcFactorAlpha,
263                              BlendFactor::Type& destFactorAlpha ) const
264 {
265   srcFactorRgb    = mBlendingOptions.GetBlendSrcFactorRgb();
266   destFactorRgb   = mBlendingOptions.GetBlendDestFactorRgb();
267   srcFactorAlpha  = mBlendingOptions.GetBlendSrcFactorAlpha();
268   destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
269 }
270
271 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
272 {
273   mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
274   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
275 }
276
277 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
278                                  BlendEquation::Type equationAlpha )
279 {
280   mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
281   SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
282 }
283
284 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
285                                  BlendEquation::Type& equationAlpha ) const
286 {
287   // These are not animatable, the cached values are up-to-date.
288   equationRgb   = mBlendingOptions.GetBlendEquationRgb();
289   equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
290 }
291
292 void Renderer::SetBlendColor( const Vector4& color )
293 {
294   if( !mBlendColor )
295   {
296     mBlendColor = new Vector4();
297   }
298   if( *mBlendColor != color )
299   {
300     *mBlendColor = color;
301     SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
302   }
303 }
304
305 Vector4 Renderer::GetBlendColor() const
306 {
307   if( mBlendColor )
308   {
309     return *mBlendColor;
310   }
311   return Color::TRANSPARENT; // GL default
312 }
313
314 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
315 {
316   if( firstElement != mIndexedDrawFirstElement )
317   {
318     mIndexedDrawFirstElement = firstElement;
319     SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
320   }
321 }
322
323 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
324 {
325   if( elementsCount != mIndexedDrawElementCount )
326   {
327     mIndexedDrawElementCount = elementsCount;
328     SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
329   }
330 }
331
332
333 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
334 {
335   if(  mPremultipledAlphaEnabled != preMultipled )
336   {
337     if( preMultipled )
338     {
339       SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
340     }
341     mPremultipledAlphaEnabled = preMultipled;
342     SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
343   }
344 }
345
346 bool Renderer::IsPreMultipliedAlphaEnabled() const
347 {
348   return mPremultipledAlphaEnabled;
349 }
350
351 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
352 {
353   return mSceneObject;
354 }
355
356 unsigned int Renderer::GetDefaultPropertyCount() const
357 {
358   return RENDERER_IMPL.GetDefaultPropertyCount();
359 }
360
361 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
362 {
363   RENDERER_IMPL.GetDefaultPropertyIndices( indices );
364 }
365
366 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
367 {
368   return RENDERER_IMPL.GetDefaultPropertyName( index );
369 }
370
371 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
372 {
373   return RENDERER_IMPL.GetDefaultPropertyIndex( name );
374 }
375
376 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
377 {
378   return RENDERER_IMPL.IsDefaultPropertyWritable( index );
379 }
380
381 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
382 {
383   return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
384 }
385
386 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
387 {
388   return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
389 }
390
391 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
392 {
393   return RENDERER_IMPL.GetDefaultPropertyType( index );
394 }
395
396 void Renderer::SetDefaultProperty( Property::Index index,
397                                    const Property::Value& propertyValue )
398 {
399   switch( index )
400   {
401     case Dali::Renderer::Property::DEPTH_INDEX:
402     {
403       SetDepthIndex( propertyValue.Get<int>() );
404       break;
405     }
406     case Dali::Renderer::Property::FACE_CULLING_MODE:
407     {
408       FaceCullingMode::Type convertedValue = mFaceCullingMode;
409       if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
410       {
411         mFaceCullingMode = convertedValue;
412         SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
413       }
414       break;
415     }
416     case Dali::Renderer::Property::BLEND_MODE:
417     {
418       BlendMode::Type convertedValue = mBlendMode;
419       if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
420       {
421         SetBlendMode( convertedValue );
422       }
423       break;
424     }
425     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
426     {
427       BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
428
429       if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
430       {
431         BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
432         mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
433         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
434       }
435       break;
436     }
437     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
438     {
439       BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
440
441       if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
442       {
443         BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
444         mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
445         SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
446       }
447       break;
448     }
449     case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
450     {
451       BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
452       GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
453
454       if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
455       {
456         SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
457       }
458       break;
459     }
460     case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
461     {
462       BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
463       GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
464
465       if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
466       {
467         SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
468       }
469       break;
470     }
471     case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
472     {
473       BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
474       GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
475
476       if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
477       {
478         SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
479       }
480       break;
481     }
482     case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
483     {
484       BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
485       GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
486
487       if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
488       {
489         SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
490       }
491       break;
492     }
493     case Dali::Renderer::Property::BLEND_COLOR:
494     {
495       Vector4 blendColor;
496       if( propertyValue.Get( blendColor ) )
497       {
498         SetBlendColor( blendColor );
499       }
500       break;
501     }
502     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
503     {
504       bool preMultipled;
505       if( propertyValue.Get( preMultipled ) )
506       {
507         EnablePreMultipliedAlpha( preMultipled );
508       }
509       break;
510     }
511     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
512     {
513       int firstElement;
514       if( propertyValue.Get( firstElement ) )
515       {
516         SetIndexedDrawFirstElement( firstElement );
517       }
518       break;
519     }
520     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
521     {
522       int elementsCount;
523       if( propertyValue.Get( elementsCount ) )
524       {
525         SetIndexedDrawElementsCount( elementsCount );
526       }
527       break;
528     }
529     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
530     {
531       DepthWriteMode::Type convertedValue = mDepthWriteMode;
532       if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
533       {
534         mDepthWriteMode = convertedValue;
535         SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
536       }
537       break;
538     }
539     case Dali::Renderer::Property::DEPTH_FUNCTION:
540     {
541       DepthFunction::Type convertedValue = mDepthFunction;
542       if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
543       {
544         mDepthFunction = convertedValue;
545         SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
546       }
547       break;
548     }
549     case Dali::Renderer::Property::DEPTH_TEST_MODE:
550     {
551       DepthTestMode::Type convertedValue = mDepthTestMode;
552       if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
553       {
554         mDepthTestMode = convertedValue;
555         SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
556       }
557       break;
558     }
559     case Dali::Renderer::Property::RENDER_MODE:
560     {
561       RenderMode::Type convertedValue = mStencilParameters.renderMode;
562       if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
563       {
564         mStencilParameters.renderMode = convertedValue;
565         SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
566       }
567       break;
568     }
569     case Dali::Renderer::Property::STENCIL_FUNCTION:
570     {
571       StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
572       if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
573       {
574         mStencilParameters.stencilFunction = convertedValue;
575         SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
576       }
577       break;
578     }
579     case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
580     {
581       int stencilFunctionMask;
582       if( propertyValue.Get( stencilFunctionMask ) )
583       {
584         if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
585         {
586           mStencilParameters.stencilFunctionMask = stencilFunctionMask;
587           SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
588         }
589       }
590       break;
591     }
592     case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
593     {
594       int stencilFunctionReference;
595       if( propertyValue.Get( stencilFunctionReference ) )
596       {
597         if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
598         {
599           mStencilParameters.stencilFunctionReference = stencilFunctionReference;
600           SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
601         }
602       }
603       break;
604     }
605     case Dali::Renderer::Property::STENCIL_MASK:
606     {
607       int stencilMask;
608       if( propertyValue.Get( stencilMask ) )
609       {
610         if( stencilMask != mStencilParameters.stencilMask )
611         {
612           mStencilParameters.stencilMask = stencilMask;
613           SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
614         }
615       }
616       break;
617     }
618     case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
619     {
620       StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
621       if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
622       {
623         mStencilParameters.stencilOperationOnFail = convertedValue;
624         SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
625       }
626       break;
627     }
628     case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
629     {
630       StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
631       if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
632       {
633         mStencilParameters.stencilOperationOnZFail = convertedValue;
634         SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
635       }
636       break;
637     }
638     case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
639     {
640       StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
641       if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
642       {
643         mStencilParameters.stencilOperationOnZPass = convertedValue;
644         SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
645       }
646       break;
647     }
648   }
649 }
650
651 void Renderer::SetSceneGraphProperty( Property::Index index,
652                                       const PropertyMetadata& entry,
653                                       const Property::Value& value )
654 {
655   RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
656   OnPropertySet(index, value);
657 }
658
659 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
660 {
661   Property::Value value;
662   switch( index )
663   {
664     case Dali::Renderer::Property::DEPTH_INDEX:
665     {
666       value = GetDepthIndex();
667       break;
668     }
669     case Dali::Renderer::Property::FACE_CULLING_MODE:
670     {
671       value = mFaceCullingMode;
672       break;
673     }
674     case Dali::Renderer::Property::BLEND_MODE:
675     {
676       value = mBlendMode;
677       break;
678     }
679     case Dali::Renderer::Property::BLEND_EQUATION_RGB:
680     {
681       value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
682       break;
683     }
684     case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
685     {
686       value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
687       break;
688     }
689     case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
690     {
691       BlendFactor::Type srcFactorRgb;
692       BlendFactor::Type destFactorRgb;
693       BlendFactor::Type srcFactorAlpha;
694       BlendFactor::Type destFactorAlpha;
695       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
696       value = static_cast<int>( srcFactorRgb );
697       break;
698     }
699     case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
700     {
701       BlendFactor::Type srcFactorRgb;
702       BlendFactor::Type destFactorRgb;
703       BlendFactor::Type srcFactorAlpha;
704       BlendFactor::Type destFactorAlpha;
705       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
706       value = static_cast<int>( destFactorRgb );
707       break;
708     }
709     case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
710     {
711       BlendFactor::Type srcFactorRgb;
712       BlendFactor::Type destFactorRgb;
713       BlendFactor::Type srcFactorAlpha;
714       BlendFactor::Type destFactorAlpha;
715       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
716       value = static_cast<int>( srcFactorAlpha );
717       break;
718     }
719     case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
720     {
721       BlendFactor::Type srcFactorRgb;
722       BlendFactor::Type destFactorRgb;
723       BlendFactor::Type srcFactorAlpha;
724       BlendFactor::Type destFactorAlpha;
725       GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
726       value = static_cast<int>( destFactorAlpha );
727       break;
728     }
729     case Dali::Renderer::Property::BLEND_COLOR:
730     {
731       if( mBlendColor )
732       {
733         value = *mBlendColor;
734       }
735       else
736       {
737         value = Color::TRANSPARENT;
738       }
739       break;
740     }
741     case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
742     {
743       value = IsPreMultipliedAlphaEnabled();
744       break;
745     }
746     case Dali::Renderer::Property::INDEX_RANGE_FIRST:
747     {
748       value = static_cast<int>( mIndexedDrawFirstElement );
749       break;
750     }
751     case Dali::Renderer::Property::INDEX_RANGE_COUNT:
752     {
753       value = static_cast<int>( mIndexedDrawElementCount );
754       break;
755     }
756     case Dali::Renderer::Property::DEPTH_WRITE_MODE:
757     {
758       value = mDepthWriteMode;
759       break;
760     }
761     case Dali::Renderer::Property::DEPTH_FUNCTION:
762     {
763       value = mDepthFunction;
764       break;
765     }
766     case Dali::Renderer::Property::DEPTH_TEST_MODE:
767     {
768       value = mDepthTestMode;
769       break;
770     }
771     case Dali::Renderer::Property::STENCIL_FUNCTION:
772     {
773       value = mStencilParameters.stencilFunction;
774       break;
775     }
776     case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
777     {
778       value = mStencilParameters.stencilFunctionMask;
779       break;
780     }
781     case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
782     {
783       value = mStencilParameters.stencilFunctionReference;
784       break;
785     }
786     case Dali::Renderer::Property::STENCIL_MASK:
787     {
788       value = mStencilParameters.stencilMask;
789       break;
790     }
791     case Dali::Renderer::Property::RENDER_MODE:
792     {
793       value = mStencilParameters.renderMode;
794       break;
795     }
796     case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
797     {
798       value = mStencilParameters.stencilOperationOnFail;
799       break;
800     }
801     case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
802     {
803       value = mStencilParameters.stencilOperationOnZFail;
804       break;
805     }
806     case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
807     {
808       value = mStencilParameters.stencilOperationOnZPass;
809       break;
810     }
811   }
812   return value;
813 }
814
815 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
816 {
817   return mSceneObject;
818 }
819
820 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
821 {
822   return mSceneObject;
823 }
824
825 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
826 {
827   DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
828   const SceneGraph::PropertyBase* property = NULL;
829
830   if( OnStage() )
831   {
832     property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
833       this,
834       &Renderer::FindAnimatableProperty,
835       &Renderer::FindCustomProperty,
836       index );
837   }
838
839   return property;
840 }
841
842 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
843 {
844   const PropertyInputImpl* property = NULL;
845
846   if( OnStage() )
847   {
848     const SceneGraph::PropertyBase* baseProperty =
849       RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
850                                                      &Renderer::FindAnimatableProperty,
851                                                      &Renderer::FindCustomProperty,
852                                                      index );
853     property = static_cast<const PropertyInputImpl*>( baseProperty );
854   }
855
856   return property;
857 }
858
859 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
860 {
861   return Property::INVALID_COMPONENT_INDEX;
862 }
863
864 bool Renderer::OnStage() const
865 {
866   return mOnStageCount > 0;
867 }
868
869 void Renderer::Connect()
870 {
871   if( mOnStageCount == 0 )
872   {
873     mTextureSetConnector.OnStageConnect();
874   }
875   ++mOnStageCount;
876 }
877
878 void Renderer::Disconnect()
879 {
880   --mOnStageCount;
881   if( mOnStageCount == 0 )
882   {
883     mTextureSetConnector.OnStageDisconnect();
884   }
885 }
886
887 Renderer::Renderer()
888 : mSceneObject(NULL ),
889   mBlendColor( NULL ),
890   mDepthIndex( 0 ),
891   mOnStageCount( 0 ),
892   mIndexedDrawFirstElement( 0 ),
893   mIndexedDrawElementCount( 0 ),
894   mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
895   mBlendingOptions(),
896   mDepthFunction( DepthFunction::LESS ),
897   mFaceCullingMode( FaceCullingMode::NONE ),
898   mBlendMode( BlendMode::AUTO ),
899   mDepthWriteMode( DepthWriteMode::AUTO ),
900   mDepthTestMode( DepthTestMode::AUTO ),
901   mPremultipledAlphaEnabled( false )
902 {
903 }
904
905 void Renderer::Initialize()
906 {
907   EventThreadServices& eventThreadServices = GetEventThreadServices();
908   SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
909
910   mSceneObject = SceneGraph::Renderer::New();
911   AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
912
913   eventThreadServices.RegisterObject( this );
914 }
915
916 Renderer::~Renderer()
917 {
918   if( EventThreadServices::IsCoreRunning() )
919   {
920     EventThreadServices& eventThreadServices = GetEventThreadServices();
921     SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
922     RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
923
924     eventThreadServices.UnregisterObject( this );
925   }
926 }
927
928 } // namespace Internal
929 } // namespace Dali