From: seungho baek Date: Wed, 31 Jan 2024 06:20:57 +0000 (+0900) Subject: [Tizen] Create Shadow RenderTask only shadow is required. X-Git-Tag: accepted/tizen/8.0/unified/20240220.144353~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F306263%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Create Shadow RenderTask only shadow is required. - By using OrderIndex, Shadow RenderTask can be created only it is required. Change-Id: I65a14ff4db167b1aa546be81f80238008322e7b5 Signed-off-by: seungho baek --- diff --git a/automated-tests/src/dali-scene3d/utc-Dali-Light.cpp b/automated-tests/src/dali-scene3d/utc-Dali-Light.cpp index cc5bc7f..c9d9f79 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-Light.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-Light.cpp @@ -1046,3 +1046,55 @@ int UtcDaliLightShadowSoftFiltering(void) END_TEST; } + +namespace +{ +constexpr int32_t SCENE_ORDER_INDEX = 100; +constexpr int32_t SHADOW_ORDER_INDEX = 99; +} + +int UtcDaliLightShadowRenderTask(void) +{ + ToolkitTestApplication application; + RenderTaskList taskList = application.GetScene().GetRenderTaskList(); + DALI_TEST_EQUALS(1, taskList.GetTaskCount(), TEST_LOCATION); + + Scene3D::SceneView sceneView = Scene3D::SceneView::New(); + sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT); + sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT); + application.GetScene().Add(sceneView); + + DALI_TEST_EQUALS(2, taskList.GetTaskCount(), TEST_LOCATION); + + sceneView.UseFramebuffer(true); + + DALI_TEST_EQUALS(2, taskList.GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(0, taskList.GetTask(0u).GetOrderIndex(), TEST_LOCATION); + DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(1u).GetOrderIndex(), TEST_LOCATION); + + Scene3D::Light light = Scene3D::Light::New(); + light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE); + Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f)); + light.EnableShadow(true); + sceneView.Add(light); + + DALI_TEST_EQUALS(3, taskList.GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(0, taskList.GetTask(0u).GetOrderIndex(), TEST_LOCATION); + DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(1u).GetOrderIndex(), TEST_LOCATION); + DALI_TEST_EQUALS(SHADOW_ORDER_INDEX, taskList.GetTask(2u).GetOrderIndex(), TEST_LOCATION); + + application.SendNotification(); + + DALI_TEST_EQUALS(SHADOW_ORDER_INDEX, taskList.GetTask(1u).GetOrderIndex(), TEST_LOCATION); + DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(2u).GetOrderIndex(), TEST_LOCATION); + + light.EnableShadow(false); + + DALI_TEST_EQUALS(2, taskList.GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(0, taskList.GetTask(0u).GetOrderIndex(), TEST_LOCATION); + DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(1u).GetOrderIndex(), TEST_LOCATION); + + END_TEST; +} \ No newline at end of file diff --git a/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp b/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp index 37b1f98..06ff712 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp @@ -326,9 +326,9 @@ int UtcDaliSceneViewOnScene02(void) application.Render(); renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); - DALI_TEST_EQUALS(baseRenderTaskCount + 2u, renderTaskCount, TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount + 1u, renderTaskCount, TEST_LOCATION); - RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount + 1u); + RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount); CameraActor camera = renderTask.GetCameraActor(); CameraActor defaultCamera = renderTask.GetCameraActor(); @@ -694,7 +694,7 @@ int UtcDaliSceneViewUseFramebuffer02(void) application.SendNotification(); application.Render(); - RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount + 1u); + RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount); DALI_TEST_CHECK(!renderTask.GetFrameBuffer()); view.UseFramebuffer(true); @@ -1006,7 +1006,7 @@ int UtcDaliSceneViewCreateAndRemoveRenderTask(void) application.GetScene().Add(view); - DALI_TEST_EQUALS(baseRenderTaskCount + 2, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount + 1, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); view.Unparent(); @@ -1105,7 +1105,7 @@ int UtcDaliSceneViewSetResolution02(void) tet_printf("Test Framebuffer result target created well\n"); view.UseFramebuffer(true); - RenderTask renderTask = renderTaskList.GetTask(baseRenderTaskCount + 1u); + RenderTask renderTask = renderTaskList.GetTask(baseRenderTaskCount); DALI_TEST_CHECK(renderTask); FrameBuffer frameBuffer = renderTask.GetFrameBuffer(); @@ -1122,7 +1122,7 @@ int UtcDaliSceneViewSetResolution02(void) tet_printf("Test Framebuffer result target created well after create new FBO, by set multisampling level\n"); view.SetFramebufferMultiSamplingLevel(2u); - renderTask = renderTaskList.GetTask(baseRenderTaskCount + 1u); + renderTask = renderTaskList.GetTask(baseRenderTaskCount); DALI_TEST_CHECK(renderTask); frameBuffer = renderTask.GetFrameBuffer(); @@ -1142,7 +1142,7 @@ int UtcDaliSceneViewSetResolution02(void) expectHeight = 103u; view.SetResolution(expectWidth, expectHeight); - renderTask = renderTaskList.GetTask(baseRenderTaskCount + 1u); + renderTask = renderTaskList.GetTask(baseRenderTaskCount); DALI_TEST_CHECK(renderTask); frameBuffer = renderTask.GetFrameBuffer(); diff --git a/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp b/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp index 8be2fa1..903575e 100644 --- a/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp +++ b/dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp @@ -72,6 +72,9 @@ constexpr int32_t DEFAULT_ORIENTATION = 0; constexpr int32_t INVALID_INDEX = -1; constexpr uint32_t MAXIMUM_SIZE_SHADOW_MAP = 2048; +constexpr int32_t SCENE_ORDER_INDEX = 100; +constexpr int32_t SHADOW_ORDER_INDEX = 99; + static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity"; static constexpr std::string_view Y_FLIP_MASK_TEXTURE = "uYFlipMaskTexture"; static constexpr float FLIP_MASK_TEXTURE = 1.0f; @@ -659,9 +662,13 @@ void SceneView::SetShadow(Scene3D::Light light) UpdateShadowMapBuffer(shadowMapBufferSize); // use lightCamera as a camera of shadow render task. - mShadowMapRenderTask.SetCameraActor(lightCamera); + if(mShadowMapRenderTask) + { + mShadowMapRenderTask.SetCameraActor(lightCamera); + } mShaderManager->SetShadow(light); + UpdateShadowMapBuffer(shadowMapBufferSize); } void SceneView::RemoveShadow(Scene3D::Light light) @@ -678,7 +685,10 @@ void SceneView::RemoveShadow(Scene3D::Light light) // reset framebuffer and remove it from render task. mShadowFrameBuffer.Reset(); mShaderManager->RemoveShadow(); - mShadowMapRenderTask.SetCameraActor(CameraActor()); + if(mShadowMapRenderTask) + { + mShadowMapRenderTask.SetCameraActor(CameraActor()); + } mShadowLight.Reset(); @@ -700,6 +710,13 @@ void SceneView::RemoveShadow(Scene3D::Light light) SetShadow(lightEntity.first); break; } + + if(mShadowMapRenderTask) + { + RenderTaskList taskList = Integration::SceneHolder::Get(Self()).GetRenderTaskList(); + taskList.RemoveTask(mShadowMapRenderTask); + mShadowMapRenderTask.Reset(); + } } uint32_t SceneView::GetActivatedLightCount() const @@ -982,21 +999,12 @@ void SceneView::OnSceneConnection(int depth) if(mSceneHolder) { RenderTaskList taskList = mSceneHolder.GetRenderTaskList(); - mShadowMapRenderTask = taskList.CreateTask(); - mShadowMapRenderTask.SetSourceActor(mRootLayer); - mShadowMapRenderTask.SetExclusive(true); - mShadowMapRenderTask.SetInputEnabled(false); - mShadowMapRenderTask.SetCullMode(false); - mShadowMapRenderTask.SetClearEnabled(true); - mShadowMapRenderTask.SetClearColor(Color::WHITE); - mShadowMapRenderTask.SetRenderPassTag(10); - mShadowMapRenderTask.SetCameraActor(CameraActor()); - mRenderTask = taskList.CreateTask(); mRenderTask.SetSourceActor(mRootLayer); mRenderTask.SetExclusive(true); mRenderTask.SetInputEnabled(true); mRenderTask.SetCullMode(false); + mRenderTask.SetOrderIndex(SCENE_ORDER_INDEX); mRenderTask.SetScreenToFrameBufferMappingActor(Self()); UpdateRenderTask(); @@ -1367,11 +1375,30 @@ void SceneView::NotifyImageBasedLightTextureChange() void SceneView::UpdateShadowMapBuffer(uint32_t shadowMapSize) { + if(!mShadowLight) + { + return; + } + + if(!mShadowMapRenderTask) + { + RenderTaskList taskList = Integration::SceneHolder::Get(Self()).GetRenderTaskList(); + mShadowMapRenderTask = taskList.CreateTask(); + mShadowMapRenderTask.SetSourceActor(mRootLayer); + mShadowMapRenderTask.SetExclusive(true); + mShadowMapRenderTask.SetInputEnabled(false); + mShadowMapRenderTask.SetCullMode(false); + mShadowMapRenderTask.SetClearEnabled(true); + mShadowMapRenderTask.SetClearColor(Color::WHITE); + mShadowMapRenderTask.SetRenderPassTag(10); + mShadowMapRenderTask.SetCameraActor(GetImplementation(mShadowLight).GetCamera()); + mShadowMapRenderTask.SetOrderIndex(SHADOW_ORDER_INDEX); + } + Dali::FrameBuffer currentShadowFrameBuffer = mShadowMapRenderTask.GetFrameBuffer(); - if(mShadowLight && - (!currentShadowFrameBuffer || - !mShadowTexture || - !Dali::Equals(DevelFrameBuffer::GetDepthTexture(currentShadowFrameBuffer).GetWidth(), shadowMapSize))) + if(!currentShadowFrameBuffer || + !mShadowTexture || + !Dali::Equals(DevelFrameBuffer::GetDepthTexture(currentShadowFrameBuffer).GetWidth(), shadowMapSize)) { mShadowFrameBuffer.Reset(); mShadowTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, shadowMapSize, shadowMapSize);