2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
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>
41 * Properties: |name |type |writable|animatable|constraint-input|enum for index-checking|
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 )
70 // Property string to enumeration tables:
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 )
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 )
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 )
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 )
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 )
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 )
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 )
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 )
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 )
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 )
162 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
166 return Dali::BaseHandle();
169 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
171 } // unnamed namespace
173 RendererPtr Renderer::New()
175 RendererPtr rendererPtr( new Renderer() );
176 rendererPtr->Initialize();
180 void Renderer::SetGeometry( Geometry& geometry )
182 mGeometry = &geometry;
184 const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
185 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
188 Geometry* Renderer::GetGeometry() const
190 return mGeometry.Get();
193 void Renderer::SetTextures( TextureSet& textureSet )
195 mTextureSet = &textureSet;
196 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
197 SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
200 TextureSet* Renderer::GetTextures() const
202 return mTextureSet.Get();
205 void Renderer::SetShader( Shader& shader )
208 SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
209 SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
212 Shader* Renderer::GetShader() const
214 return mShader.Get();
217 void Renderer::SetDepthIndex( int depthIndex )
219 if ( mDepthIndex != depthIndex )
221 mDepthIndex = depthIndex;
222 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
226 int Renderer::GetDepthIndex() const
231 void Renderer::SetBlendMode( BlendMode::Type mode )
233 if( mBlendMode != mode )
237 SetBlendModeMessage( GetEventThreadServices(), *mSceneObject, mBlendMode );
241 BlendMode::Type Renderer::GetBlendMode() const
246 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
248 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
249 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
252 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
253 BlendFactor::Type destFactorRgb,
254 BlendFactor::Type srcFactorAlpha,
255 BlendFactor::Type destFactorAlpha )
257 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
258 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
261 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
262 BlendFactor::Type& destFactorRgb,
263 BlendFactor::Type& srcFactorAlpha,
264 BlendFactor::Type& destFactorAlpha ) const
266 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
267 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
268 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
269 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
272 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
274 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
275 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
278 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
279 BlendEquation::Type equationAlpha )
281 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
282 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
285 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
286 BlendEquation::Type& equationAlpha ) const
288 // These are not animatable, the cached values are up-to-date.
289 equationRgb = mBlendingOptions.GetBlendEquationRgb();
290 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
293 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
295 if( firstElement != mIndexedDrawFirstElement )
297 mIndexedDrawFirstElement = firstElement;
298 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
302 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
304 if( elementsCount != mIndexedDrawElementCount )
306 mIndexedDrawElementCount = elementsCount;
307 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
312 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
314 if( mPremultipledAlphaEnabled != preMultipled )
318 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
320 mPremultipledAlphaEnabled = preMultipled;
321 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
325 bool Renderer::IsPreMultipliedAlphaEnabled() const
327 return mPremultipledAlphaEnabled;
330 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
335 unsigned int Renderer::GetDefaultPropertyCount() const
337 return RENDERER_IMPL.GetDefaultPropertyCount();
340 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
342 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
345 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
347 return RENDERER_IMPL.GetDefaultPropertyName( index );
350 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
352 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
355 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
357 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
360 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
362 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
365 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
367 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
370 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
372 return RENDERER_IMPL.GetDefaultPropertyType( index );
375 void Renderer::SetDefaultProperty( Property::Index index,
376 const Property::Value& propertyValue )
380 case Dali::Renderer::Property::DEPTH_INDEX:
382 SetDepthIndex( propertyValue.Get<int>() );
385 case Dali::Renderer::Property::FACE_CULLING_MODE:
387 FaceCullingMode::Type convertedValue = mFaceCullingMode;
388 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
390 mFaceCullingMode = convertedValue;
391 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
395 case Dali::Renderer::Property::BLEND_MODE:
397 BlendMode::Type convertedValue = mBlendMode;
398 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
400 SetBlendMode( convertedValue );
404 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
406 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
408 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
410 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
411 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
412 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
416 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
418 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
420 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
422 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
423 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
424 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
428 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
430 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
431 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
433 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
435 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
439 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
441 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
442 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
444 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
446 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
450 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
452 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
453 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
455 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
457 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
461 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
463 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
464 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
466 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
468 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
472 case Dali::Renderer::Property::BLEND_COLOR:
475 if( propertyValue.Get( blendColor ) )
477 SetBlendColor( blendColor );
481 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
484 if( propertyValue.Get( preMultipled ) )
486 EnablePreMultipliedAlpha( preMultipled );
490 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
493 if( propertyValue.Get( firstElement ) )
495 SetIndexedDrawFirstElement( firstElement );
499 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
502 if( propertyValue.Get( elementsCount ) )
504 SetIndexedDrawElementsCount( elementsCount );
508 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
510 DepthWriteMode::Type convertedValue = mDepthWriteMode;
511 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
513 mDepthWriteMode = convertedValue;
514 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
518 case Dali::Renderer::Property::DEPTH_FUNCTION:
520 DepthFunction::Type convertedValue = mDepthFunction;
521 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
523 mDepthFunction = convertedValue;
524 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
528 case Dali::Renderer::Property::DEPTH_TEST_MODE:
530 DepthTestMode::Type convertedValue = mDepthTestMode;
531 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
533 mDepthTestMode = convertedValue;
534 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
538 case Dali::Renderer::Property::RENDER_MODE:
540 RenderMode::Type convertedValue = mStencilParameters.renderMode;
541 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
543 mStencilParameters.renderMode = convertedValue;
544 SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
548 case Dali::Renderer::Property::STENCIL_FUNCTION:
550 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
551 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
553 mStencilParameters.stencilFunction = convertedValue;
554 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
558 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
560 int stencilFunctionMask;
561 if( propertyValue.Get( stencilFunctionMask ) )
563 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
565 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
566 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
571 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
573 int stencilFunctionReference;
574 if( propertyValue.Get( stencilFunctionReference ) )
576 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
578 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
579 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
584 case Dali::Renderer::Property::STENCIL_MASK:
587 if( propertyValue.Get( stencilMask ) )
589 if( stencilMask != mStencilParameters.stencilMask )
591 mStencilParameters.stencilMask = stencilMask;
592 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
597 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
599 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
600 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
602 mStencilParameters.stencilOperationOnFail = convertedValue;
603 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
607 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
609 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
610 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
612 mStencilParameters.stencilOperationOnZFail = convertedValue;
613 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
617 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
619 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
620 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
622 mStencilParameters.stencilOperationOnZPass = convertedValue;
623 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
630 void Renderer::SetSceneGraphProperty( Property::Index index,
631 const PropertyMetadata& entry,
632 const Property::Value& value )
634 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
635 OnPropertySet(index, value);
638 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
640 Property::Value value;
643 case Dali::Renderer::Property::DEPTH_INDEX:
645 value = GetDepthIndex();
648 case Dali::Renderer::Property::FACE_CULLING_MODE:
650 value = mFaceCullingMode;
653 case Dali::Renderer::Property::BLEND_MODE:
658 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
660 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
663 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
665 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
668 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
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 );
678 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
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 );
688 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
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 );
698 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
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 );
708 case Dali::Renderer::Property::BLEND_COLOR:
710 value = GetBlendColor();
713 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
715 value = IsPreMultipliedAlphaEnabled();
718 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
720 value = static_cast<int>( mIndexedDrawFirstElement );
723 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
725 value = static_cast<int>( mIndexedDrawElementCount );
728 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
730 value = mDepthWriteMode;
733 case Dali::Renderer::Property::DEPTH_FUNCTION:
735 value = mDepthFunction;
738 case Dali::Renderer::Property::DEPTH_TEST_MODE:
740 value = mDepthTestMode;
743 case Dali::Renderer::Property::STENCIL_FUNCTION:
745 value = mStencilParameters.stencilFunction;
748 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
750 value = mStencilParameters.stencilFunctionMask;
753 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
755 value = mStencilParameters.stencilFunctionReference;
758 case Dali::Renderer::Property::STENCIL_MASK:
760 value = mStencilParameters.stencilMask;
763 case Dali::Renderer::Property::RENDER_MODE:
765 value = mStencilParameters.renderMode;
768 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
770 value = mStencilParameters.stencilOperationOnFail;
773 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
775 value = mStencilParameters.stencilOperationOnZFail;
778 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
780 value = mStencilParameters.stencilOperationOnZPass;
787 Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const
789 return GetDefaultProperty( index ); // Event-side only properties
792 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
797 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
802 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
804 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
805 const SceneGraph::PropertyBase* property = NULL;
807 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
809 &Renderer::FindAnimatableProperty,
810 &Renderer::FindCustomProperty,
816 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
818 const PropertyInputImpl* property = NULL;
820 const SceneGraph::PropertyBase* baseProperty =
821 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
822 &Renderer::FindAnimatableProperty,
823 &Renderer::FindCustomProperty,
825 property = static_cast<const PropertyInputImpl*>( baseProperty );
830 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
832 return Property::INVALID_COMPONENT_INDEX;
836 : mSceneObject(NULL ),
838 mIndexedDrawFirstElement( 0 ),
839 mIndexedDrawElementCount( 0 ),
840 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
842 mDepthFunction( DepthFunction::LESS ),
843 mFaceCullingMode( FaceCullingMode::NONE ),
844 mBlendMode( BlendMode::AUTO ),
845 mDepthWriteMode( DepthWriteMode::AUTO ),
846 mDepthTestMode( DepthTestMode::AUTO ),
847 mPremultipledAlphaEnabled( false )
851 void Renderer::Initialize()
853 EventThreadServices& eventThreadServices = GetEventThreadServices();
854 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
856 mSceneObject = SceneGraph::Renderer::New();
857 OwnerPointer< SceneGraph::Renderer > transferOwnership( mSceneObject );
858 AddRendererMessage( updateManager, transferOwnership );
860 eventThreadServices.RegisterObject( this );
863 void Renderer::SetBlendColor( const Vector4& blendColor )
865 mBlendingOptions.SetBlendColor( blendColor );
866 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() );
869 const Vector4& Renderer::GetBlendColor() const
871 const Vector4* blendColor = mBlendingOptions.GetBlendColor();
876 return Color::TRANSPARENT; // GL default
879 Renderer::~Renderer()
881 if( EventThreadServices::IsCoreRunning() )
883 EventThreadServices& eventThreadServices = GetEventThreadServices();
884 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
885 RemoveRendererMessage( updateManager, *mSceneObject );
887 eventThreadServices.UnregisterObject( this );
891 } // namespace Internal