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/public-api/object/type-registry.h>
24 #include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
25 #include <dali/internal/event/common/property-input-impl.h>
26 #include <dali/internal/render/renderers/render-geometry.h>
27 #include <dali/internal/update/manager/update-manager.h>
28 #include <dali/internal/update/rendering/scene-graph-renderer.h>
39 * Properties: |name |type |writable|animatable|constraint-input|enum for index-checking|
41 DALI_PROPERTY_TABLE_BEGIN
42 DALI_PROPERTY( "depthIndex", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_INDEX )
43 DALI_PROPERTY( "faceCullingMode", INTEGER, true, false, false, Dali::Renderer::Property::FACE_CULLING_MODE )
44 DALI_PROPERTY( "blendMode", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_MODE )
45 DALI_PROPERTY( "blendEquationRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_RGB )
46 DALI_PROPERTY( "blendEquationAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_EQUATION_ALPHA )
47 DALI_PROPERTY( "blendFactorSrcRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB )
48 DALI_PROPERTY( "blendFactorDestRgb", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB )
49 DALI_PROPERTY( "blendFactorSrcAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA )
50 DALI_PROPERTY( "blendFactorDestAlpha", INTEGER, true, false, false, Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA )
51 DALI_PROPERTY( "blendColor", VECTOR4, true, false, false, Dali::Renderer::Property::BLEND_COLOR )
52 DALI_PROPERTY( "blendPreMultipliedAlpha", BOOLEAN, true, false, false, Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA )
53 DALI_PROPERTY( "indexRangeFirst", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_FIRST )
54 DALI_PROPERTY( "indexRangeCount", INTEGER, true, false, false, Dali::Renderer::Property::INDEX_RANGE_COUNT )
55 DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
56 DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
57 DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
58 DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
59 DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
60 DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
61 DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
62 DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
63 DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
64 DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
65 DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
66 DALI_PROPERTY( "opacity", FLOAT, true, true, true, Dali::DevelRenderer::Property::OPACITY )
67 DALI_PROPERTY( "renderingBehavior", INTEGER, true, false, false, Dali::DevelRenderer::Property::RENDERING_BEHAVIOR )
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 )
162 DALI_ENUM_TO_STRING_TABLE_BEGIN( RENDERING_BEHAVIOR )
163 DALI_ENUM_TO_STRING_WITH_SCOPE( DevelRenderer::Rendering, IF_REQUIRED )
164 DALI_ENUM_TO_STRING_WITH_SCOPE( DevelRenderer::Rendering, CONTINUOUSLY )
165 DALI_ENUM_TO_STRING_TABLE_END( RENDERING_BEHAVIOR )
169 return Dali::BaseHandle();
172 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create, RendererDefaultProperties );
174 } // unnamed namespace
176 RendererPtr Renderer::New()
178 // create scene object first so it's guaranteed to exist for the event side
179 auto sceneObject = SceneGraph::Renderer::New();
180 OwnerPointer< SceneGraph::Renderer > transferOwnership( sceneObject );
181 // pass the pointer to base for message passing
182 RendererPtr rendererPtr( new Renderer( sceneObject ) );
183 // transfer scene object ownership to update manager
184 EventThreadServices& eventThreadServices = rendererPtr->GetEventThreadServices();
185 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
186 AddRendererMessage( updateManager, transferOwnership );
188 eventThreadServices.RegisterObject( rendererPtr.Get() );
192 void Renderer::SetGeometry( Geometry& geometry )
194 mGeometry = &geometry;
196 const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
197 SetGeometryMessage( GetEventThreadServices(), GetRendererSceneObject(), *geometrySceneObject );
200 GeometryPtr Renderer::GetGeometry() const
205 void Renderer::SetTextures( TextureSet& textureSet )
207 mTextureSet = &textureSet;
208 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
209 SetTexturesMessage( GetEventThreadServices(), GetRendererSceneObject(), *textureSetSceneObject );
212 TextureSetPtr Renderer::GetTextures() const
217 void Renderer::SetShader( Shader& shader )
220 const SceneGraph::Shader& sceneGraphShader = shader.GetShaderSceneObject();
221 SceneGraph::SetShaderMessage( GetEventThreadServices(), GetRendererSceneObject(), sceneGraphShader );
224 ShaderPtr Renderer::GetShader() const
229 void Renderer::SetDepthIndex( int32_t depthIndex )
231 if ( mDepthIndex != depthIndex )
233 mDepthIndex = depthIndex;
234 SetDepthIndexMessage( GetEventThreadServices(), GetRendererSceneObject(), depthIndex );
238 int32_t Renderer::GetDepthIndex() const
243 void Renderer::SetBlendMode( BlendMode::Type mode )
245 if( mBlendMode != mode )
249 SetBlendModeMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendMode );
253 BlendMode::Type Renderer::GetBlendMode() const
258 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
260 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
261 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
264 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
265 BlendFactor::Type destFactorRgb,
266 BlendFactor::Type srcFactorAlpha,
267 BlendFactor::Type destFactorAlpha )
269 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
270 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
273 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
274 BlendFactor::Type& destFactorRgb,
275 BlendFactor::Type& srcFactorAlpha,
276 BlendFactor::Type& destFactorAlpha ) const
278 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
279 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
280 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
281 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
284 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
286 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
287 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
290 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
291 BlendEquation::Type equationAlpha )
293 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
294 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
297 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
298 BlendEquation::Type& equationAlpha ) const
300 // These are not animatable, the cached values are up-to-date.
301 equationRgb = mBlendingOptions.GetBlendEquationRgb();
302 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
305 void Renderer::SetIndexedDrawFirstElement( uint32_t firstElement )
307 if( firstElement != mIndexedDrawFirstElement )
309 mIndexedDrawFirstElement = firstElement;
310 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), GetRendererSceneObject(), mIndexedDrawFirstElement );
314 void Renderer::SetIndexedDrawElementsCount( uint32_t elementsCount )
316 if( elementsCount != mIndexedDrawElementCount )
318 mIndexedDrawElementCount = elementsCount;
319 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), GetRendererSceneObject(), mIndexedDrawElementCount );
324 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
326 if( mPremultipledAlphaEnabled != preMultipled )
330 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
334 SetBlendFunc( BlendFactor::SRC_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
336 mPremultipledAlphaEnabled = preMultipled;
337 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), GetRendererSceneObject(), mPremultipledAlphaEnabled );
341 bool Renderer::IsPreMultipliedAlphaEnabled() const
343 return mPremultipledAlphaEnabled;
346 const SceneGraph::Renderer& Renderer::GetRendererSceneObject() const
348 return static_cast<const SceneGraph::Renderer&>( GetSceneObject() );
351 void Renderer::SetDefaultProperty( Property::Index index,
352 const Property::Value& propertyValue )
356 case Dali::Renderer::Property::DEPTH_INDEX:
358 SetDepthIndex( propertyValue.Get<int32_t>() );
361 case Dali::Renderer::Property::FACE_CULLING_MODE:
363 FaceCullingMode::Type convertedValue = mFaceCullingMode;
364 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
366 mFaceCullingMode = convertedValue;
367 SetFaceCullingModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
371 case Dali::Renderer::Property::BLEND_MODE:
373 BlendMode::Type convertedValue = mBlendMode;
374 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
376 SetBlendMode( convertedValue );
380 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
382 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
384 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
386 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
387 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
388 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
392 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
394 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
396 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
398 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
399 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
400 SetBlendingOptionsMessage( GetEventThreadServices(), GetRendererSceneObject(), mBlendingOptions.GetBitmask() );
404 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
406 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
407 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
409 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
411 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
415 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
417 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
418 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
420 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
422 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
426 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
428 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
429 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
431 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
433 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
437 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
439 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
440 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
442 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
444 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
448 case Dali::Renderer::Property::BLEND_COLOR:
451 if( propertyValue.Get( blendColor ) )
453 SetBlendColor( blendColor );
457 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
460 if( propertyValue.Get( preMultipled ) )
462 EnablePreMultipliedAlpha( preMultipled );
466 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
468 int32_t firstElement;
469 if( propertyValue.Get( firstElement ) )
471 SetIndexedDrawFirstElement( firstElement );
475 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
477 int32_t elementsCount;
478 if( propertyValue.Get( elementsCount ) )
480 SetIndexedDrawElementsCount( elementsCount );
484 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
486 DepthWriteMode::Type convertedValue = mDepthWriteMode;
487 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
489 mDepthWriteMode = convertedValue;
490 SetDepthWriteModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
494 case Dali::Renderer::Property::DEPTH_FUNCTION:
496 DepthFunction::Type convertedValue = mDepthFunction;
497 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
499 mDepthFunction = convertedValue;
500 SetDepthFunctionMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
504 case Dali::Renderer::Property::DEPTH_TEST_MODE:
506 DepthTestMode::Type convertedValue = mDepthTestMode;
507 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
509 mDepthTestMode = convertedValue;
510 SetDepthTestModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
514 case Dali::Renderer::Property::RENDER_MODE:
516 RenderMode::Type convertedValue = mStencilParameters.renderMode;
517 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
519 mStencilParameters.renderMode = convertedValue;
520 SetRenderModeMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
524 case Dali::Renderer::Property::STENCIL_FUNCTION:
526 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
527 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
529 mStencilParameters.stencilFunction = convertedValue;
530 SetStencilFunctionMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
534 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
536 int32_t stencilFunctionMask;
537 if( propertyValue.Get( stencilFunctionMask ) )
539 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
541 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
542 SetStencilFunctionMaskMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilFunctionMask );
547 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
549 int32_t stencilFunctionReference;
550 if( propertyValue.Get( stencilFunctionReference ) )
552 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
554 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
555 SetStencilFunctionReferenceMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilFunctionReference );
560 case Dali::Renderer::Property::STENCIL_MASK:
563 if( propertyValue.Get( stencilMask ) )
565 if( stencilMask != mStencilParameters.stencilMask )
567 mStencilParameters.stencilMask = stencilMask;
568 SetStencilMaskMessage( GetEventThreadServices(), GetRendererSceneObject(), stencilMask );
573 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
575 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
576 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
578 mStencilParameters.stencilOperationOnFail = convertedValue;
579 SetStencilOperationOnFailMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
583 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
585 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
586 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
588 mStencilParameters.stencilOperationOnZFail = convertedValue;
589 SetStencilOperationOnZFailMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
593 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
595 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
596 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
598 mStencilParameters.stencilOperationOnZPass = convertedValue;
599 SetStencilOperationOnZPassMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
603 case Dali::DevelRenderer::Property::OPACITY:
606 if( propertyValue.Get( opacity ) )
608 if( !Equals( mOpacity, opacity ) )
611 BakeOpacityMessage( GetEventThreadServices(), GetRendererSceneObject(), mOpacity );
616 case DevelRenderer::Property::RENDERING_BEHAVIOR:
618 DevelRenderer::Rendering::Type convertedValue = mRenderingBehavior;
619 if( Scripting::GetEnumerationProperty< DevelRenderer::Rendering::Type >( propertyValue, RENDERING_BEHAVIOR_TABLE, RENDERING_BEHAVIOR_TABLE_COUNT, convertedValue ) )
621 mRenderingBehavior = convertedValue;
622 SetRenderingBehaviorMessage( GetEventThreadServices(), GetRendererSceneObject(), convertedValue );
629 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
631 Property::Value value;
633 if( ! GetCachedPropertyValue( index, value ) )
635 // If property value is not stored in the event-side, then it must be a scene-graph only property
636 GetCurrentPropertyValue( index, value );
642 Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const
644 Property::Value value;
646 if( ! GetCurrentPropertyValue( index, value ) )
648 // If unable to retrieve scene-graph property value, then it must be an event-side only property
649 GetCachedPropertyValue( index, value );
655 void Renderer::OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType )
657 switch( animationType )
660 case Animation::BETWEEN:
664 case Dali::DevelRenderer::Property::OPACITY:
666 value.Get( mOpacity );
677 case Dali::DevelRenderer::Property::OPACITY:
679 AdjustValue< float >( mOpacity, value );
688 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
690 const SceneGraph::PropertyBase* property = NULL;
692 if( index == DevelRenderer::Property::OPACITY )
694 property = &GetRendererSceneObject().mOpacity;
698 // not our property, ask base
699 property = Object::GetSceneObjectAnimatableProperty( index );
705 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
707 // reuse animatable property getter, Object::GetSceneObjectInputProperty does the same so no need to call that0
708 return GetSceneObjectAnimatableProperty( index );
711 Renderer::Renderer( const SceneGraph::Renderer* sceneObject )
712 : Object( sceneObject ),
714 mIndexedDrawFirstElement( 0 ),
715 mIndexedDrawElementCount( 0 ),
716 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
719 mDepthFunction( DepthFunction::LESS ),
720 mFaceCullingMode( FaceCullingMode::NONE ),
721 mBlendMode( BlendMode::AUTO ),
722 mDepthWriteMode( DepthWriteMode::AUTO ),
723 mDepthTestMode( DepthTestMode::AUTO ),
724 mRenderingBehavior( DevelRenderer::Rendering::IF_REQUIRED ),
725 mPremultipledAlphaEnabled( false )
729 void Renderer::SetBlendColor( const Vector4& blendColor )
731 mBlendingOptions.SetBlendColor( blendColor );
732 SetBlendColorMessage( GetEventThreadServices(), GetRendererSceneObject(), GetBlendColor() );
735 const Vector4& Renderer::GetBlendColor() const
737 const Vector4* blendColor = mBlendingOptions.GetBlendColor();
742 return Color::TRANSPARENT; // GL default
745 Renderer::~Renderer()
747 if( EventThreadServices::IsCoreRunning() )
749 EventThreadServices& eventThreadServices = GetEventThreadServices();
750 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
751 RemoveRendererMessage( updateManager, GetRendererSceneObject() );
753 eventThreadServices.UnregisterObject( this );
757 bool Renderer::GetCachedPropertyValue( Property::Index index, Property::Value& value ) const
759 bool valueSet = true;
763 case Dali::Renderer::Property::DEPTH_INDEX:
765 value = GetDepthIndex();
768 case Dali::Renderer::Property::FACE_CULLING_MODE:
770 value = mFaceCullingMode;
773 case Dali::Renderer::Property::BLEND_MODE:
778 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
780 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationRgb() );
783 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
785 value = static_cast<int32_t>( mBlendingOptions.GetBlendEquationAlpha() );
788 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
790 BlendFactor::Type srcFactorRgb;
791 BlendFactor::Type destFactorRgb;
792 BlendFactor::Type srcFactorAlpha;
793 BlendFactor::Type destFactorAlpha;
794 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
795 value = static_cast<int32_t>( srcFactorRgb );
798 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
800 BlendFactor::Type srcFactorRgb;
801 BlendFactor::Type destFactorRgb;
802 BlendFactor::Type srcFactorAlpha;
803 BlendFactor::Type destFactorAlpha;
804 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
805 value = static_cast<int32_t>( destFactorRgb );
808 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
810 BlendFactor::Type srcFactorRgb;
811 BlendFactor::Type destFactorRgb;
812 BlendFactor::Type srcFactorAlpha;
813 BlendFactor::Type destFactorAlpha;
814 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
815 value = static_cast<int32_t>( srcFactorAlpha );
818 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
820 BlendFactor::Type srcFactorRgb;
821 BlendFactor::Type destFactorRgb;
822 BlendFactor::Type srcFactorAlpha;
823 BlendFactor::Type destFactorAlpha;
824 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
825 value = static_cast<int32_t>( destFactorAlpha );
828 case Dali::Renderer::Property::BLEND_COLOR:
830 value = GetBlendColor();
833 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
835 value = IsPreMultipliedAlphaEnabled();
838 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
840 value = static_cast<int32_t>( mIndexedDrawFirstElement );
843 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
845 value = static_cast<int32_t>( mIndexedDrawElementCount );
848 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
850 value = mDepthWriteMode;
853 case Dali::Renderer::Property::DEPTH_FUNCTION:
855 value = mDepthFunction;
858 case Dali::Renderer::Property::DEPTH_TEST_MODE:
860 value = mDepthTestMode;
863 case Dali::Renderer::Property::STENCIL_FUNCTION:
865 value = mStencilParameters.stencilFunction;
868 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
870 value = mStencilParameters.stencilFunctionMask;
873 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
875 value = mStencilParameters.stencilFunctionReference;
878 case Dali::Renderer::Property::STENCIL_MASK:
880 value = mStencilParameters.stencilMask;
883 case Dali::Renderer::Property::RENDER_MODE:
885 value = mStencilParameters.renderMode;
888 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
890 value = mStencilParameters.stencilOperationOnFail;
893 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
895 value = mStencilParameters.stencilOperationOnZFail;
898 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
900 value = mStencilParameters.stencilOperationOnZPass;
903 case Dali::DevelRenderer::Property::OPACITY:
908 case Dali::DevelRenderer::Property::RENDERING_BEHAVIOR:
910 value = mRenderingBehavior;
915 // Must be a scene-graph only property
924 bool Renderer::GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const
926 bool valueSet = true;
927 const SceneGraph::Renderer& sceneObject = GetRendererSceneObject();
931 case Dali::Renderer::Property::DEPTH_INDEX:
933 value = sceneObject.GetDepthIndex();
936 case Dali::Renderer::Property::FACE_CULLING_MODE:
938 value = sceneObject.GetFaceCullingMode();
941 case Dali::Renderer::Property::BLEND_MODE:
943 value = sceneObject.GetBlendMode();
946 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
948 uint32_t bitMask = sceneObject.GetBlendingOptions();
949 BlendingOptions blendingOptions;
950 blendingOptions.SetBitmask( bitMask );
951 value = static_cast<int32_t>( blendingOptions.GetBlendEquationRgb() );
954 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
956 uint32_t bitMask = sceneObject.GetBlendingOptions();
957 BlendingOptions blendingOptions;
958 blendingOptions.SetBitmask( bitMask );
959 value = static_cast<int32_t>( blendingOptions.GetBlendEquationAlpha() );
962 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
964 uint32_t bitMask = sceneObject.GetBlendingOptions();
965 BlendingOptions blendingOptions;
966 blendingOptions.SetBitmask( bitMask );
967 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorRgb() );
970 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
972 uint32_t bitMask = sceneObject.GetBlendingOptions();
973 BlendingOptions blendingOptions;
974 blendingOptions.SetBitmask( bitMask );
975 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorRgb() );
978 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
980 uint32_t bitMask = sceneObject.GetBlendingOptions();
981 BlendingOptions blendingOptions;
982 blendingOptions.SetBitmask( bitMask );
983 value = static_cast<int32_t>( blendingOptions.GetBlendSrcFactorAlpha() );
986 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
988 uint32_t bitMask = sceneObject.GetBlendingOptions();
989 BlendingOptions blendingOptions;
990 blendingOptions.SetBitmask( bitMask );
991 value = static_cast<int32_t>( blendingOptions.GetBlendDestFactorAlpha() );
994 case Dali::Renderer::Property::BLEND_COLOR:
996 value = sceneObject.GetBlendColor();
999 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
1001 value = sceneObject.IsPreMultipliedAlphaEnabled();
1004 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
1006 value = static_cast<int32_t>( sceneObject.GetIndexedDrawFirstElement() );
1009 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
1011 value = static_cast<int32_t>( sceneObject.GetIndexedDrawElementsCount() );
1014 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
1016 value = sceneObject.GetDepthWriteMode();
1019 case Dali::Renderer::Property::DEPTH_FUNCTION:
1021 value = sceneObject.GetDepthFunction();
1024 case Dali::Renderer::Property::DEPTH_TEST_MODE:
1026 value = sceneObject.GetDepthTestMode();
1029 case Dali::Renderer::Property::STENCIL_FUNCTION:
1031 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1032 value = stencilParameters.stencilFunction;
1035 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
1037 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1038 value = stencilParameters.stencilFunctionMask;
1041 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
1043 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1044 value = stencilParameters.stencilFunctionReference;
1047 case Dali::Renderer::Property::STENCIL_MASK:
1049 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1050 value = stencilParameters.stencilMask;
1053 case Dali::Renderer::Property::RENDER_MODE:
1055 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1056 value = stencilParameters.renderMode;
1059 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
1061 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1062 value = stencilParameters.stencilOperationOnFail;
1065 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
1067 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1068 value = stencilParameters.stencilOperationOnZFail;
1071 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
1073 Render::Renderer::StencilParameters stencilParameters = sceneObject.GetStencilParameters();
1074 value = stencilParameters.stencilOperationOnZPass;
1077 case Dali::DevelRenderer::Property::OPACITY:
1079 value = sceneObject.GetOpacity( GetEventThreadServices().GetEventBufferIndex() );
1082 case Dali::DevelRenderer::Property::RENDERING_BEHAVIOR:
1084 value = sceneObject.GetRenderingBehavior();
1089 // Must be an event-side only property
1098 } // namespace Internal