From 6d0f621ce196d949386a4727f3472f9295efe2c4 Mon Sep 17 00:00:00 2001 From: seungho baek Date: Tue, 5 Dec 2023 17:20:18 +0900 Subject: [PATCH] Use DepthIndex for 3D rendering order Change-Id: I898668b515410c888e616b64ce103f833cc4f399 Signed-off-by: seungho baek --- automated-tests/src/dali/utc-Dali-Renderer.cpp | 81 ++++++++++++++++++++++ .../manager/render-instruction-processor.cpp | 8 ++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/utc-Dali-Renderer.cpp b/automated-tests/src/dali/utc-Dali-Renderer.cpp index 1d9d6a6..9f6115c 100644 --- a/automated-tests/src/dali/utc-Dali-Renderer.cpp +++ b/automated-tests/src/dali/utc-Dali-Renderer.cpp @@ -2304,6 +2304,87 @@ int UtcDaliRendererRenderOrder2DLayerOverlay(void) END_TEST; } +int UtcDaliRendererRenderOrder3DLayer(void) +{ + TestApplication application; + tet_infoline("Test the rendering order in a 3D layer is correct"); + + Shader shader = Shader::New("VertexSource", "FragmentSource"); + Geometry geometry = CreateQuadGeometry(); + + application.GetScene().GetRootLayer().SetProperty(Layer::Property::BEHAVIOR, Layer::Behavior::LAYER_3D); + Actor root = application.GetScene().GetRootLayer(); + + Actor actor0 = CreateActor(root, 0, TEST_LOCATION); + Renderer renderer0 = CreateRenderer(actor0, geometry, shader, 300); + actor0.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR); + + Actor actor1 = CreateActor(root, 0, TEST_LOCATION); + Renderer renderer1 = CreateRenderer(actor1, geometry, shader, 200); + actor1.SetProperty(Dali::Actor::Property::OPACITY, 0.5f); + actor1.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR); + + Actor actor2 = CreateActor(root, 0, TEST_LOCATION); + Renderer renderer2 = CreateRenderer(actor2, geometry, shader, 100); + actor2.SetProperty(Dali::Actor::Property::OPACITY, 0.5f); + actor2.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR); + + Actor actor3 = CreateActor(root, 0, TEST_LOCATION); + Renderer renderer3 = CreateRenderer(actor3, geometry, shader, 0); + actor3.SetProperty(Dali::Actor::Property::OPACITY, 0.5f); + actor3.SetProperty(Dali::Actor::Property::COLOR_MODE, USE_OWN_COLOR); + + application.SendNotification(); + application.Render(0); + + /* + * Create the following hierarchy: + * + * actor2 + * / + * / + * actor1 + * / + * / + * actor0 + * / + * / + * actor3 + * + * Expected rendering order : actor0 - actor3 - actor2 - actor1 + */ + actor2.Add(actor1); + actor1.Add(actor0); + actor0.Add(actor3); + application.SendNotification(); + application.Render(0); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + gl.GetTextureTrace().Reset(); + gl.EnableTextureCallTrace(true); + application.SendNotification(); + application.Render(0); + + int textureBindIndex[4]; + for(unsigned int i(0); i < 4; ++i) + { + std::stringstream params; + params << std::hex << GL_TEXTURE_2D << std::dec << ", " << i + 1; + textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str()); + } + + //Check that actor3 has been rendered after actor0 + DALI_TEST_GREATER(textureBindIndex[3], textureBindIndex[0], TEST_LOCATION); + + //Check that actor2 has been rendered after actor3 + DALI_TEST_GREATER(textureBindIndex[2], textureBindIndex[3], TEST_LOCATION); + + //Check that actor1 has been rendered after actor2 + DALI_TEST_GREATER(textureBindIndex[1], textureBindIndex[2], TEST_LOCATION); + + END_TEST; +} + int UtcDaliRendererSetIndexRange(void) { std::string diff --git a/dali/internal/update/manager/render-instruction-processor.cpp b/dali/internal/update/manager/render-instruction-processor.cpp index 21955c1..34423f9 100644 --- a/dali/internal/update/manager/render-instruction-processor.cpp +++ b/dali/internal/update/manager/render-instruction-processor.cpp @@ -107,6 +107,11 @@ bool CompareItems3D(const RenderInstructionProcessor::SortAttributes& lhs, const } else { + if(lhs.renderItem->mDepthIndex != rhs.renderItem->mDepthIndex) + { + return lhs.renderItem->mDepthIndex < rhs.renderItem->mDepthIndex; + } + // If both RenderItems are transparent, sort using Z, then shader, then material, then geometry. if(Equals(lhs.zValue, rhs.zValue)) { @@ -270,7 +275,8 @@ inline void AddRendererToRenderList(BufferIndex updateBufferIndex, bool isOpaque = true; if(!hasRenderCallback) { - Renderer::OpacityType opacityType = rendererExist ? renderable.mRenderer->GetOpacityType(updateBufferIndex, renderPass, *node) : Renderer::OPAQUE; + bool isVisualRenderer = (isLayer3d && !!(renderable.mRenderer->GetVisualProperties())); + Renderer::OpacityType opacityType = rendererExist ? (isVisualRenderer ? Renderer::TRANSLUCENT : renderable.mRenderer->GetOpacityType(updateBufferIndex, renderPass, *node)) : Renderer::OPAQUE; // We can skip render when node is not clipping and transparent skipRender = (opacityType == Renderer::TRANSPARENT && node->GetClippingMode() == ClippingMode::DISABLED); -- 2.7.4