From a655572ea47581cebad010a722db91bae9984980 Mon Sep 17 00:00:00 2001 From: Seungho Baek Date: Wed, 25 Nov 2020 19:07:17 +0900 Subject: [PATCH] Make blend for the opaque renderer when advanced blend equation is applied. - Not to change BlendMode. Change-Id: Ic0d085a67d3c49e270a5cd83e703981bfd916f24 Signed-off-by: Seungho Baek --- automated-tests/src/dali/utc-Dali-Renderer.cpp | 74 ++++++++++++++++++++++ dali/internal/common/blending-options.cpp | 11 ++++ dali/internal/common/blending-options.h | 6 ++ dali/internal/event/actors/actor-impl.cpp | 2 - .../update/rendering/scene-graph-renderer.cpp | 8 +++ 5 files changed, 99 insertions(+), 2 deletions(-) diff --git a/automated-tests/src/dali/utc-Dali-Renderer.cpp b/automated-tests/src/dali/utc-Dali-Renderer.cpp index b50d710..564ca27 100644 --- a/automated-tests/src/dali/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali/utc-Dali-Renderer.cpp @@ -1101,6 +1101,80 @@ int UtcDaliRendererSetBlendMode07(void) END_TEST; } +int UtcDaliRendererSetBlendMode08(void) +{ + TestApplication application; + + tet_infoline("Test setting the blend mode to auto with opaque color and Advanced Blend Equation."); + + if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) ) + { + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::OPACITY, 1.0f); + actor.AddRenderer(renderer); + actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f)); + application.GetScene().Add(actor); + + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::AUTO); + renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true ); + renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN ); + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + glAbstraction.EnableEnableDisableCallTrace(true); + + application.SendNotification(); + application.Render(); + + TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); + std::ostringstream blendStr; + blendStr << GL_BLEND; + DALI_TEST_CHECK(glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str())); + } + + END_TEST; +} + +int UtcDaliRendererSetBlendMode08b(void) +{ + TestApplication application; + + tet_infoline("Test setting the blend mode to off with opaque color and Advanced Blend Equation."); + + if( Dali::Capabilities::IsBlendEquationSupported( DevelBlendEquation::SCREEN ) ) + { + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New(geometry, shader); + + Actor actor = Actor::New(); + actor.SetProperty(Actor::Property::OPACITY, 1.0f); + actor.AddRenderer(renderer); + actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f)); + application.GetScene().Add(actor); + + renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF); + renderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, true ); + renderer.SetProperty( DevelRenderer::Property::BLEND_EQUATION, DevelBlendEquation::SCREEN ); + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + glAbstraction.EnableEnableDisableCallTrace(true); + + application.SendNotification(); + application.Render(); + + TraceCallStack& glEnableStack = glAbstraction.GetEnableDisableTrace(); + std::ostringstream blendStr; + blendStr << GL_BLEND; + DALI_TEST_CHECK(!glEnableStack.FindMethodAndParams("Enable", blendStr.str().c_str())); + } + + END_TEST; +} + int UtcDaliRendererGetBlendMode(void) { TestApplication application; diff --git a/dali/internal/common/blending-options.cpp b/dali/internal/common/blending-options.cpp index 596e544..969d54a 100644 --- a/dali/internal/common/blending-options.cpp +++ b/dali/internal/common/blending-options.cpp @@ -495,6 +495,17 @@ bool BlendingOptions::IsAdvancedBlendEquationApplied() ( ( indexA >= BLENDING_EQUATION_ADVANCED_INDEX_START ) && ( indexA <= BLENDING_EQUATION_ADVANCED_INDEX_END ) ) ); } +bool BlendingOptions::IsAdvancedBlendEquationIncluded( unsigned int bitmask ) +{ + unsigned int indexRgb = bitmask & MASK_EQUATION_RGB; + indexRgb = indexRgb >> SHIFT_TO_EQUATION_RGB; + unsigned int indexA = bitmask & MASK_EQUATION_ALPHA; + indexA = indexA >> SHIFT_TO_EQUATION_ALPHA; + + return ( ( ( indexRgb >= BLENDING_EQUATION_ADVANCED_INDEX_START ) && ( indexRgb <= BLENDING_EQUATION_ADVANCED_INDEX_END ) ) || + ( ( indexA >= BLENDING_EQUATION_ADVANCED_INDEX_START ) && ( indexA <= BLENDING_EQUATION_ADVANCED_INDEX_END ) ) ); +} + bool BlendingOptions::IsAdvancedBlendEquation( DevelBlendEquation::Type equation ) { switch ( equation ) diff --git a/dali/internal/common/blending-options.h b/dali/internal/common/blending-options.h index f150685..f8a4a3d 100644 --- a/dali/internal/common/blending-options.h +++ b/dali/internal/common/blending-options.h @@ -116,6 +116,12 @@ struct BlendingOptions bool IsAdvancedBlendEquationApplied(); /** + * Query whether input bit mask include advanced blend equation. + * @return True if the bit mask include advanced blend equation. + */ + static bool IsAdvancedBlendEquationIncluded( unsigned int bitmask ); + + /** * Query whether input blend equation is advanced option. * @return True if input blend equation is advanced. */ diff --git a/dali/internal/event/actors/actor-impl.cpp b/dali/internal/event/actors/actor-impl.cpp index b6960ed..cc6d998 100755 --- a/dali/internal/event/actors/actor-impl.cpp +++ b/dali/internal/event/actors/actor-impl.cpp @@ -1199,7 +1199,6 @@ uint32_t Actor::AddRenderer( Renderer& renderer ) if(mIsBlendEquationSet) { - renderer.SetBlendMode(Dali::BlendMode::ON); renderer.SetBlendEquation(static_cast(mBlendEquation)); } @@ -1270,7 +1269,6 @@ void Actor::SetBlendEquation(DevelBlendEquation::Type blendEquation) for(uint32_t i = 0; i < rendererCount; ++i) { RendererPtr renderer = GetRendererAt(i); - renderer->SetBlendMode(Dali::BlendMode::ON); renderer->SetBlendEquation(static_cast(blendEquation)); } } diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index cce7464..1039a8d 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace Dali { @@ -710,6 +711,12 @@ Renderer::OpacityType Renderer::GetOpacityType( BufferIndex updateBufferIndex, c } case BlendMode::AUTO: { + if(BlendingOptions::IsAdvancedBlendEquationIncluded(mBlendBitmask)) + { + opacityType = Renderer::TRANSLUCENT; + break; + } + bool shaderRequiresBlending( mShader->HintEnabled( Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT ) ); if( shaderRequiresBlending || ( mTextureSet && mTextureSet->HasAlpha() ) ) { @@ -726,6 +733,7 @@ Renderer::OpacityType Renderer::GetOpacityType( BufferIndex updateBufferIndex, c { opacityType = Renderer::TRANSLUCENT; } + break; } case BlendMode::OFF: // the renderer should never use blending -- 2.7.4