From: seungho baek Date: Mon, 12 Dec 2022 08:00:52 +0000 (+0900) Subject: Add Renderer::BlendMode::USE_ACTOR_OPACITY X-Git-Tag: dali_2.2.7~4 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=4ead80f66de9cb96b0dd85cd039d86671cfaf2f1 Add Renderer::BlendMode::USE_ACTOR_OPACITY - This option make the renderer opaque only when its Actor::Color is opaque. Change-Id: I931b54bd42d83aa8460a9e6ee932f3511cf19401 Signed-off-by: seungho baek --- diff --git a/automated-tests/src/dali/utc-Dali-Renderer.cpp b/automated-tests/src/dali/utc-Dali-Renderer.cpp index 3fd820b..67fa251 100644 --- a/automated-tests/src/dali/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali/utc-Dali-Renderer.cpp @@ -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; diff --git a/dali/internal/event/rendering/renderer-impl.cpp b/dali/internal/event/rendering/renderer-impl.cpp index bf68b0e..ca336e1 100644 --- a/dali/internal/event/rendering/renderer-impl.cpp +++ b/dali/internal/event/rendering/renderer-impl.cpp @@ -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) diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index 1e03ce8..94fc6de 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-renderer.cpp @@ -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: { diff --git a/dali/public-api/rendering/renderer.h b/dali/public-api/rendering/renderer.h index c19e514..e6f1afe 100644 --- a/dali/public-api/rendering/renderer.h +++ b/dali/public-api/rendering/renderer.h @@ -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