2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/rendering/renderer-impl.h> // Dali::Internal::Renderer
22 #include <dali/devel-api/scripting/scripting.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
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_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
69 // Property string to enumeration tables:
71 DALI_ENUM_TO_STRING_TABLE_BEGIN( FACE_CULLING_MODE )
72 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, NONE )
73 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT )
74 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, BACK )
75 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT_AND_BACK )
76 DALI_ENUM_TO_STRING_TABLE_END( FACE_CULLING_MODE )
78 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_MODE )
79 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, OFF )
80 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, AUTO )
81 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, ON )
82 DALI_ENUM_TO_STRING_TABLE_END( BLEND_MODE )
84 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_EQUATION )
85 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, ADD )
86 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, SUBTRACT )
87 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, REVERSE_SUBTRACT )
88 DALI_ENUM_TO_STRING_TABLE_END( BLEND_EQUATION )
90 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_FACTOR )
91 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ZERO )
92 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE )
93 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_COLOR )
94 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_COLOR )
95 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA )
96 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_ALPHA )
97 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_ALPHA )
98 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_ALPHA )
99 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_COLOR )
100 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_COLOR )
101 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA_SATURATE )
102 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_COLOR )
103 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_COLOR )
104 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_ALPHA )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_ALPHA )
106 DALI_ENUM_TO_STRING_TABLE_END( BLEND_FACTOR )
108 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_WRITE_MODE )
109 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, OFF )
110 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, AUTO )
111 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, ON )
112 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_WRITE_MODE )
114 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_TEST_MODE )
115 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, OFF )
116 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, AUTO )
117 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, ON )
118 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_TEST_MODE )
120 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_FUNCTION )
121 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NEVER )
122 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, ALWAYS )
123 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS )
124 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER )
125 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, EQUAL )
126 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NOT_EQUAL )
127 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS_EQUAL )
128 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER_EQUAL )
129 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_FUNCTION )
131 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_FUNCTION )
132 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NEVER )
133 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS )
134 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, EQUAL )
135 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS_EQUAL )
136 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER )
137 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NOT_EQUAL )
138 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER_EQUAL )
139 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, ALWAYS )
140 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_FUNCTION )
142 DALI_ENUM_TO_STRING_TABLE_BEGIN( RENDER_MODE )
143 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, NONE )
144 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, AUTO )
145 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR )
146 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, STENCIL )
147 DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR_STENCIL )
148 DALI_ENUM_TO_STRING_TABLE_END( RENDER_MODE )
150 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_OPERATION )
151 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, ZERO )
152 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, KEEP )
153 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, REPLACE )
154 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT )
155 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT )
156 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INVERT )
157 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT_WRAP )
158 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT_WRAP )
159 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_OPERATION )
161 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
165 return Dali::BaseHandle();
168 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
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 mTextureSetConnector.Set( textureSet, OnStage() );
195 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
196 SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
199 TextureSet* Renderer::GetTextures() const
201 return mTextureSetConnector.Get().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::SetBlendColor( const Vector4& color )
296 mBlendColor = new Vector4();
298 if( *mBlendColor != color )
300 *mBlendColor = color;
301 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
305 Vector4 Renderer::GetBlendColor() const
311 return Color::TRANSPARENT; // GL default
314 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
316 if( firstElement != mIndexedDrawFirstElement )
318 mIndexedDrawFirstElement = firstElement;
319 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
323 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
325 if( elementsCount != mIndexedDrawElementCount )
327 mIndexedDrawElementCount = elementsCount;
328 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
333 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
335 if( mPremultipledAlphaEnabled != preMultipled )
339 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
341 mPremultipledAlphaEnabled = preMultipled;
342 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
346 bool Renderer::IsPreMultipliedAlphaEnabled() const
348 return mPremultipledAlphaEnabled;
351 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
356 unsigned int Renderer::GetDefaultPropertyCount() const
358 return RENDERER_IMPL.GetDefaultPropertyCount();
361 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
363 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
366 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
368 return RENDERER_IMPL.GetDefaultPropertyName( index );
371 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
373 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
376 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
378 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
381 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
383 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
386 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
388 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
391 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
393 return RENDERER_IMPL.GetDefaultPropertyType( index );
396 void Renderer::SetDefaultProperty( Property::Index index,
397 const Property::Value& propertyValue )
401 case Dali::Renderer::Property::DEPTH_INDEX:
403 SetDepthIndex( propertyValue.Get<int>() );
406 case Dali::Renderer::Property::FACE_CULLING_MODE:
408 FaceCullingMode::Type convertedValue = mFaceCullingMode;
409 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
411 mFaceCullingMode = convertedValue;
412 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
416 case Dali::Renderer::Property::BLEND_MODE:
418 BlendMode::Type convertedValue = mBlendMode;
419 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
421 SetBlendMode( convertedValue );
425 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
427 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
429 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
431 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
432 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
433 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
437 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
439 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
441 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
443 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
444 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
445 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
449 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
451 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
452 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
454 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
456 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
460 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
462 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
463 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
465 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
467 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
471 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
473 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
474 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
476 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
478 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
482 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
484 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
485 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
487 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
489 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
493 case Dali::Renderer::Property::BLEND_COLOR:
496 if( propertyValue.Get( blendColor ) )
498 SetBlendColor( blendColor );
502 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
505 if( propertyValue.Get( preMultipled ) )
507 EnablePreMultipliedAlpha( preMultipled );
511 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
514 if( propertyValue.Get( firstElement ) )
516 SetIndexedDrawFirstElement( firstElement );
520 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
523 if( propertyValue.Get( elementsCount ) )
525 SetIndexedDrawElementsCount( elementsCount );
529 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
531 DepthWriteMode::Type convertedValue = mDepthWriteMode;
532 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
534 mDepthWriteMode = convertedValue;
535 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
539 case Dali::Renderer::Property::DEPTH_FUNCTION:
541 DepthFunction::Type convertedValue = mDepthFunction;
542 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
544 mDepthFunction = convertedValue;
545 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
549 case Dali::Renderer::Property::DEPTH_TEST_MODE:
551 DepthTestMode::Type convertedValue = mDepthTestMode;
552 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
554 mDepthTestMode = convertedValue;
555 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
559 case Dali::Renderer::Property::RENDER_MODE:
561 RenderMode::Type convertedValue = mStencilParameters.renderMode;
562 if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
564 mStencilParameters.renderMode = convertedValue;
565 SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
569 case Dali::Renderer::Property::STENCIL_FUNCTION:
571 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
572 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
574 mStencilParameters.stencilFunction = convertedValue;
575 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
579 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
581 int stencilFunctionMask;
582 if( propertyValue.Get( stencilFunctionMask ) )
584 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
586 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
587 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
592 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
594 int stencilFunctionReference;
595 if( propertyValue.Get( stencilFunctionReference ) )
597 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
599 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
600 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
605 case Dali::Renderer::Property::STENCIL_MASK:
608 if( propertyValue.Get( stencilMask ) )
610 if( stencilMask != mStencilParameters.stencilMask )
612 mStencilParameters.stencilMask = stencilMask;
613 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
618 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
620 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
621 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
623 mStencilParameters.stencilOperationOnFail = convertedValue;
624 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
628 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
630 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
631 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
633 mStencilParameters.stencilOperationOnZFail = convertedValue;
634 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
638 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
640 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
641 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
643 mStencilParameters.stencilOperationOnZPass = convertedValue;
644 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
651 void Renderer::SetSceneGraphProperty( Property::Index index,
652 const PropertyMetadata& entry,
653 const Property::Value& value )
655 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
656 OnPropertySet(index, value);
659 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
661 Property::Value value;
664 case Dali::Renderer::Property::DEPTH_INDEX:
666 value = GetDepthIndex();
669 case Dali::Renderer::Property::FACE_CULLING_MODE:
671 value = mFaceCullingMode;
674 case Dali::Renderer::Property::BLEND_MODE:
679 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
681 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
684 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
686 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
689 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
691 BlendFactor::Type srcFactorRgb;
692 BlendFactor::Type destFactorRgb;
693 BlendFactor::Type srcFactorAlpha;
694 BlendFactor::Type destFactorAlpha;
695 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
696 value = static_cast<int>( srcFactorRgb );
699 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
701 BlendFactor::Type srcFactorRgb;
702 BlendFactor::Type destFactorRgb;
703 BlendFactor::Type srcFactorAlpha;
704 BlendFactor::Type destFactorAlpha;
705 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
706 value = static_cast<int>( destFactorRgb );
709 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
711 BlendFactor::Type srcFactorRgb;
712 BlendFactor::Type destFactorRgb;
713 BlendFactor::Type srcFactorAlpha;
714 BlendFactor::Type destFactorAlpha;
715 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
716 value = static_cast<int>( srcFactorAlpha );
719 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
721 BlendFactor::Type srcFactorRgb;
722 BlendFactor::Type destFactorRgb;
723 BlendFactor::Type srcFactorAlpha;
724 BlendFactor::Type destFactorAlpha;
725 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
726 value = static_cast<int>( destFactorAlpha );
729 case Dali::Renderer::Property::BLEND_COLOR:
733 value = *mBlendColor;
737 value = Color::TRANSPARENT;
741 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
743 value = IsPreMultipliedAlphaEnabled();
746 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
748 value = static_cast<int>( mIndexedDrawFirstElement );
751 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
753 value = static_cast<int>( mIndexedDrawElementCount );
756 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
758 value = mDepthWriteMode;
761 case Dali::Renderer::Property::DEPTH_FUNCTION:
763 value = mDepthFunction;
766 case Dali::Renderer::Property::DEPTH_TEST_MODE:
768 value = mDepthTestMode;
771 case Dali::Renderer::Property::STENCIL_FUNCTION:
773 value = mStencilParameters.stencilFunction;
776 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
778 value = mStencilParameters.stencilFunctionMask;
781 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
783 value = mStencilParameters.stencilFunctionReference;
786 case Dali::Renderer::Property::STENCIL_MASK:
788 value = mStencilParameters.stencilMask;
791 case Dali::Renderer::Property::RENDER_MODE:
793 value = mStencilParameters.renderMode;
796 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
798 value = mStencilParameters.stencilOperationOnFail;
801 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
803 value = mStencilParameters.stencilOperationOnZFail;
806 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
808 value = mStencilParameters.stencilOperationOnZPass;
815 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
820 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
825 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
827 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
828 const SceneGraph::PropertyBase* property = NULL;
832 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
834 &Renderer::FindAnimatableProperty,
835 &Renderer::FindCustomProperty,
842 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
844 const PropertyInputImpl* property = NULL;
848 const SceneGraph::PropertyBase* baseProperty =
849 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
850 &Renderer::FindAnimatableProperty,
851 &Renderer::FindCustomProperty,
853 property = static_cast<const PropertyInputImpl*>( baseProperty );
859 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
861 return Property::INVALID_COMPONENT_INDEX;
864 bool Renderer::OnStage() const
866 return mOnStageCount > 0;
869 void Renderer::Connect()
871 if( mOnStageCount == 0 )
873 mTextureSetConnector.OnStageConnect();
878 void Renderer::Disconnect()
881 if( mOnStageCount == 0 )
883 mTextureSetConnector.OnStageDisconnect();
888 : mSceneObject (NULL ),
892 mIndexedDrawFirstElement( 0 ),
893 mIndexedDrawElementCount( 0 ),
894 mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
896 mDepthFunction( DepthFunction::LESS ),
897 mFaceCullingMode( FaceCullingMode::NONE ),
898 mBlendMode( BlendMode::AUTO ),
899 mDepthWriteMode( DepthWriteMode::AUTO ),
900 mDepthTestMode( DepthTestMode::AUTO ),
901 mPremultipledAlphaEnabled( false )
905 void Renderer::Initialize()
907 EventThreadServices& eventThreadServices = GetEventThreadServices();
908 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
910 mSceneObject = SceneGraph::Renderer::New();
911 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
913 eventThreadServices.RegisterObject( this );
916 Renderer::~Renderer()
918 if( EventThreadServices::IsCoreRunning() )
920 EventThreadServices& eventThreadServices = GetEventThreadServices();
921 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
922 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
924 eventThreadServices.UnregisterObject( this );
928 } // namespace Internal