/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/devel-api/scripting/scripting.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
#include <dali/public-api/object/type-registry.h>
#include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
#include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
DALI_PROPERTY( "depthWriteMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_WRITE_MODE )
DALI_PROPERTY( "depthFunction", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_FUNCTION )
DALI_PROPERTY( "depthTestMode", INTEGER, true, false, false, Dali::Renderer::Property::DEPTH_TEST_MODE )
+DALI_PROPERTY( "renderMode", INTEGER, true, false, false, Dali::Renderer::Property::RENDER_MODE )
DALI_PROPERTY( "stencilFunction", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION )
DALI_PROPERTY( "stencilFunctionMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_MASK )
DALI_PROPERTY( "stencilFunctionReference", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_FUNCTION_REFERENCE )
DALI_PROPERTY( "stencilMask", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MASK )
-DALI_PROPERTY( "stencilMode", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_MODE )
DALI_PROPERTY( "stencilOperationOnFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL )
DALI_PROPERTY( "stencilOperationOnZFail", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL )
DALI_PROPERTY( "stencilOperationOnZPass", INTEGER, true, false, false, Dali::Renderer::Property::STENCIL_OPERATION_ON_Z_PASS )
-DALI_PROPERTY( "writeToColorBuffer", BOOLEAN, true, false, false, Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER )
-DALI_PROPERTY( "batchingEnabled", BOOLEAN, true, false, false, Dali::Renderer::Property::BATCHING_ENABLED )
DALI_PROPERTY_TABLE_END( DEFAULT_RENDERER_PROPERTY_START_INDEX )
// Property string to enumeration tables:
DALI_ENUM_TO_STRING_WITH_SCOPE( StencilFunction, ALWAYS )
DALI_ENUM_TO_STRING_TABLE_END( STENCIL_FUNCTION )
-DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_MODE )
-DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, OFF )
-DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, AUTO )
-DALI_ENUM_TO_STRING_WITH_SCOPE( StencilMode, ON )
-DALI_ENUM_TO_STRING_TABLE_END( STENCIL_MODE )
+DALI_ENUM_TO_STRING_TABLE_BEGIN( RENDER_MODE )
+DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, NONE )
+DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, AUTO )
+DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR )
+DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, STENCIL )
+DALI_ENUM_TO_STRING_WITH_SCOPE( RenderMode, COLOR_STENCIL )
+DALI_ENUM_TO_STRING_TABLE_END( RENDER_MODE )
DALI_ENUM_TO_STRING_TABLE_BEGIN( STENCIL_OPERATION )
DALI_ENUM_TO_STRING_WITH_SCOPE( StencilOperation, ZERO )
void Renderer::SetTextures( TextureSet& textureSet )
{
- mTextureSetConnector.Set( textureSet, OnStage() );
+ mTextureSet = &textureSet;
const SceneGraph::TextureSet* textureSetSceneObject = textureSet.GetTextureSetSceneObject();
SetTexturesMessage( GetEventThreadServices(), *mSceneObject, *textureSetSceneObject );
}
TextureSet* Renderer::GetTextures() const
{
- return mTextureSetConnector.Get().Get();
+ return mTextureSet.Get();
}
void Renderer::SetShader( Shader& shader )
equationAlpha = mBlendingOptions.GetBlendEquationAlpha();
}
-void Renderer::SetBlendColor( const Vector4& color )
-{
- if( !mBlendColor )
- {
- mBlendColor = new Vector4();
- }
- if( *mBlendColor != color )
- {
- *mBlendColor = color;
- SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, *mBlendColor );
- }
-}
-
-Vector4 Renderer::GetBlendColor() const
-{
- if( mBlendColor )
- {
- return *mBlendColor;
- }
- return Color::TRANSPARENT; // GL default
-}
-
void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
{
if( firstElement != mIndexedDrawFirstElement )
{
if( preMultipled )
{
- SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE );
+ SetBlendFunc( BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA );
}
mPremultipledAlphaEnabled = preMultipled;
SetEnablePreMultipliedAlphaMessage( GetEventThreadServices(), *mSceneObject, mPremultipledAlphaEnabled );
return mPremultipledAlphaEnabled;
}
-bool Renderer::IsBatchingEnabled() const
-{
- return mBatchingEnabled;
-}
-
SceneGraph::Renderer* Renderer::GetRendererSceneObject()
{
return mSceneObject;
}
break;
}
- case Dali::Renderer::Property::STENCIL_MODE:
+ case Dali::Renderer::Property::RENDER_MODE:
{
- StencilMode::Type convertedValue = mStencilParameters.stencilMode;
- if( Scripting::GetEnumerationProperty< StencilMode::Type >( propertyValue, STENCIL_MODE_TABLE, STENCIL_MODE_TABLE_COUNT, convertedValue ) )
+ RenderMode::Type convertedValue = mStencilParameters.renderMode;
+ if( Scripting::GetEnumerationProperty< RenderMode::Type >( propertyValue, RENDER_MODE_TABLE, RENDER_MODE_TABLE_COUNT, convertedValue ) )
{
- mStencilParameters.stencilMode = convertedValue;
- SetStencilModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
+ mStencilParameters.renderMode = convertedValue;
+ SetRenderModeMessage( GetEventThreadServices(), *mSceneObject, convertedValue );
}
break;
}
}
break;
}
- case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
- {
- bool writeToColorBuffer;
- if( propertyValue.Get( writeToColorBuffer ) )
- {
- if( mWriteToColorBuffer != writeToColorBuffer )
- {
- mWriteToColorBuffer = writeToColorBuffer;
- SetWriteToColorBufferMessage( GetEventThreadServices(), *mSceneObject, writeToColorBuffer );
- }
- }
- break;
- }
- case Dali::Renderer::Property::BATCHING_ENABLED:
- {
- bool enabled;
- if( propertyValue.Get( enabled ) )
- {
- if( mBatchingEnabled != enabled )
- {
- mBatchingEnabled = enabled;
- SetBatchingEnabledMessage( GetEventThreadServices(), *mSceneObject, mBatchingEnabled );
- }
- }
- break;
- }
}
}
}
case Dali::Renderer::Property::BLEND_COLOR:
{
- if( mBlendColor )
- {
- value = *mBlendColor;
- }
- else
- {
- value = Color::TRANSPARENT;
- }
+ value = GetBlendColor();
break;
}
case Dali::Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA:
value = mDepthWriteMode;
break;
}
- case Dali::Renderer::Property::BATCHING_ENABLED:
- {
- value = mBatchingEnabled;
- break;
- }
case Dali::Renderer::Property::DEPTH_FUNCTION:
{
value = mDepthFunction;
value = mStencilParameters.stencilMask;
break;
}
- case Dali::Renderer::Property::STENCIL_MODE:
+ case Dali::Renderer::Property::RENDER_MODE:
{
- value = mStencilParameters.stencilMode;
+ value = mStencilParameters.renderMode;
break;
}
case Dali::Renderer::Property::STENCIL_OPERATION_ON_FAIL:
value = mStencilParameters.stencilOperationOnZPass;
break;
}
- case Dali::Renderer::Property::WRITE_TO_COLOR_BUFFER:
- {
- value = mWriteToColorBuffer;
- break;
- }
}
return value;
}
+Property::Value Renderer::GetDefaultPropertyCurrentValue( Property::Index index ) const
+{
+ return GetDefaultProperty( index ); // Event-side only properties
+}
+
const SceneGraph::PropertyOwner* Renderer::GetPropertyOwner() const
{
return mSceneObject;
DALI_ASSERT_ALWAYS( IsPropertyAnimatable(index) && "Property is not animatable" );
const SceneGraph::PropertyBase* property = NULL;
- if( OnStage() )
- {
- property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
- this,
- &Renderer::FindAnimatableProperty,
- &Renderer::FindCustomProperty,
- index );
- }
+ property = RENDERER_IMPL.GetRegisteredSceneGraphProperty(
+ this,
+ &Renderer::FindAnimatableProperty,
+ &Renderer::FindCustomProperty,
+ index );
return property;
}
{
const PropertyInputImpl* property = NULL;
- if( OnStage() )
- {
- const SceneGraph::PropertyBase* baseProperty =
- RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
- &Renderer::FindAnimatableProperty,
- &Renderer::FindCustomProperty,
- index );
- property = static_cast<const PropertyInputImpl*>( baseProperty );
- }
+ const SceneGraph::PropertyBase* baseProperty =
+ RENDERER_IMPL.GetRegisteredSceneGraphProperty( this,
+ &Renderer::FindAnimatableProperty,
+ &Renderer::FindCustomProperty,
+ index );
+ property = static_cast<const PropertyInputImpl*>( baseProperty );
return property;
}
return Property::INVALID_COMPONENT_INDEX;
}
-bool Renderer::OnStage() const
-{
- return mOnStageCount > 0;
-}
-
-void Renderer::Connect()
-{
- if( mOnStageCount == 0 )
- {
- mTextureSetConnector.OnStageConnect();
- }
- ++mOnStageCount;
-}
-
-void Renderer::Disconnect()
-{
- --mOnStageCount;
- if( mOnStageCount == 0 )
- {
- mTextureSetConnector.OnStageDisconnect();
- }
-}
-
Renderer::Renderer()
-: mSceneObject (NULL ),
- mBlendColor( NULL ),
+: mSceneObject(NULL ),
mDepthIndex( 0 ),
- mOnStageCount( 0 ),
mIndexedDrawFirstElement( 0 ),
mIndexedDrawElementCount( 0 ),
- mStencilParameters( StencilMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
+ mStencilParameters( RenderMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ),
mBlendingOptions(),
mDepthFunction( DepthFunction::LESS ),
mFaceCullingMode( FaceCullingMode::NONE ),
mBlendMode( BlendMode::AUTO ),
mDepthWriteMode( DepthWriteMode::AUTO ),
mDepthTestMode( DepthTestMode::AUTO ),
- mWriteToColorBuffer( true ),
- mPremultipledAlphaEnabled( false ),
- mBatchingEnabled( false )
+ mPremultipledAlphaEnabled( false )
{
}
SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
mSceneObject = SceneGraph::Renderer::New();
- AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
+ OwnerPointer< SceneGraph::Renderer > transferOwnership( mSceneObject );
+ AddRendererMessage( updateManager, transferOwnership );
eventThreadServices.RegisterObject( this );
}
+void Renderer::SetBlendColor( const Vector4& blendColor )
+{
+ mBlendingOptions.SetBlendColor( blendColor );
+ SetBlendColorMessage( GetEventThreadServices(), *mSceneObject, GetBlendColor() );
+}
+
+const Vector4& Renderer::GetBlendColor() const
+{
+ const Vector4* blendColor = mBlendingOptions.GetBlendColor();
+ if( blendColor )
+ {
+ return *blendColor;
+ }
+ return Color::TRANSPARENT; // GL default
+}
+
Renderer::~Renderer()
{
if( EventThreadServices::IsCoreRunning() )
{
EventThreadServices& eventThreadServices = GetEventThreadServices();
SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
- RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
+ RemoveRendererMessage( updateManager, *mSceneObject );
eventThreadServices.UnregisterObject( this );
}