Make blend for the opaque renderer when advanced blend equation is applied. 27/248327/4
authorSeungho Baek <sbsh.baek@samsung.com>
Wed, 25 Nov 2020 10:07:17 +0000 (19:07 +0900)
committerseungho <sbsh.baek@samsung.com>
Tue, 1 Dec 2020 08:39:54 +0000 (17:39 +0900)
 - Not to change BlendMode.

Change-Id: Ic0d085a67d3c49e270a5cd83e703981bfd916f24
Signed-off-by: Seungho Baek <sbsh.baek@samsung.com>
automated-tests/src/dali/utc-Dali-Renderer.cpp
dali/internal/common/blending-options.cpp
dali/internal/common/blending-options.h
dali/internal/event/actors/actor-impl.cpp
dali/internal/update/rendering/scene-graph-renderer.cpp

index b50d710..564ca27 100644 (file)
@@ -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;
index 596e544..969d54a 100644 (file)
@@ -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 )
index f150685..f8a4a3d 100644 (file)
@@ -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.
    */
index b6960ed..cc6d998 100755 (executable)
@@ -1199,7 +1199,6 @@ uint32_t Actor::AddRenderer( Renderer& renderer )
 
   if(mIsBlendEquationSet)
   {
-    renderer.SetBlendMode(Dali::BlendMode::ON);
     renderer.SetBlendEquation(static_cast<DevelBlendEquation::Type>(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<DevelBlendEquation::Type>(blendEquation));
       }
     }
index cce7464..1039a8d 100644 (file)
@@ -29,6 +29,7 @@
 #include <dali/internal/render/renderers/render-geometry.h>
 #include <dali/internal/render/shaders/program.h>
 #include <dali/internal/render/shaders/scene-graph-shader.h>
+#include <dali/internal/common/blending-options.h>
 
 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