2 * Copyright (c) 2018 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( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
69 DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX, RendererDefaultProperties )
71 // Property string to enumeration tables:
73 DALI_ENUM_TO_STRING_TABLE_BEGIN( FACE_CULLING_MODE )
74 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, NONE )
75 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT )
76 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, BACK )
77 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT_AND_BACK )
78 DALI_ENUM_TO_STRING_TABLE_END( FACE_CULLING_MODE )
80 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_MODE )
81 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, OFF )
82 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, AUTO )
83 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, ON )
84 DALI_ENUM_TO_STRING_TABLE_END( BLEND_MODE )
86 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_EQUATION )
87 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, ADD )
88 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, SUBTRACT )
89 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, REVERSE_SUBTRACT )
90 DALI_ENUM_TO_STRING_TABLE_END( BLEND_EQUATION )
92 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_FACTOR )
93 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ZERO )
94 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE )
95 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_COLOR )
96 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_COLOR )
97 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA )
98 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_ALPHA )
99 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_ALPHA )
100 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_ALPHA )
101 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_COLOR )
102 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_COLOR )
103 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA_SATURATE )
104 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_COLOR )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_COLOR )
106 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_ALPHA )
107 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_ALPHA )
108 DALI_ENUM_TO_STRING_TABLE_END( BLEND_FACTOR )
110 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_WRITE_MODE )
111 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, OFF )
112 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, AUTO )
113 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, ON )
114 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_WRITE_MODE )
116 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_TEST_MODE )
117 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, OFF )
118 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, AUTO )
119 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, ON )
120 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_TEST_MODE )
122 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_FUNCTION )
123 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NEVER )
124 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, ALWAYS )
125 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS )
126 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER )
127 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, EQUAL )
128 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NOT_EQUAL )
129 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS_EQUAL )
130 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER_EQUAL )
131 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_FUNCTION )
133 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_FUNCTION )
134 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NEVER )
135 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS )
136 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, EQUAL )
137 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS_EQUAL )
138 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER )
139 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NOT_EQUAL )
140 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER_EQUAL )
141 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, ALWAYS )
142 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_FUNCTION )
144 DALI_ENUM_TO_STRING_TABLE_BEGIN( RENDER_MODE )
145 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, NONE )
146 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, AUTO )
147 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR )
148 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, STENCIL )
149 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR_STENCIL )
150 DALI_ENUM_TO_STRING_TABLE_END( RENDER_MODE )
152 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_OPERATION )
153 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, ZERO )
154 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, KEEP )
155 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, REPLACE )
156 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT )
157 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT )
158 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INVERT )
159 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT_WRAP )
160 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT_WRAP )
161 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_OPERATION )
165 return Dali::BaseHandle();
168 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create, RendererDefaultProperties );
170 } // unnamed namespace
172 RendererPtr Renderer::New()
174 RendererPtr rendererPtr( new Renderer() );
175 rendererPtr->Initialize();
179 void Renderer::SetGeometry( Geometry& geometry )
181 mGeometry = &geometry;
183 const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
184 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
187 Geometry* Renderer::GetGeometry() const
189 return mGeometry.Get();
192 void Renderer::SetTextures( TextureSet& textureSet )
194 mTextureSet = &textureSet;
195 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
196 SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
199 TextureSet* Renderer::GetTextures() const
201 return mTextureSet.Get();
204 void Renderer::SetShader( Shader& shader )
207 SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
208 SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
211 Shader* Renderer::GetShader() const
213 return mShader.Get();
216 void Renderer::SetDepthIndex( int depthIndex )
218 if ( mDepthIndex != depthIndex )
220 mDepthIndex = depthIndex;
221 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
225 int Renderer::GetDepthIndex() const
230 void Renderer::SetBlendMode( BlendMode::Type mode )
232 if( mBlendMode != mode )
236 SetBlendModeMessage( GetEventThreadServices(), *mSceneObject, mBlendMode );
240 BlendMode::Type Renderer::GetBlendMode() const
245 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
247 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
248 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
251 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
252 BlendFactor::Type destFactorRgb,
253 BlendFactor::Type srcFactorAlpha,
254 BlendFactor::Type destFactorAlpha )
256 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
257 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
260 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
261 BlendFactor::Type& destFactorRgb,
262 BlendFactor::Type& srcFactorAlpha,
263 BlendFactor::Type& destFactorAlpha ) const
265 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
266 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
267 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
268 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
271 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
273 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
274 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
277 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
278 BlendEquation::Type equationAlpha )
280 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
281 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
284 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
285 BlendEquation::Type& equationAlpha ) const
287 // These are not animatable, the cached values are up-to-date.
288 equationRgb = mBlendingOptions.GetBlendEquationRgb();
289 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
292 void Renderer::SetIndexedDrawFirstElement( uint32_t firstElement )
294 if( firstElement != mIndexedDrawFirstElement )
296 mIndexedDrawFirstElement = firstElement;
297 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
301 void Renderer::SetIndexedDrawElementsCount( uint32_t elementsCount )
303 if( elementsCount != mIndexedDrawElementCount )
305 mIndexedDrawElementCount = elementsCount;
306 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
311 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
313 if( mPremultipledAlphaEnabled != preMultipled )
317 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
321 SetBlendFunc( BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
323 mPremultipledAlphaEnabled = preMultipled;
324 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
328 bool Renderer::IsPreMultipliedAlphaEnabled() const
330 return mPremultipledAlphaEnabled;
333 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
338 void Renderer::SetDefaultProperty( Property::Index index,
339 const Property::Value& propertyValue )
343 case Dali::Renderer::Property::DEPTH_INDEX:
345 SetDepthIndex( propertyValue.Get<int>() );
348 case Dali::Renderer::Property::FACE_CULLING_MODE:
350 FaceCullingMode::Type convertedValue = mFaceCullingMode;
351 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
353 mFaceCullingMode = convertedValue;
354 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
358 case Dali::Renderer::Property::BLEND_MODE:
360 BlendMode::Type convertedValue = mBlendMode;
361 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
363 SetBlendMode( convertedValue );
367 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
369 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
371 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
373 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
374 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
375 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
379 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
381 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
383 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
385 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
386 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
387 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
391 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
393 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
394 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
396 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
398 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
402 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
404 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
405 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
407 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
409 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
413 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
415 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
416 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
418 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
420 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
424 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
426 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
427 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
429 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
431 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
435 case Dali::Renderer::Property::BLEND_COLOR:
438 if( propertyValue.Get( blendColor ) )
440 SetBlendColor( blendColor );
444 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
447 if( propertyValue.Get( preMultipled ) )
449 EnablePreMultipliedAlpha( preMultipled );
453 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
456 if( propertyValue.Get( firstElement ) )
458 SetIndexedDrawFirstElement( firstElement );
462 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
465 if( propertyValue.Get( elementsCount ) )
467 SetIndexedDrawElementsCount( elementsCount );
471 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
473 DepthWriteMode::Type convertedValue = mDepthWriteMode;
474 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
476 mDepthWriteMode = convertedValue;
477 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
481 case Dali::Renderer::Property::DEPTH_FUNCTION:
483 DepthFunction::Type convertedValue = mDepthFunction;
484 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
486 mDepthFunction = convertedValue;
487 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
491 case Dali::Renderer::Property::DEPTH_TEST_MODE:
493 DepthTestMode::Type convertedValue = mDepthTestMode;
494 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
496 mDepthTestMode = convertedValue;
497 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
501 case Dali::Renderer::Property::RENDER_MODE:
503 RenderMode::Type convertedValue = mStencilParameters.renderMode;
504 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
506 mStencilParameters.renderMode = convertedValue;
507 SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
511 case Dali::Renderer::Property::STENCIL_FUNCTION:
513 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
514 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
516 mStencilParameters.stencilFunction = convertedValue;
517 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
521 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
523 int stencilFunctionMask;
524 if( propertyValue.Get( stencilFunctionMask ) )
526 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
528 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
529 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
534 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
536 int stencilFunctionReference;
537 if( propertyValue.Get( stencilFunctionReference ) )
539 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
541 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
542 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
547 case Dali::Renderer::Property::STENCIL_MASK:
550 if( propertyValue.Get( stencilMask ) )
552 if( stencilMask != mStencilParameters.stencilMask )
554 mStencilParameters.stencilMask = stencilMask;
555 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
560 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
562 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
563 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
565 mStencilParameters.stencilOperationOnFail = convertedValue;
566 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
570 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
572 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
573 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
575 mStencilParameters.stencilOperationOnZFail = convertedValue;
576 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
580 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
582 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
583 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
585 mStencilParameters.stencilOperationOnZPass = convertedValue;
586 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
590 case Dali::DevelRenderer::Property::OPACITY:
593 if( propertyValue.Get( opacity ) )
595 if( !Equals( mOpacity, opacity ) )
598 BakeOpacityMessage( GetEventThreadServices(), *mSceneObject, mOpacity );
606 void Renderer::SetSceneGraphProperty( Property::Index index,
607 const PropertyMetadata& entry,
608 const Property::Value& value )
610 ObjectImplHelper::SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
611 OnPropertySet(index, value);
614 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
616 Property::Value value;
618 if( ! GetCachedPropertyValue( index, value ) )
620 // If property value is not stored in the event-side, then it must be a scene-graph only property
621 GetCurrentPropertyValue( index, value );
627 Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const
629 Property::Value value;
631 if( ! GetCurrentPropertyValue( index, value ) )
633 // If unable to retrieve scene-graph property value, then it must be an event-side only property
634 GetCachedPropertyValue( index, value );
640 void Renderer::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
642 switch( animationType )
645 case Animation::BETWEEN:
649 case Dali::DevelRenderer::Property::OPACITY:
651 value.Get( mOpacity );
662 case Dali::DevelRenderer::Property::OPACITY:
664 AdjustValue< float >( mOpacity, value );
673 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
678 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
683 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
685 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
686 const SceneGraph::PropertyBase* property = NULL;
688 property = ObjectImplHelper::GetRegisteredSceneGraphProperty( this,
689 &Renderer::FindAnimatableProperty,
690 &Renderer::FindCustomProperty,
695 if( index == DevelRenderer::Property::OPACITY )
697 property = &mSceneObject->mOpacity;
704 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
706 const PropertyInputImpl* property = NULL;
708 const SceneGraph::PropertyBase* baseProperty = ObjectImplHelper::GetRegisteredSceneGraphProperty( this,
709 &Renderer::FindAnimatableProperty,
710 &Renderer::FindCustomProperty,
712 property = static_cast<const PropertyInputImpl*>( baseProperty );
717 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
719 return Property::INVALID_COMPONENT_INDEX;
723 : mSceneObject(NULL ),
725 mIndexedDrawFirstElement( 0 ),
726 mIndexedDrawElementCount( 0 ),
727 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
730 mDepthFunction( DepthFunction::LESS ),
731 mFaceCullingMode( FaceCullingMode::NONE ),
732 mBlendMode( BlendMode::AUTO ),
733 mDepthWriteMode( DepthWriteMode::AUTO ),
734 mDepthTestMode( DepthTestMode::AUTO ),
735 mPremultipledAlphaEnabled( false )
739 void Renderer::Initialize()
741 EventThreadServices& eventThreadServices = GetEventThreadServices();
742 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
744 mSceneObject = SceneGraph::Renderer::New();
745 OwnerPointer< SceneGraph::Renderer > transferOwnership( mSceneObject );
746 AddRendererMessage( updateManager, transferOwnership );
748 eventThreadServices.RegisterObject( this );
751 void Renderer::SetBlendColor( const Vector4& blendColor )
753 mBlendingOptions.SetBlendColor( blendColor );
754 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() );
757 const Vector4& Renderer::GetBlendColor() const
759 const Vector4* blendColor = mBlendingOptions.GetBlendColor();
764 return Color::TRANSPARENT; // GL default
767 Renderer::~Renderer()
769 if( EventThreadServices::IsCoreRunning() )
771 EventThreadServices& eventThreadServices = GetEventThreadServices();
772 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
773 RemoveRendererMessage( updateManager, *mSceneObject );
775 eventThreadServices.UnregisterObject( this );
779 bool Renderer::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const
781 bool valueSet = true;
785 case Dali::Renderer::Property::DEPTH_INDEX:
787 value = GetDepthIndex();
790 case Dali::Renderer::Property::FACE_CULLING_MODE:
792 value = mFaceCullingMode;
795 case Dali::Renderer::Property::BLEND_MODE:
800 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
802 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationRgb() );
805 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
807 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationAlpha() );
810 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
812 BlendFactor::Type srcFactorRgb;
813 BlendFactor::Type destFactorRgb;
814 BlendFactor::Type srcFactorAlpha;
815 BlendFactor::Type destFactorAlpha;
816 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
817 value = static_cast<int32_t>( srcFactorRgb );
820 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
822 BlendFactor::Type srcFactorRgb;
823 BlendFactor::Type destFactorRgb;
824 BlendFactor::Type srcFactorAlpha;
825 BlendFactor::Type destFactorAlpha;
826 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
827 value = static_cast<int32_t>( destFactorRgb );
830 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
832 BlendFactor::Type srcFactorRgb;
833 BlendFactor::Type destFactorRgb;
834 BlendFactor::Type srcFactorAlpha;
835 BlendFactor::Type destFactorAlpha;
836 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
837 value = static_cast<int32_t>( srcFactorAlpha );
840 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
842 BlendFactor::Type srcFactorRgb;
843 BlendFactor::Type destFactorRgb;
844 BlendFactor::Type srcFactorAlpha;
845 BlendFactor::Type destFactorAlpha;
846 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
847 value = static_cast<int32_t>( destFactorAlpha );
850 case Dali::Renderer::Property::BLEND_COLOR:
852 value = GetBlendColor();
855 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
857 value = IsPreMultipliedAlphaEnabled();
860 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
862 value = static_cast<int32_t>( mIndexedDrawFirstElement );
865 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
867 value = static_cast<int32_t>( mIndexedDrawElementCount );
870 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
872 value = mDepthWriteMode;
875 case Dali::Renderer::Property::DEPTH_FUNCTION:
877 value = mDepthFunction;
880 case Dali::Renderer::Property::DEPTH_TEST_MODE:
882 value = mDepthTestMode;
885 case Dali::Renderer::Property::STENCIL_FUNCTION:
887 value = mStencilParameters.stencilFunction;
890 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
892 value = mStencilParameters.stencilFunctionMask;
895 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
897 value = mStencilParameters.stencilFunctionReference;
900 case Dali::Renderer::Property::STENCIL_MASK:
902 value = mStencilParameters.stencilMask;
905 case Dali::Renderer::Property::RENDER_MODE:
907 value = mStencilParameters.renderMode;
910 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
912 value = mStencilParameters.stencilOperationOnFail;
915 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
917 value = mStencilParameters.stencilOperationOnZFail;
920 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
922 value = mStencilParameters.stencilOperationOnZPass;
925 case Dali::DevelRenderer::Property::OPACITY:
932 // Must be a scene-graph only property
941 bool Renderer::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const
943 bool valueSet = true;
947 case Dali::Renderer::Property::DEPTH_INDEX:
949 value = mSceneObject->GetDepthIndex();
952 case Dali::Renderer::Property::FACE_CULLING_MODE:
954 value = mSceneObject->GetFaceCullingMode();
957 case Dali::Renderer::Property::BLEND_MODE:
959 value = mSceneObject->GetBlendMode();
962 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
964 uint32_t bitMask = mSceneObject->GetBlendingOptions();
965 BlendingOptions blendingOptions;
966 blendingOptions.SetBitmask( bitMask );
967 value = static_cast<int32_t>( blendingOptions.GetBlendEquationRgb() );
970 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
972 uint32_t bitMask = mSceneObject->GetBlendingOptions();
973 BlendingOptions blendingOptions;
974 blendingOptions.SetBitmask( bitMask );
975 value = static_cast<int32_t>( blendingOptions.GetBlendEquationAlpha() );
978 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
980 uint32_t bitMask = mSceneObject->GetBlendingOptions();
981 BlendingOptions blendingOptions;
982 blendingOptions.SetBitmask( bitMask );
983 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorRgb() );
986 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
988 uint32_t bitMask = mSceneObject->GetBlendingOptions();
989 BlendingOptions blendingOptions;
990 blendingOptions.SetBitmask( bitMask );
991 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorRgb() );
994 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
996 uint32_t bitMask = mSceneObject->GetBlendingOptions();
997 BlendingOptions blendingOptions;
998 blendingOptions.SetBitmask( bitMask );
999 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorAlpha() );
1002 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
1004 uint32_t bitMask = mSceneObject->GetBlendingOptions();
1005 BlendingOptions blendingOptions;
1006 blendingOptions.SetBitmask( bitMask );
1007 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorAlpha() );
1010 case Dali::Renderer::Property::BLEND_COLOR:
1012 value = mSceneObject->GetBlendColor();
1015 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
1017 value = mSceneObject->IsPreMultipliedAlphaEnabled();
1020 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
1022 value = static_cast<int>( mSceneObject->GetIndexedDrawFirstElement() );
1025 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
1027 value = static_cast<int>( mSceneObject->GetIndexedDrawElementsCount() );
1030 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
1032 value = mSceneObject->GetDepthWriteMode();
1035 case Dali::Renderer::Property::DEPTH_FUNCTION:
1037 value = mSceneObject->GetDepthFunction();
1040 case Dali::Renderer::Property::DEPTH_TEST_MODE:
1042 value = mSceneObject->GetDepthTestMode();
1045 case Dali::Renderer::Property::STENCIL_FUNCTION:
1047 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1048 value = stencilParameters.stencilFunction;
1051 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
1053 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1054 value = stencilParameters.stencilFunctionMask;
1057 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
1059 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1060 value = stencilParameters.stencilFunctionReference;
1063 case Dali::Renderer::Property::STENCIL_MASK:
1065 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1066 value = stencilParameters.stencilMask;
1069 case Dali::Renderer::Property::RENDER_MODE:
1071 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1072 value = stencilParameters.renderMode;
1075 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
1077 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1078 value = stencilParameters.stencilOperationOnFail;
1081 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
1083 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1084 value = stencilParameters.stencilOperationOnZFail;
1087 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
1089 Render::Renderer::StencilParameters stencilParameters = mSceneObject->GetStencilParameters();
1090 value = stencilParameters.stencilOperationOnZPass;
1093 case Dali::DevelRenderer::Property::OPACITY:
1095 value = mSceneObject->GetOpacity( GetEventThreadServices().GetEventBufferIndex() );
1100 // Must be an event-side only property
1109 } // namespace Internal