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