Add Renderer::BlendMode::USE_ACTOR_OPACITY 03/285403/10
authorseungho baek <sbsh.baek@samsung.com>
Mon, 12 Dec 2022 08:00:52 +0000 (17:00 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Wed, 21 Dec 2022 01:30:54 +0000 (10:30 +0900)
 - This option make the renderer opaque only when its Actor::Color is opaque.

Change-Id: I931b54bd42d83aa8460a9e6ee932f3511cf19401
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
automated-tests/src/dali/utc-Dali-Renderer.cpp
dali/internal/event/rendering/renderer-impl.cpp
dali/internal/update/rendering/scene-graph-renderer.cpp
dali/public-api/rendering/renderer.h

index 3fd820b..67fa251 100644 (file)
@@ -2818,6 +2818,63 @@ int UtcDaliRendererSetDepthWriteMode(void)
   END_TEST;
 }
 
+int UtcDaliRendererBlendModeUseActorOpacity(void)
+{
+  TestApplication application;
+  tet_infoline("Test setting the UseActorOpacity");
+
+  Geometry geometry = CreateQuadGeometry();
+  Shader   shader   = CreateShader();
+  Renderer renderer = Renderer::New(geometry, shader);
+
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+  actor.SetProperty(Actor::Property::SIZE, Vector2(400.0f, 400.0f));
+  Integration::Scene scene = application.GetScene();
+  scene.GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
+  scene.Add(actor);
+
+  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+  renderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::USE_ACTOR_OPACITY);
+  actor.AddRenderer(renderer);
+  application.GetScene().Add(actor);
+
+  application.SendNotification();
+  application.Render();
+
+  // Check the default depth-write status first.
+  DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
+
+  // Turn off depth-writing.
+  actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.5));
+
+  application.SendNotification();
+  application.Render();
+
+  // Check depth-write is now disabled.
+  DALI_TEST_CHECK(!glAbstraction.GetLastDepthMask());
+
+  // Turn on depth-writing.
+  actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 1));
+
+  application.SendNotification();
+  application.Render();
+
+  // Check depth-write is now enabled.
+  DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
+
+  // Turn off depth-writing.
+  actor.SetProperty(Dali::Actor::Property::COLOR, Vector4(1, 1, 1, 0.0));
+
+  application.SendNotification();
+  application.Render();
+
+  // if actor alpha is 0, SetDepthWriteEnable is not called so GetLastDepthMask returns default value true;
+  DALI_TEST_CHECK(glAbstraction.GetLastDepthMask());
+
+  END_TEST;
+}
+
 int UtcDaliRendererCheckStencilDefaults(void)
 {
   TestApplication application;
index bf68b0e..ca336e1 100644 (file)
@@ -80,6 +80,7 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(BLEND_MODE)
   DALI_ENUM_TO_STRING_WITH_SCOPE(BlendMode, AUTO)
   DALI_ENUM_TO_STRING_WITH_SCOPE(BlendMode, ON)
   DALI_ENUM_TO_STRING_WITH_SCOPE(BlendMode, ON_WITHOUT_CULL)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(BlendMode, USE_ACTOR_OPACITY)
 DALI_ENUM_TO_STRING_TABLE_END(BLEND_MODE)
 
 DALI_ENUM_TO_STRING_TABLE_BEGIN(BLEND_EQUATION)
index 1e03ce8..94fc6de 100644 (file)
@@ -663,6 +663,24 @@ Renderer::OpacityType Renderer::GetOpacityType(BufferIndex updateBufferIndex, co
 
       break;
     }
+    case BlendMode::USE_ACTOR_OPACITY: // the renderer should never use blending
+    {
+      // renderer should determine opacity using the actor color
+      float alpha = node.GetWorldColor(updateBufferIndex).a;
+      if(alpha <= FULLY_TRANSPARENT)
+      {
+        opacityType = Renderer::TRANSPARENT;
+      }
+      else if(alpha < FULLY_OPAQUE)
+      {
+        opacityType = Renderer::TRANSLUCENT;
+      }
+      else
+      {
+        opacityType = Renderer::OPAQUE;
+      }
+      break;
+    }
     case BlendMode::OFF: // the renderer should never use blending
     default:
     {
index c19e514..e6f1afe 100644 (file)
@@ -62,10 +62,11 @@ namespace BlendMode
  */
 enum Type
 {
-  OFF,            ///< Blending is disabled.                                                    @SINCE_1_1.43
-  AUTO,           ///< Blending is enabled if there is alpha channel. This is the default mode. @SINCE_1_1.43
-  ON,             ///< Blending is enabled.                                                     @SINCE_1_1.43
-  ON_WITHOUT_CULL ///< Blending is enabled, and don't cull the renderer                         @SINCE_2_0.43
+  OFF,               ///< Blending is disabled.                                                    @SINCE_1_1.43
+  AUTO,              ///< Blending is enabled if there is alpha channel. This is the default mode. @SINCE_1_1.43
+  ON,                ///< Blending is enabled.                                                     @SINCE_1_1.43
+  ON_WITHOUT_CULL,   ///< Blending is enabled, and don't cull the renderer                         @SINCE_2_0.43
+  USE_ACTOR_OPACITY  ///< Blending is enabled when the actor is not opaque                         @SINCE_2_2.7
 };
 
 } // namespace BlendMode