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_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
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( STENCIL_MODE )
144 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, OFF )
145 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, AUTO )
146 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, ON )
147 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_MODE )
149 DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_OPERATION )
150 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, ZERO )
151 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, KEEP )
152 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, REPLACE )
153 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT )
154 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT )
155 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INVERT )
156 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, INCREMENT_WRAP )
157 DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, DECREMENT_WRAP )
158 DALI_ENUM_TO_STRING_TABLE_END( STENCIL_OPERATION )
160 const ObjectImplHelper<DEFAULT_PROPERTY_COUNT> RENDERER_IMPL = { DEFAULT_PROPERTY_DETAILS };
164 return Dali::BaseHandle();
167 TypeRegistration mType( typeid( Dali::Renderer ), typeid( Dali::Handle ), Create );
169 } // unnamed namespace
171 RendererPtr Renderer::New()
173 RendererPtr rendererPtr( new Renderer() );
174 rendererPtr->Initialize();
178 void Renderer::SetGeometry( Geometry& geometry )
180 mGeometry = &geometry;
182 const Render::Geometry* geometrySceneObject = geometry.GetRenderObject();
183 SetGeometryMessage( GetEventThreadServices(), *mSceneObject, *geometrySceneObject );
186 Geometry* Renderer::GetGeometry() const
188 return mGeometry.Get();
191 void Renderer::SetTextures( TextureSet& textureSet )
193 mTextureSetConnector.Set( textureSet, OnStage() );
194 const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
195 SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
198 TextureSet* Renderer::GetTextures() const
200 return mTextureSetConnector.Get().Get();
203 void Renderer::SetShader( Shader& shader )
206 SceneGraph::Shader& sceneGraphShader = *shader.GetShaderSceneObject();
207 SceneGraph::SetShaderMessage( GetEventThreadServices(), *mSceneObject, sceneGraphShader );
210 Shader* Renderer::GetShader() const
212 return mShader.Get();
215 void Renderer::SetDepthIndex( int depthIndex )
217 if ( mDepthIndex != depthIndex )
219 mDepthIndex = depthIndex;
220 SetDepthIndexMessage( GetEventThreadServices(), *mSceneObject, depthIndex );
224 int Renderer::GetDepthIndex() const
229 void Renderer::SetBlendMode( BlendMode::Type mode )
231 if( mBlendMode != mode )
235 SetBlendModeMessage( GetEventThreadServices(), *mSceneObject, mBlendMode );
239 BlendMode::Type Renderer::GetBlendMode() const
244 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba )
246 mBlendingOptions.SetBlendFunc( srcFactorRgba, destFactorRgba, srcFactorRgba, destFactorRgba );
247 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
250 void Renderer::SetBlendFunc( BlendFactor::Type srcFactorRgb,
251 BlendFactor::Type destFactorRgb,
252 BlendFactor::Type srcFactorAlpha,
253 BlendFactor::Type destFactorAlpha )
255 mBlendingOptions.SetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
256 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
259 void Renderer::GetBlendFunc( BlendFactor::Type& srcFactorRgb,
260 BlendFactor::Type& destFactorRgb,
261 BlendFactor::Type& srcFactorAlpha,
262 BlendFactor::Type& destFactorAlpha ) const
264 srcFactorRgb = mBlendingOptions.GetBlendSrcFactorRgb();
265 destFactorRgb = mBlendingOptions.GetBlendDestFactorRgb();
266 srcFactorAlpha = mBlendingOptions.GetBlendSrcFactorAlpha();
267 destFactorAlpha = mBlendingOptions.GetBlendDestFactorAlpha();
270 void Renderer::SetBlendEquation( BlendEquation::Type equationRgba )
272 mBlendingOptions.SetBlendEquation( equationRgba, equationRgba );
273 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
276 void Renderer::SetBlendEquation( BlendEquation::Type equationRgb,
277 BlendEquation::Type equationAlpha )
279 mBlendingOptions.SetBlendEquation( equationRgb, equationAlpha );
280 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
283 void Renderer::GetBlendEquation( BlendEquation::Type& equationRgb,
284 BlendEquation::Type& equationAlpha ) const
286 // These are not animatable, the cached values are up-to-date.
287 equationRgb = mBlendingOptions.GetBlendEquationRgb();
288 equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
291 void Renderer::SetBlendColor( const Vector4& color )
295 mBlendColor = new Vector4();
297 if( *mBlendColor != color )
299 *mBlendColor = color;
300 SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
304 Vector4 Renderer::GetBlendColor() const
310 return Color::TRANSPARENT; // GL default
313 void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
315 if( firstElement != mIndexedDrawFirstElement )
317 mIndexedDrawFirstElement = firstElement;
318 SetIndexedDrawFirstElementMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawFirstElement );
322 void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
324 if( elementsCount != mIndexedDrawElementCount )
326 mIndexedDrawElementCount = elementsCount;
327 SetIndexedDrawElementsCountMessage( GetEventThreadServices(), *mSceneObject, mIndexedDrawElementCount );
332 void Renderer::EnablePreMultipliedAlpha( bool preMultipled )
334 if( mPremultipledAlphaEnabled != preMultipled )
338 SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
340 mPremultipledAlphaEnabled = preMultipled;
341 SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
345 bool Renderer::IsPreMultipliedAlphaEnabled() const
347 return mPremultipledAlphaEnabled;
350 SceneGraph::Renderer* Renderer::GetRendererSceneObject()
355 unsigned int Renderer::GetDefaultPropertyCount() const
357 return RENDERER_IMPL.GetDefaultPropertyCount();
360 void Renderer::GetDefaultPropertyIndices( Property::IndexContainer& indices ) const
362 RENDERER_IMPL.GetDefaultPropertyIndices( indices );
365 const char* Renderer::GetDefaultPropertyName(Property::Index index) const
367 return RENDERER_IMPL.GetDefaultPropertyName( index );
370 Property::Index Renderer::GetDefaultPropertyIndex( const std::string& name ) const
372 return RENDERER_IMPL.GetDefaultPropertyIndex( name );
375 bool Renderer::IsDefaultPropertyWritable( Property::Index index ) const
377 return RENDERER_IMPL.IsDefaultPropertyWritable( index );
380 bool Renderer::IsDefaultPropertyAnimatable( Property::Index index ) const
382 return RENDERER_IMPL.IsDefaultPropertyAnimatable( index );
385 bool Renderer::IsDefaultPropertyAConstraintInput( Property::Index index ) const
387 return RENDERER_IMPL.IsDefaultPropertyAConstraintInput( index );
390 Property::Type Renderer::GetDefaultPropertyType( Property::Index index ) const
392 return RENDERER_IMPL.GetDefaultPropertyType( index );
395 void Renderer::SetDefaultProperty( Property::Index index,
396 const Property::Value& propertyValue )
400 case Dali::Renderer::Property::DEPTH_INDEX:
402 SetDepthIndex( propertyValue.Get<int>() );
405 case Dali::Renderer::Property::FACE_CULLING_MODE:
407 FaceCullingMode::Type convertedValue = mFaceCullingMode;
408 if( Scripting::GetEnumerationProperty< FaceCullingMode::Type >( propertyValue, FACE_CULLING_MODE_TABLE, FACE_CULLING_MODE_TABLE_COUNT, convertedValue ) )
410 mFaceCullingMode = convertedValue;
411 SetFaceCullingModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
415 case Dali::Renderer::Property::BLEND_MODE:
417 BlendMode::Type convertedValue = mBlendMode;
418 if( Scripting::GetEnumerationProperty< BlendMode::Type >( propertyValue, BLEND_MODE_TABLE, BLEND_MODE_TABLE_COUNT, convertedValue ) )
420 SetBlendMode( convertedValue );
424 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
426 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationRgb();
428 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
430 BlendEquation::Type alphaEquation = mBlendingOptions.GetBlendEquationAlpha();
431 mBlendingOptions.SetBlendEquation( convertedValue, alphaEquation );
432 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
436 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
438 BlendEquation::Type convertedValue = mBlendingOptions.GetBlendEquationAlpha();
440 if( Scripting::GetEnumerationProperty< BlendEquation::Type >( propertyValue, BLEND_EQUATION_TABLE, BLEND_EQUATION_TABLE_COUNT, convertedValue ) )
442 BlendEquation::Type rgbEquation = mBlendingOptions.GetBlendEquationRgb();
443 mBlendingOptions.SetBlendEquation( rgbEquation, convertedValue );
444 SetBlendingOptionsMessage( GetEventThreadServices(), *mSceneObject, mBlendingOptions.GetBitmask() );
448 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
450 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
451 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
453 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorRgb ) )
455 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
459 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
461 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
462 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
464 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorRgb ) )
466 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
470 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
472 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
473 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
475 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, sourceFactorAlpha ) )
477 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
481 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
483 BlendFactor::Type sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha;
484 GetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
486 if( Scripting::GetEnumerationProperty< BlendFactor::Type >( propertyValue, BLEND_FACTOR_TABLE, BLEND_FACTOR_TABLE_COUNT, destinationFactorAlpha ) )
488 SetBlendFunc( sourceFactorRgb, destinationFactorRgb, sourceFactorAlpha, destinationFactorAlpha );
492 case Dali::Renderer::Property::BLEND_COLOR:
495 if( propertyValue.Get( blendColor ) )
497 SetBlendColor( blendColor );
501 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
504 if( propertyValue.Get( preMultipled ) )
506 EnablePreMultipliedAlpha( preMultipled );
510 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
513 if( propertyValue.Get( firstElement ) )
515 SetIndexedDrawFirstElement( firstElement );
519 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
522 if( propertyValue.Get( elementsCount ) )
524 SetIndexedDrawElementsCount( elementsCount );
528 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
530 DepthWriteMode::Type convertedValue = mDepthWriteMode;
531 if( Scripting::GetEnumerationProperty< DepthWriteMode::Type >( propertyValue, DEPTH_WRITE_MODE_TABLE, DEPTH_WRITE_MODE_TABLE_COUNT, convertedValue ) )
533 mDepthWriteMode = convertedValue;
534 SetDepthWriteModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
538 case Dali::Renderer::Property::DEPTH_FUNCTION:
540 DepthFunction::Type convertedValue = mDepthFunction;
541 if( Scripting::GetEnumerationProperty< DepthFunction::Type >( propertyValue, DEPTH_FUNCTION_TABLE, DEPTH_FUNCTION_TABLE_COUNT, convertedValue ) )
543 mDepthFunction = convertedValue;
544 SetDepthFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
548 case Dali::Renderer::Property::DEPTH_TEST_MODE:
550 DepthTestMode::Type convertedValue = mDepthTestMode;
551 if( Scripting::GetEnumerationProperty< DepthTestMode::Type >( propertyValue, DEPTH_TEST_MODE_TABLE, DEPTH_TEST_MODE_TABLE_COUNT, convertedValue ) )
553 mDepthTestMode = convertedValue;
554 SetDepthTestModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
558 case Dali::Renderer::Property::STENCIL_MODE:
560 StencilMode::Type convertedValue = mStencilParameters.stencilMode;
561 if( Scripting::GetEnumerationProperty< StencilMode::Type >( propertyValue, STENCIL_MODE_TABLE, STENCIL_MODE_TABLE_COUNT, convertedValue ) )
563 mStencilParameters.stencilMode = convertedValue;
564 SetStencilModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
568 case Dali::Renderer::Property::STENCIL_FUNCTION:
570 StencilFunction::Type convertedValue = mStencilParameters.stencilFunction;
571 if( Scripting::GetEnumerationProperty< StencilFunction::Type >( propertyValue, STENCIL_FUNCTION_TABLE, STENCIL_FUNCTION_TABLE_COUNT, convertedValue ) )
573 mStencilParameters.stencilFunction = convertedValue;
574 SetStencilFunctionMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
578 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
580 int stencilFunctionMask;
581 if( propertyValue.Get( stencilFunctionMask ) )
583 if( stencilFunctionMask != mStencilParameters.stencilFunctionMask )
585 mStencilParameters.stencilFunctionMask = stencilFunctionMask;
586 SetStencilFunctionMaskMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionMask );
591 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
593 int stencilFunctionReference;
594 if( propertyValue.Get( stencilFunctionReference ) )
596 if( stencilFunctionReference != mStencilParameters.stencilFunctionReference )
598 mStencilParameters.stencilFunctionReference = stencilFunctionReference;
599 SetStencilFunctionReferenceMessage( GetEventThreadServices(), *mSceneObject, stencilFunctionReference );
604 case Dali::Renderer::Property::STENCIL_MASK:
607 if( propertyValue.Get( stencilMask ) )
609 if( stencilMask != mStencilParameters.stencilMask )
611 mStencilParameters.stencilMask = stencilMask;
612 SetStencilMaskMessage( GetEventThreadServices(), *mSceneObject, stencilMask );
617 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
619 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnFail;
620 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
622 mStencilParameters.stencilOperationOnFail = convertedValue;
623 SetStencilOperationOnFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
627 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
629 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZFail;
630 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
632 mStencilParameters.stencilOperationOnZFail = convertedValue;
633 SetStencilOperationOnZFailMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
637 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
639 StencilOperation::Type convertedValue = mStencilParameters.stencilOperationOnZPass;
640 if( Scripting::GetEnumerationProperty< StencilOperation::Type >( propertyValue, STENCIL_OPERATION_TABLE, STENCIL_OPERATION_TABLE_COUNT, convertedValue ) )
642 mStencilParameters.stencilOperationOnZPass = convertedValue;
643 SetStencilOperationOnZPassMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
647 case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
649 bool writeToColorBuffer;
650 if( propertyValue.Get( writeToColorBuffer ) )
652 if( mWriteToColorBuffer != writeToColorBuffer )
654 mWriteToColorBuffer = writeToColorBuffer;
655 SetWriteToColorBufferMessage( GetEventThreadServices(), *mSceneObject, writeToColorBuffer );
663 void Renderer::SetSceneGraphProperty( Property::Index index,
664 const PropertyMetadata& entry,
665 const Property::Value& value )
667 RENDERER_IMPL.SetSceneGraphProperty( GetEventThreadServices(), this, index, entry, value );
668 OnPropertySet(index, value);
671 Property::Value Renderer::GetDefaultProperty( Property::Index index ) const
673 Property::Value value;
676 case Dali::Renderer::Property::DEPTH_INDEX:
678 value = GetDepthIndex();
681 case Dali::Renderer::Property::FACE_CULLING_MODE:
683 value = mFaceCullingMode;
686 case Dali::Renderer::Property::BLEND_MODE:
691 case Dali::Renderer::Property::BLEND_EQUATION_RGB:
693 value = static_cast<int>( mBlendingOptions.GetBlendEquationRgb() );
696 case Dali::Renderer::Property::BLEND_EQUATION_ALPHA:
698 value = static_cast<int>( mBlendingOptions.GetBlendEquationAlpha() );
701 case Dali::Renderer::Property::BLEND_FACTOR_SRC_RGB:
703 BlendFactor::Type srcFactorRgb;
704 BlendFactor::Type destFactorRgb;
705 BlendFactor::Type srcFactorAlpha;
706 BlendFactor::Type destFactorAlpha;
707 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
708 value = static_cast<int>( srcFactorRgb );
711 case Dali::Renderer::Property::BLEND_FACTOR_DEST_RGB:
713 BlendFactor::Type srcFactorRgb;
714 BlendFactor::Type destFactorRgb;
715 BlendFactor::Type srcFactorAlpha;
716 BlendFactor::Type destFactorAlpha;
717 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
718 value = static_cast<int>( destFactorRgb );
721 case Dali::Renderer::Property::BLEND_FACTOR_SRC_ALPHA:
723 BlendFactor::Type srcFactorRgb;
724 BlendFactor::Type destFactorRgb;
725 BlendFactor::Type srcFactorAlpha;
726 BlendFactor::Type destFactorAlpha;
727 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
728 value = static_cast<int>( srcFactorAlpha );
731 case Dali::Renderer::Property::BLEND_FACTOR_DEST_ALPHA:
733 BlendFactor::Type srcFactorRgb;
734 BlendFactor::Type destFactorRgb;
735 BlendFactor::Type srcFactorAlpha;
736 BlendFactor::Type destFactorAlpha;
737 GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
738 value = static_cast<int>( destFactorAlpha );
741 case Dali::Renderer::Property::BLEND_COLOR:
745 value = *mBlendColor;
749 value = Color::TRANSPARENT;
753 case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
755 value = IsPreMultipliedAlphaEnabled();
758 case Dali::Renderer::Property::INDEX_RANGE_FIRST:
760 value = static_cast<int>( mIndexedDrawFirstElement );
763 case Dali::Renderer::Property::INDEX_RANGE_COUNT:
765 value = static_cast<int>( mIndexedDrawElementCount );
768 case Dali::Renderer::Property::DEPTH_WRITE_MODE:
770 value = mDepthWriteMode;
773 case Dali::Renderer::Property::DEPTH_FUNCTION:
775 value = mDepthFunction;
778 case Dali::Renderer::Property::DEPTH_TEST_MODE:
780 value = mDepthTestMode;
783 case Dali::Renderer::Property::STENCIL_FUNCTION:
785 value = mStencilParameters.stencilFunction;
788 case Dali::Renderer::Property::STENCIL_FUNCTION_MASK:
790 value = mStencilParameters.stencilFunctionMask;
793 case Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE:
795 value = mStencilParameters.stencilFunctionReference;
798 case Dali::Renderer::Property::STENCIL_MASK:
800 value = mStencilParameters.stencilMask;
803 case Dali::Renderer::Property::STENCIL_MODE:
805 value = mStencilParameters.stencilMode;
808 case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
810 value = mStencilParameters.stencilOperationOnFail;
813 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL:
815 value = mStencilParameters.stencilOperationOnZFail;
818 case Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS:
820 value = mStencilParameters.stencilOperationOnZPass;
823 case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
825 value = mWriteToColorBuffer;
832 const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
837 const SceneGraph::PropertyOwner* Renderer::GetSceneObject() const
842 const SceneGraph::PropertyBase* Renderer::GetSceneObjectAnimatableProperty( Property::Index index ) const
844 DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
845 const SceneGraph::PropertyBase* property = NULL;
849 property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
851 &Renderer::FindAnimatableProperty,
852 &Renderer::FindCustomProperty,
859 const PropertyInputImpl* Renderer::GetSceneObjectInputProperty( Property::Index index ) const
861 const PropertyInputImpl* property = NULL;
865 const SceneGraph::PropertyBase* baseProperty =
866 RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
867 &Renderer::FindAnimatableProperty,
868 &Renderer::FindCustomProperty,
870 property = static_cast<const PropertyInputImpl*>( baseProperty );
876 int Renderer::GetPropertyComponentIndex( Property::Index index ) const
878 return Property::INVALID_COMPONENT_INDEX;
881 bool Renderer::OnStage() const
883 return mOnStageCount > 0;
886 void Renderer::Connect()
888 if( mOnStageCount == 0 )
890 mTextureSetConnector.OnStageConnect();
895 void Renderer::Disconnect()
898 if( mOnStageCount == 0 )
900 mTextureSetConnector.OnStageDisconnect();
905 : mSceneObject (NULL ),
909 mIndexedDrawFirstElement( 0 ),
910 mIndexedDrawElementCount( 0 ),
911 mStencilParameters( StencilMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
913 mDepthFunction( DepthFunction::LESS ),
914 mFaceCullingMode( FaceCullingMode::NONE ),
915 mBlendMode( BlendMode::AUTO ),
916 mDepthWriteMode( DepthWriteMode::AUTO ),
917 mDepthTestMode( DepthTestMode::AUTO ),
918 mWriteToColorBuffer( true ),
919 mPremultipledAlphaEnabled( false )
923 void Renderer::Initialize()
925 EventThreadServices& eventThreadServices = GetEventThreadServices();
926 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
928 mSceneObject = SceneGraph::Renderer::New();
929 AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
931 eventThreadServices.RegisterObject( this );
934 Renderer::~Renderer()
936 if( EventThreadServices::IsCoreRunning() )
938 EventThreadServices& eventThreadServices = GetEventThreadServices();
939 SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
940 RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
942 eventThreadServices.UnregisterObject( this );
946 } // namespace Internal