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/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
26 #include <dali/internal/event/common/property-input-impl.h>
27 #include <dali/internal/render/renderers/render-geometry.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/rendering/scene-graph-renderer.h>
40 * Properties: |name |type |writable|animatable|constraint-input|enum for index-checking|
42 DALI_PROPERTY_TABLE_BEGIN
43 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
44 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
45 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
46 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
47 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
48 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
49 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
50 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
51 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
52 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
53 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
54 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
55 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
56 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
57 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
58 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
59 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
60 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
61 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
62 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
63 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
64 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
65 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
66 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
67 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
68 DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX, RendererDefaultProperties )
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 )
164 return Dali::BaseHandle();
167 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create, RendererDefaultProperties );
169 } // unnamed namespace
171 RendererPtr Renderer::New()
173 // create scene object first so it's guaranteed to exist for the event side
174 auto sceneObject = SceneGraph::Renderer::New();
175 OwnerPointer< SceneGraph::Renderer > transferOwnership( sceneObject );
176 // pass the pointer to base for message passing
177 RendererPtr rendererPtr( new Renderer( sceneObject ) );
178 // transfer scene object ownership to update manager
179 EventThreadServices& eventThreadServices = rendererPtr->GetEventThreadServices();
180 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
181 AddRendererMessage( updateManager, transferOwnership );
183 eventThreadServices.RegisterObject( rendererPtr.Get() );
187 void Renderer::SetGeometry( Geometry& geometry )
189 mGeometry = &geometry;
191 const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
192 SetGeometryMessage( GetEventThreadServices(), GetRendererSceneObject(), *geometrySceneObject );
195 GeometryPtr Renderer::GetGeometry() const
200 void Renderer::SetTextures( TextureSet& textureSet )
202 mTextureSet = &textureSet;
203 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
204 SetTexturesMessage( GetEventThreadServices(), GetRendererSceneObject(), *textureSetSceneObject );
207 TextureSetPtr Renderer::GetTextures() const
212 void Renderer::SetShader( Shader& shader )
215 const SceneGraph::Shader& sceneGraphShader = shader.GetShaderSceneObject();
216 SceneGraph::SetShaderMessage( GetEventThreadServices(), GetRendererSceneObject(), sceneGraphShader );
219 ShaderPtr Renderer::GetShader() const
224 void Renderer::SetDepthIndex( int32_t depthIndex )
226 if ( mDepthIndex != depthIndex )
228 mDepthIndex = depthIndex;
229 SetDepthIndexMessage( GetEventThreadServices(), GetRendererSceneObject(), depthIndex );
233 int32_t Renderer::GetDepthIndex() const
238 void Renderer::SetBlendMode( BlendMode::Type mode )
240 if( mBlendMode != mode )
244 SetBlendModeMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendMode );
248 BlendMode::Type Renderer::GetBlendMode() const
253 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
255 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
256 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
259 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
260 BlendFactor::Type destFactorRgb,
261 BlendFactor::Type srcFactorAlpha,
262 BlendFactor::Type destFactorAlpha )
264 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
265 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
268 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
269 BlendFactor::Type& destFactorRgb,
270 BlendFactor::Type& srcFactorAlpha,
271 BlendFactor::Type& destFactorAlpha ) const
273 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
274 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
275 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
276 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
279 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
281 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
282 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
285 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
286 BlendEquation::Type equationAlpha )
288 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
289 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
292 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
293 BlendEquation::Type& equationAlpha ) const
295 // These are not animatable, the cached values are up-to-date.
296 equationRgb = mBlendingOptions.GetBlendEquationRgb();
297 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
300 void Renderer::SetIndexedDrawFirstElement( uint32_t firstElement )
302 if( firstElement != mIndexedDrawFirstElement )
304 mIndexedDrawFirstElement = firstElement;
305 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), GetRendererSceneObject(), mIndexedDrawFirstElement );
309 void Renderer::SetIndexedDrawElementsCount( uint32_t elementsCount )
311 if( elementsCount != mIndexedDrawElementCount )
313 mIndexedDrawElementCount = elementsCount;
314 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), GetRendererSceneObject(), mIndexedDrawElementCount );
319 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
321 if( mPremultipledAlphaEnabled != preMultipled )
325 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
329 SetBlendFunc( BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
331 mPremultipledAlphaEnabled = preMultipled;
332 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), GetRendererSceneObject(), mPremultipledAlphaEnabled );
336 bool Renderer::IsPreMultipliedAlphaEnabled() const
338 return mPremultipledAlphaEnabled;
341 const SceneGraph::Renderer& Renderer::GetRendererSceneObject() const
343 return static_cast<const SceneGraph::Renderer&>( GetSceneObject() );
346 void Renderer::SetDefaultProperty( Property::Index index,
347 const Property::Value& propertyValue )
351 case Dali::Renderer::Property::DEPTH_INDEX:
353 SetDepthIndex( propertyValue.Get<int32_t>() );
356 case Dali::Renderer::Property::FACE_CULLING_MODE:
358 FaceCullingMode::Type convertedValue = mFaceCullingMode;
359 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
361 mFaceCullingMode = convertedValue;
362 SetFaceCullingModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
366 case Dali::Renderer::Property::BLEND_MODE:
368 BlendMode::Type convertedValue = mBlendMode;
369 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
371 SetBlendMode( convertedValue );
375 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
377 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
379 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
381 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
382 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
383 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
387 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
389 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
391 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
393 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
394 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
395 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
399 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
401 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
402 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
404 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
406 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
410 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
412 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
413 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
415 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
417 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
421 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
423 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
424 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
426 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
428 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
432 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
434 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
435 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
437 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
439 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
443 case Dali::Renderer::Property::BLEND_COLOR:
446 if( propertyValue.Get( blendColor ) )
448 SetBlendColor( blendColor );
452 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
455 if( propertyValue.Get( preMultipled ) )
457 EnablePreMultipliedAlpha( preMultipled );
461 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
463 int32_t firstElement;
464 if( propertyValue.Get( firstElement ) )
466 SetIndexedDrawFirstElement( firstElement );
470 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
472 int32_t elementsCount;
473 if( propertyValue.Get( elementsCount ) )
475 SetIndexedDrawElementsCount( elementsCount );
479 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
481 DepthWriteMode::Type convertedValue = mDepthWriteMode;
482 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
484 mDepthWriteMode = convertedValue;
485 SetDepthWriteModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
489 case Dali::Renderer::Property::DEPTH_FUNCTION:
491 DepthFunction::Type convertedValue = mDepthFunction;
492 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
494 mDepthFunction = convertedValue;
495 SetDepthFunctionMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
499 case Dali::Renderer::Property::DEPTH_TEST_MODE:
501 DepthTestMode::Type convertedValue = mDepthTestMode;
502 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
504 mDepthTestMode = convertedValue;
505 SetDepthTestModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
509 case Dali::Renderer::Property::RENDER_MODE:
511 RenderMode::Type convertedValue = mStencilParameters.renderMode;
512 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
514 mStencilParameters.renderMode = convertedValue;
515 SetRenderModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
519 case Dali::Renderer::Property::STENCIL_FUNCTION:
521 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
522 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
524 mStencilParameters.stencilFunction = convertedValue;
525 SetStencilFunctionMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
529 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
531 int32_t stencilFunctionMask;
532 if( propertyValue.Get( stencilFunctionMask ) )
534 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
536 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
537 SetStencilFunctionMaskMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilFunctionMask );
542 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
544 int32_t stencilFunctionReference;
545 if( propertyValue.Get( stencilFunctionReference ) )
547 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
549 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
550 SetStencilFunctionReferenceMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilFunctionReference );
555 case Dali::Renderer::Property::STENCIL_MASK:
558 if( propertyValue.Get( stencilMask ) )
560 if( stencilMask != mStencilParameters.stencilMask )
562 mStencilParameters.stencilMask = stencilMask;
563 SetStencilMaskMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilMask );
568 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
570 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
571 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
573 mStencilParameters.stencilOperationOnFail = convertedValue;
574 SetStencilOperationOnFailMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
578 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
580 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
581 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
583 mStencilParameters.stencilOperationOnZFail = convertedValue;
584 SetStencilOperationOnZFailMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
588 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
590 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
591 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
593 mStencilParameters.stencilOperationOnZPass = convertedValue;
594 SetStencilOperationOnZPassMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
598 case Dali::DevelRenderer::Property::OPACITY:
601 if( propertyValue.Get( opacity ) )
603 if( !Equals( mOpacity, opacity ) )
606 BakeOpacityMessage( GetEventThreadServices(), GetRendererSceneObject(), mOpacity );
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::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
675 const SceneGraph::PropertyBase* property = NULL;
677 if( index == DevelRenderer::Property::OPACITY )
679 property = &GetRendererSceneObject().mOpacity;
683 // not our property, ask base
684 property = Object::GetSceneObjectAnimatableProperty( index );
690 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
692 // reuse animatable property getter, Object::GetSceneObjectInputProperty does the same so no need to call that0
693 return GetSceneObjectAnimatableProperty( index );
696 Renderer::Renderer( const SceneGraph::Renderer* sceneObject )
697 : Object( sceneObject ),
699 mIndexedDrawFirstElement( 0 ),
700 mIndexedDrawElementCount( 0 ),
701 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
704 mDepthFunction( DepthFunction::LESS ),
705 mFaceCullingMode( FaceCullingMode::NONE ),
706 mBlendMode( BlendMode::AUTO ),
707 mDepthWriteMode( DepthWriteMode::AUTO ),
708 mDepthTestMode( DepthTestMode::AUTO ),
709 mPremultipledAlphaEnabled( false )
713 void Renderer::SetBlendColor( const Vector4& blendColor )
715 mBlendingOptions.SetBlendColor( blendColor );
716 SetBlendColorMessage( GetEventThreadServices(), GetRendererSceneObject(), GetBlendColor() );
719 const Vector4& Renderer::GetBlendColor() const
721 const Vector4* blendColor = mBlendingOptions.GetBlendColor();
726 return Color::TRANSPARENT; // GL default
729 Renderer::~Renderer()
731 if( EventThreadServices::IsCoreRunning() )
733 EventThreadServices& eventThreadServices = GetEventThreadServices();
734 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
735 RemoveRendererMessage( updateManager, GetRendererSceneObject() );
737 eventThreadServices.UnregisterObject( this );
741 bool Renderer::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const
743 bool valueSet = true;
747 case Dali::Renderer::Property::DEPTH_INDEX:
749 value = GetDepthIndex();
752 case Dali::Renderer::Property::FACE_CULLING_MODE:
754 value = mFaceCullingMode;
757 case Dali::Renderer::Property::BLEND_MODE:
762 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
764 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationRgb() );
767 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
769 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationAlpha() );
772 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
774 BlendFactor::Type srcFactorRgb;
775 BlendFactor::Type destFactorRgb;
776 BlendFactor::Type srcFactorAlpha;
777 BlendFactor::Type destFactorAlpha;
778 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
779 value = static_cast<int32_t>( srcFactorRgb );
782 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
784 BlendFactor::Type srcFactorRgb;
785 BlendFactor::Type destFactorRgb;
786 BlendFactor::Type srcFactorAlpha;
787 BlendFactor::Type destFactorAlpha;
788 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
789 value = static_cast<int32_t>( destFactorRgb );
792 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
794 BlendFactor::Type srcFactorRgb;
795 BlendFactor::Type destFactorRgb;
796 BlendFactor::Type srcFactorAlpha;
797 BlendFactor::Type destFactorAlpha;
798 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
799 value = static_cast<int32_t>( srcFactorAlpha );
802 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
804 BlendFactor::Type srcFactorRgb;
805 BlendFactor::Type destFactorRgb;
806 BlendFactor::Type srcFactorAlpha;
807 BlendFactor::Type destFactorAlpha;
808 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
809 value = static_cast<int32_t>( destFactorAlpha );
812 case Dali::Renderer::Property::BLEND_COLOR:
814 value = GetBlendColor();
817 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
819 value = IsPreMultipliedAlphaEnabled();
822 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
824 value = static_cast<int32_t>( mIndexedDrawFirstElement );
827 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
829 value = static_cast<int32_t>( mIndexedDrawElementCount );
832 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
834 value = mDepthWriteMode;
837 case Dali::Renderer::Property::DEPTH_FUNCTION:
839 value = mDepthFunction;
842 case Dali::Renderer::Property::DEPTH_TEST_MODE:
844 value = mDepthTestMode;
847 case Dali::Renderer::Property::STENCIL_FUNCTION:
849 value = mStencilParameters.stencilFunction;
852 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
854 value = mStencilParameters.stencilFunctionMask;
857 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
859 value = mStencilParameters.stencilFunctionReference;
862 case Dali::Renderer::Property::STENCIL_MASK:
864 value = mStencilParameters.stencilMask;
867 case Dali::Renderer::Property::RENDER_MODE:
869 value = mStencilParameters.renderMode;
872 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
874 value = mStencilParameters.stencilOperationOnFail;
877 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
879 value = mStencilParameters.stencilOperationOnZFail;
882 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
884 value = mStencilParameters.stencilOperationOnZPass;
887 case Dali::DevelRenderer::Property::OPACITY:
894 // Must be a scene-graph only property
903 bool Renderer::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const
905 bool valueSet = true;
906 const SceneGraph::Renderer& sceneObject = GetRendererSceneObject();
910 case Dali::Renderer::Property::DEPTH_INDEX:
912 value = sceneObject.GetDepthIndex();
915 case Dali::Renderer::Property::FACE_CULLING_MODE:
917 value = sceneObject.GetFaceCullingMode();
920 case Dali::Renderer::Property::BLEND_MODE:
922 value = sceneObject.GetBlendMode();
925 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
927 uint32_t bitMask = sceneObject.GetBlendingOptions();
928 BlendingOptions blendingOptions;
929 blendingOptions.SetBitmask( bitMask );
930 value = static_cast<int32_t>( blendingOptions.GetBlendEquationRgb() );
933 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
935 uint32_t bitMask = sceneObject.GetBlendingOptions();
936 BlendingOptions blendingOptions;
937 blendingOptions.SetBitmask( bitMask );
938 value = static_cast<int32_t>( blendingOptions.GetBlendEquationAlpha() );
941 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
943 uint32_t bitMask = sceneObject.GetBlendingOptions();
944 BlendingOptions blendingOptions;
945 blendingOptions.SetBitmask( bitMask );
946 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorRgb() );
949 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
951 uint32_t bitMask = sceneObject.GetBlendingOptions();
952 BlendingOptions blendingOptions;
953 blendingOptions.SetBitmask( bitMask );
954 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorRgb() );
957 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
959 uint32_t bitMask = sceneObject.GetBlendingOptions();
960 BlendingOptions blendingOptions;
961 blendingOptions.SetBitmask( bitMask );
962 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorAlpha() );
965 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
967 uint32_t bitMask = sceneObject.GetBlendingOptions();
968 BlendingOptions blendingOptions;
969 blendingOptions.SetBitmask( bitMask );
970 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorAlpha() );
973 case Dali::Renderer::Property::BLEND_COLOR:
975 value = sceneObject.GetBlendColor();
978 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
980 value = sceneObject.IsPreMultipliedAlphaEnabled();
983 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
985 value = static_cast<int32_t>( sceneObject.GetIndexedDrawFirstElement() );
988 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
990 value = static_cast<int32_t>( sceneObject.GetIndexedDrawElementsCount() );
993 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
995 value = sceneObject.GetDepthWriteMode();
998 case Dali::Renderer::Property::DEPTH_FUNCTION:
1000 value = sceneObject.GetDepthFunction();
1003 case Dali::Renderer::Property::DEPTH_TEST_MODE:
1005 value = sceneObject.GetDepthTestMode();
1008 case Dali::Renderer::Property::STENCIL_FUNCTION:
1010 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1011 value = stencilParameters.stencilFunction;
1014 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
1016 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1017 value = stencilParameters.stencilFunctionMask;
1020 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
1022 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1023 value = stencilParameters.stencilFunctionReference;
1026 case Dali::Renderer::Property::STENCIL_MASK:
1028 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1029 value = stencilParameters.stencilMask;
1032 case Dali::Renderer::Property::RENDER_MODE:
1034 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1035 value = stencilParameters.renderMode;
1038 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
1040 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1041 value = stencilParameters.stencilOperationOnFail;
1044 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
1046 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1047 value = stencilParameters.stencilOperationOnZFail;
1050 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
1052 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1053 value = stencilParameters.stencilOperationOnZPass;
1056 case Dali::DevelRenderer::Property::OPACITY:
1058 value = sceneObject.GetOpacity( GetEventThreadServices().GetEventBufferIndex() );
1063 // Must be an event-side only property
1072 } // namespace Internal