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( "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( "stencilMode", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MODE )
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( "writeToColorBuffer", BOOLEAN, true, false, false, Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER )
68 DALI_PROPERTY( "batchingEnabled", BOOLEAN, true, false, false, Dali::Renderer::Property::BATCHING_ENABLED )
69 DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
71 // Property string to enumeration tables:
73 DALI_ENUM_TO_STRING_TABLE_BEGIN( FACE_CULLING_MODE )
74 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, NONE )
75 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT )
76 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, BACK )
77 DALI_ENUM_TO_STRING_WITH_SCOPE( FaceCullingMode, FRONT_AND_BACK )
78 DALI_ENUM_TO_STRING_TABLE_END( FACE_CULLING_MODE )
80 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_MODE )
81 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, OFF )
82 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, AUTO )
83 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendMode, ON )
84 DALI_ENUM_TO_STRING_TABLE_END( BLEND_MODE )
86 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_EQUATION )
87 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, ADD )
88 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, SUBTRACT )
89 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendEquation, REVERSE_SUBTRACT )
90 DALI_ENUM_TO_STRING_TABLE_END( BLEND_EQUATION )
92 DALI_ENUM_TO_STRING_TABLE_BEGIN( BLEND_FACTOR )
93 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ZERO )
94 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE )
95 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_COLOR )
96 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_COLOR )
97 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA )
98 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_SRC_ALPHA )
99 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_ALPHA )
100 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_ALPHA )
101 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, DST_COLOR )
102 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_DST_COLOR )
103 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, SRC_ALPHA_SATURATE )
104 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_COLOR )
105 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_COLOR )
106 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, CONSTANT_ALPHA )
107 DALI_ENUM_TO_STRING_WITH_SCOPE( BlendFactor, ONE_MINUS_CONSTANT_ALPHA )
108 DALI_ENUM_TO_STRING_TABLE_END( BLEND_FACTOR )
110 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_WRITE_MODE )
111 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, OFF )
112 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, AUTO )
113 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthWriteMode, ON )
114 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_WRITE_MODE )
116 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_TEST_MODE )
117 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, OFF )
118 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, AUTO )
119 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthTestMode, ON )
120 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_TEST_MODE )
122 DALI_ENUM_TO_STRING_TABLE_BEGIN( DEPTH_FUNCTION )
123 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NEVER )
124 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, ALWAYS )
125 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS )
126 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER )
127 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, EQUAL )
128 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, NOT_EQUAL )
129 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, LESS_EQUAL )
130 DALI_ENUM_TO_STRING_WITH_SCOPE( DepthFunction, GREATER_EQUAL )
131 DALI_ENUM_TO_STRING_TABLE_END( DEPTH_FUNCTION )
133 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_FUNCTION )
134 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NEVER )
135 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS )
136 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, EQUAL )
137 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, LESS_EQUAL )
138 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER )
139 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, NOT_EQUAL )
140 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, GREATER_EQUAL )
141 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, ALWAYS )
142 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_FUNCTION )
144 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_MODE )
145 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, OFF )
146 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, AUTO )
147 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, ON )
148 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_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 bool Renderer::IsBatchingEnabled() const
353 return mBatchingEnabled;
356 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
361 unsigned int Renderer::GetDefaultPropertyCount() const
363 return RENDERER_IMPL.GetDefaultPropertyCount();
366 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
368 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
371 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
373 return RENDERER_IMPL.GetDefaultPropertyName( index );
376 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
378 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
381 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
383 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
386 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
388 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
391 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
393 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
396 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
398 return RENDERER_IMPL.GetDefaultPropertyType( index );
401 void Renderer::SetDefaultProperty( Property::Index index,
402 const Property::Value& propertyValue )
406 case Dali::Renderer::Property::DEPTH_INDEX:
408 SetDepthIndex( propertyValue.Get<int>() );
411 case Dali::Renderer::Property::FACE_CULLING_MODE:
413 FaceCullingMode::Type convertedValue = mFaceCullingMode;
414 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
416 mFaceCullingMode = convertedValue;
417 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
421 case Dali::Renderer::Property::BLEND_MODE:
423 BlendMode::Type convertedValue = mBlendMode;
424 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
426 SetBlendMode( convertedValue );
430 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
432 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
434 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
436 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
437 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
438 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
442 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
444 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
446 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
448 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
449 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
450 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
454 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
456 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
457 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
459 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
461 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
465 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
467 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
468 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
470 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
472 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
476 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
478 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
479 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
481 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
483 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
487 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
489 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
490 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
492 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
494 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
498 case Dali::Renderer::Property::BLEND_COLOR:
501 if( propertyValue.Get( blendColor ) )
503 SetBlendColor( blendColor );
507 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
510 if( propertyValue.Get( preMultipled ) )
512 EnablePreMultipliedAlpha( preMultipled );
516 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
519 if( propertyValue.Get( firstElement ) )
521 SetIndexedDrawFirstElement( firstElement );
525 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
528 if( propertyValue.Get( elementsCount ) )
530 SetIndexedDrawElementsCount( elementsCount );
534 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
536 DepthWriteMode::Type convertedValue = mDepthWriteMode;
537 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
539 mDepthWriteMode = convertedValue;
540 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
544 case Dali::Renderer::Property::DEPTH_FUNCTION:
546 DepthFunction::Type convertedValue = mDepthFunction;
547 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
549 mDepthFunction = convertedValue;
550 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
554 case Dali::Renderer::Property::DEPTH_TEST_MODE:
556 DepthTestMode::Type convertedValue = mDepthTestMode;
557 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
559 mDepthTestMode = convertedValue;
560 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
564 case Dali::Renderer::Property::STENCIL_MODE:
566 StencilMode::Type convertedValue = mStencilParameters.stencilMode;
567 if( Scripting::GetEnumerationProperty< StencilMode::Type >( propertyValue, STENCIL_MODE_TABLE, STENCIL_MODE_TABLE_COUNT, convertedValue ) )
569 mStencilParameters.stencilMode = convertedValue;
570 SetStencilModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
574 case Dali::Renderer::Property::STENCIL_FUNCTION:
576 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
577 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
579 mStencilParameters.stencilFunction = convertedValue;
580 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
584 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
586 int stencilFunctionMask;
587 if( propertyValue.Get( stencilFunctionMask ) )
589 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
591 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
592 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
597 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
599 int stencilFunctionReference;
600 if( propertyValue.Get( stencilFunctionReference ) )
602 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
604 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
605 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
610 case Dali::Renderer::Property::STENCIL_MASK:
613 if( propertyValue.Get( stencilMask ) )
615 if( stencilMask != mStencilParameters.stencilMask )
617 mStencilParameters.stencilMask = stencilMask;
618 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
623 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
625 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
626 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
628 mStencilParameters.stencilOperationOnFail = convertedValue;
629 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
633 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
635 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
636 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
638 mStencilParameters.stencilOperationOnZFail = convertedValue;
639 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
643 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
645 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
646 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
648 mStencilParameters.stencilOperationOnZPass = convertedValue;
649 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
653 case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
655 bool writeToColorBuffer;
656 if( propertyValue.Get( writeToColorBuffer ) )
658 if( mWriteToColorBuffer != writeToColorBuffer )
660 mWriteToColorBuffer = writeToColorBuffer;
661 SetWriteToColorBufferMessage( GetEventThreadServices(), *mSceneObject, writeToColorBuffer );
666 case Dali::Renderer::Property::BATCHING_ENABLED:
669 if( propertyValue.Get( enabled ) )
671 if( mBatchingEnabled != enabled )
673 mBatchingEnabled = enabled;
674 SetBatchingEnabledMessage( GetEventThreadServices(), *mSceneObject, mBatchingEnabled );
682 void Renderer::SetSceneGraphProperty( Property::Index index,
683 const PropertyMetadata& entry,
684 const Property::Value& value )
686 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
687 OnPropertySet(index, value);
690 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
692 Property::Value value;
695 case Dali::Renderer::Property::DEPTH_INDEX:
697 value = GetDepthIndex();
700 case Dali::Renderer::Property::FACE_CULLING_MODE:
702 value = mFaceCullingMode;
705 case Dali::Renderer::Property::BLEND_MODE:
710 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
712 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
715 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
717 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
720 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
722 BlendFactor::Type srcFactorRgb;
723 BlendFactor::Type destFactorRgb;
724 BlendFactor::Type srcFactorAlpha;
725 BlendFactor::Type destFactorAlpha;
726 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
727 value = static_cast<int>( srcFactorRgb );
730 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
732 BlendFactor::Type srcFactorRgb;
733 BlendFactor::Type destFactorRgb;
734 BlendFactor::Type srcFactorAlpha;
735 BlendFactor::Type destFactorAlpha;
736 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
737 value = static_cast<int>( destFactorRgb );
740 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
742 BlendFactor::Type srcFactorRgb;
743 BlendFactor::Type destFactorRgb;
744 BlendFactor::Type srcFactorAlpha;
745 BlendFactor::Type destFactorAlpha;
746 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
747 value = static_cast<int>( srcFactorAlpha );
750 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
752 BlendFactor::Type srcFactorRgb;
753 BlendFactor::Type destFactorRgb;
754 BlendFactor::Type srcFactorAlpha;
755 BlendFactor::Type destFactorAlpha;
756 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
757 value = static_cast<int>( destFactorAlpha );
760 case Dali::Renderer::Property::BLEND_COLOR:
764 value = *mBlendColor;
768 value = Color::TRANSPARENT;
772 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
774 value = IsPreMultipliedAlphaEnabled();
777 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
779 value = static_cast<int>( mIndexedDrawFirstElement );
782 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
784 value = static_cast<int>( mIndexedDrawElementCount );
787 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
789 value = mDepthWriteMode;
792 case Dali::Renderer::Property::BATCHING_ENABLED:
794 value = mBatchingEnabled;
797 case Dali::Renderer::Property::DEPTH_FUNCTION:
799 value = mDepthFunction;
802 case Dali::Renderer::Property::DEPTH_TEST_MODE:
804 value = mDepthTestMode;
807 case Dali::Renderer::Property::STENCIL_FUNCTION:
809 value = mStencilParameters.stencilFunction;
812 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
814 value = mStencilParameters.stencilFunctionMask;
817 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
819 value = mStencilParameters.stencilFunctionReference;
822 case Dali::Renderer::Property::STENCIL_MASK:
824 value = mStencilParameters.stencilMask;
827 case Dali::Renderer::Property::STENCIL_MODE:
829 value = mStencilParameters.stencilMode;
832 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
834 value = mStencilParameters.stencilOperationOnFail;
837 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
839 value = mStencilParameters.stencilOperationOnZFail;
842 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
844 value = mStencilParameters.stencilOperationOnZPass;
847 case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
849 value = mWriteToColorBuffer;
856 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
861 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
866 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
868 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
869 const SceneGraph::PropertyBase* property = NULL;
873 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
875 &Renderer::FindAnimatableProperty,
876 &Renderer::FindCustomProperty,
883 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
885 const PropertyInputImpl* property = NULL;
889 const SceneGraph::PropertyBase* baseProperty =
890 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
891 &Renderer::FindAnimatableProperty,
892 &Renderer::FindCustomProperty,
894 property = static_cast<const PropertyInputImpl*>( baseProperty );
900 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
902 return Property::INVALID_COMPONENT_INDEX;
905 bool Renderer::OnStage() const
907 return mOnStageCount > 0;
910 void Renderer::Connect()
912 if( mOnStageCount == 0 )
914 mTextureSetConnector.OnStageConnect();
919 void Renderer::Disconnect()
922 if( mOnStageCount == 0 )
924 mTextureSetConnector.OnStageDisconnect();
929 : mSceneObject (NULL ),
933 mIndexedDrawFirstElement( 0 ),
934 mIndexedDrawElementCount( 0 ),
935 mStencilParameters( StencilMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
937 mDepthFunction( DepthFunction::LESS ),
938 mFaceCullingMode( FaceCullingMode::NONE ),
939 mBlendMode( BlendMode::AUTO ),
940 mDepthWriteMode( DepthWriteMode::AUTO ),
941 mDepthTestMode( DepthTestMode::AUTO ),
942 mWriteToColorBuffer( true ),
943 mPremultipledAlphaEnabled( false ),
944 mBatchingEnabled( false )
948 void Renderer::Initialize()
950 EventThreadServices& eventThreadServices = GetEventThreadServices();
951 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
953 mSceneObject = SceneGraph::Renderer::New();
954 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
956 eventThreadServices.RegisterObject( this );
959 Renderer::~Renderer()
961 if( EventThreadServices::IsCoreRunning() )
963 EventThreadServices& eventThreadServices = GetEventThreadServices();
964 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
965 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
967 eventThreadServices.UnregisterObject( this );
971 } // namespace Internal