2 * Copyright (c) 2016 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::SetBlendColor( const Vector4& color )
297 mBlendColor = new Vector4();
299 if( *mBlendColor != color )
301 *mBlendColor = color;
302 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
306 Vector4 Renderer::GetBlendColor() const
312 return Color::TRANSPARENT; // GL default
315 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
317 if( firstElement != mIndexedDrawFirstElement )
319 mIndexedDrawFirstElement = firstElement;
320 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
324 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
326 if( elementsCount != mIndexedDrawElementCount )
328 mIndexedDrawElementCount = elementsCount;
329 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
334 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
336 if( mPremultipledAlphaEnabled != preMultipled )
340 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
342 mPremultipledAlphaEnabled = preMultipled;
343 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
347 bool Renderer::IsPreMultipliedAlphaEnabled() const
349 return mPremultipledAlphaEnabled;
352 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
357 unsigned int Renderer::GetDefaultPropertyCount() const
359 return RENDERER_IMPL.GetDefaultPropertyCount();
362 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
364 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
367 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
369 return RENDERER_IMPL.GetDefaultPropertyName( index );
372 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
374 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
377 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
379 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
382 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
384 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
387 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
389 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
392 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
394 return RENDERER_IMPL.GetDefaultPropertyType( index );
397 void Renderer::SetDefaultProperty( Property::Index index,
398 const Property::Value& propertyValue )
402 case Dali::Renderer::Property::DEPTH_INDEX:
404 SetDepthIndex( propertyValue.Get<int>() );
407 case Dali::Renderer::Property::FACE_CULLING_MODE:
409 FaceCullingMode::Type convertedValue = mFaceCullingMode;
410 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
412 mFaceCullingMode = convertedValue;
413 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
417 case Dali::Renderer::Property::BLEND_MODE:
419 BlendMode::Type convertedValue = mBlendMode;
420 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
422 SetBlendMode( convertedValue );
426 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
428 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
430 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
432 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
433 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
434 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
438 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
440 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
442 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
444 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
445 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
446 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
450 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
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, sourceFactorRgb ) )
457 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
461 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
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, destinationFactorRgb ) )
468 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
472 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
474 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
475 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
477 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
479 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
483 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
485 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
486 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
488 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
490 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
494 case Dali::Renderer::Property::BLEND_COLOR:
497 if( propertyValue.Get( blendColor ) )
499 SetBlendColor( blendColor );
503 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
506 if( propertyValue.Get( preMultipled ) )
508 EnablePreMultipliedAlpha( preMultipled );
512 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
515 if( propertyValue.Get( firstElement ) )
517 SetIndexedDrawFirstElement( firstElement );
521 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
524 if( propertyValue.Get( elementsCount ) )
526 SetIndexedDrawElementsCount( elementsCount );
530 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
532 DepthWriteMode::Type convertedValue = mDepthWriteMode;
533 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
535 mDepthWriteMode = convertedValue;
536 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
540 case Dali::Renderer::Property::DEPTH_FUNCTION:
542 DepthFunction::Type convertedValue = mDepthFunction;
543 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
545 mDepthFunction = convertedValue;
546 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
550 case Dali::Renderer::Property::DEPTH_TEST_MODE:
552 DepthTestMode::Type convertedValue = mDepthTestMode;
553 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
555 mDepthTestMode = convertedValue;
556 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
560 case Dali::Renderer::Property::RENDER_MODE:
562 RenderMode::Type convertedValue = mStencilParameters.renderMode;
563 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
565 mStencilParameters.renderMode = convertedValue;
566 SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
570 case Dali::Renderer::Property::STENCIL_FUNCTION:
572 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
573 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
575 mStencilParameters.stencilFunction = convertedValue;
576 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
580 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
582 int stencilFunctionMask;
583 if( propertyValue.Get( stencilFunctionMask ) )
585 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
587 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
588 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
593 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
595 int stencilFunctionReference;
596 if( propertyValue.Get( stencilFunctionReference ) )
598 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
600 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
601 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
606 case Dali::Renderer::Property::STENCIL_MASK:
609 if( propertyValue.Get( stencilMask ) )
611 if( stencilMask != mStencilParameters.stencilMask )
613 mStencilParameters.stencilMask = stencilMask;
614 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
619 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
621 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
622 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
624 mStencilParameters.stencilOperationOnFail = convertedValue;
625 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
629 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
631 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
632 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
634 mStencilParameters.stencilOperationOnZFail = convertedValue;
635 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
639 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
641 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
642 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
644 mStencilParameters.stencilOperationOnZPass = convertedValue;
645 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
652 void Renderer::SetSceneGraphProperty( Property::Index index,
653 const PropertyMetadata& entry,
654 const Property::Value& value )
656 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
657 OnPropertySet(index, value);
660 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
662 Property::Value value;
665 case Dali::Renderer::Property::DEPTH_INDEX:
667 value = GetDepthIndex();
670 case Dali::Renderer::Property::FACE_CULLING_MODE:
672 value = mFaceCullingMode;
675 case Dali::Renderer::Property::BLEND_MODE:
680 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
682 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
685 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
687 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
690 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
692 BlendFactor::Type srcFactorRgb;
693 BlendFactor::Type destFactorRgb;
694 BlendFactor::Type srcFactorAlpha;
695 BlendFactor::Type destFactorAlpha;
696 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
697 value = static_cast<int>( srcFactorRgb );
700 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
702 BlendFactor::Type srcFactorRgb;
703 BlendFactor::Type destFactorRgb;
704 BlendFactor::Type srcFactorAlpha;
705 BlendFactor::Type destFactorAlpha;
706 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
707 value = static_cast<int>( destFactorRgb );
710 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
712 BlendFactor::Type srcFactorRgb;
713 BlendFactor::Type destFactorRgb;
714 BlendFactor::Type srcFactorAlpha;
715 BlendFactor::Type destFactorAlpha;
716 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
717 value = static_cast<int>( srcFactorAlpha );
720 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
722 BlendFactor::Type srcFactorRgb;
723 BlendFactor::Type destFactorRgb;
724 BlendFactor::Type srcFactorAlpha;
725 BlendFactor::Type destFactorAlpha;
726 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
727 value = static_cast<int>( destFactorAlpha );
730 case Dali::Renderer::Property::BLEND_COLOR:
734 value = *mBlendColor;
738 value = Color::TRANSPARENT;
742 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
744 value = IsPreMultipliedAlphaEnabled();
747 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
749 value = static_cast<int>( mIndexedDrawFirstElement );
752 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
754 value = static_cast<int>( mIndexedDrawElementCount );
757 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
759 value = mDepthWriteMode;
762 case Dali::Renderer::Property::DEPTH_FUNCTION:
764 value = mDepthFunction;
767 case Dali::Renderer::Property::DEPTH_TEST_MODE:
769 value = mDepthTestMode;
772 case Dali::Renderer::Property::STENCIL_FUNCTION:
774 value = mStencilParameters.stencilFunction;
777 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
779 value = mStencilParameters.stencilFunctionMask;
782 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
784 value = mStencilParameters.stencilFunctionReference;
787 case Dali::Renderer::Property::STENCIL_MASK:
789 value = mStencilParameters.stencilMask;
792 case Dali::Renderer::Property::RENDER_MODE:
794 value = mStencilParameters.renderMode;
797 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
799 value = mStencilParameters.stencilOperationOnFail;
802 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
804 value = mStencilParameters.stencilOperationOnZFail;
807 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
809 value = mStencilParameters.stencilOperationOnZPass;
816 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
821 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
826 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
828 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
829 const SceneGraph::PropertyBase* property = NULL;
831 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
833 &Renderer::FindAnimatableProperty,
834 &Renderer::FindCustomProperty,
840 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
842 const PropertyInputImpl* property = NULL;
844 const SceneGraph::PropertyBase* baseProperty =
845 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
846 &Renderer::FindAnimatableProperty,
847 &Renderer::FindCustomProperty,
849 property = static_cast<const PropertyInputImpl*>( baseProperty );
854 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
856 return Property::INVALID_COMPONENT_INDEX;
860 : mSceneObject(NULL ),
863 mIndexedDrawFirstElement( 0 ),
864 mIndexedDrawElementCount( 0 ),
865 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
867 mDepthFunction( DepthFunction::LESS ),
868 mFaceCullingMode( FaceCullingMode::NONE ),
869 mBlendMode( BlendMode::AUTO ),
870 mDepthWriteMode( DepthWriteMode::AUTO ),
871 mDepthTestMode( DepthTestMode::AUTO ),
872 mPremultipledAlphaEnabled( false )
876 void Renderer::Initialize()
878 EventThreadServices& eventThreadServices = GetEventThreadServices();
879 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
881 mSceneObject = SceneGraph::Renderer::New();
882 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
884 eventThreadServices.RegisterObject( this );
887 Renderer::~Renderer()
889 if( EventThreadServices::IsCoreRunning() )
891 EventThreadServices& eventThreadServices = GetEventThreadServices();
892 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
893 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
895 eventThreadServices.UnregisterObject( this );
899 } // namespace Internal