Make SceneView's SetResolution works well 70/303770/2
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 4 Jan 2024 12:23:07 +0000 (21:23 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 4 Jan 2024 13:47:43 +0000 (22:47 +0900)
Let we change codes that might need to check whether the size of render target
is inputed by App side, by the API SetResolution.

We usually use it to reduce memory of SceneView FBO usage. So let we also make
ShadowMap size will relative with resolution.

Change-Id: Ic243dae41da04f5adea95998b5e49d863b92ba86
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.cpp
dali-scene3d/internal/controls/scene-view/scene-view-impl.h

index 7adb73e..37b1f98 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@ const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
  * These textures are based off version of Wave engine sample
  * Take from https://github.com/WaveEngine/Samples
  *
- * Copyright (c) 2023 Wave Coorporation
+ * Copyright (c) 2024 Wave Coorporation
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -313,13 +313,12 @@ int UtcDaliSceneViewOnScene02(void)
 {
   ToolkitTestApplication application;
 
-  uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
-  DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
+  uint32_t baseRenderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
 
   Scene3D::SceneView view = Scene3D::SceneView::New();
 
-  renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
-  DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION);
+  uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
+  DALI_TEST_EQUALS(baseRenderTaskCount, renderTaskCount, TEST_LOCATION);
 
   application.GetScene().Add(view);
 
@@ -327,9 +326,9 @@ int UtcDaliSceneViewOnScene02(void)
   application.Render();
 
   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
-  DALI_TEST_EQUALS(3u, renderTaskCount, TEST_LOCATION);
+  DALI_TEST_EQUALS(baseRenderTaskCount + 2u, renderTaskCount, TEST_LOCATION);
 
-  RenderTask  renderTask = application.GetScene().GetRenderTaskList().GetTask(2u);
+  RenderTask  renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount + 1u);
   CameraActor camera     = renderTask.GetCameraActor();
 
   CameraActor defaultCamera = renderTask.GetCameraActor();
@@ -685,6 +684,8 @@ int UtcDaliSceneViewUseFramebuffer02(void)
 {
   ToolkitTestApplication application;
 
+  uint32_t baseRenderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
+
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
 
@@ -693,7 +694,7 @@ int UtcDaliSceneViewUseFramebuffer02(void)
   application.SendNotification();
   application.Render();
 
-  RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(2u);
+  RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount + 1u);
   DALI_TEST_CHECK(!renderTask.GetFrameBuffer());
 
   view.UseFramebuffer(true);
@@ -996,20 +997,20 @@ int UtcDaliSceneViewCreateAndRemoveRenderTask(void)
   ToolkitTestApplication application;
   RenderTaskList         taskList = application.GetScene().GetRenderTaskList();
 
-  uint32_t renderTaskCount = taskList.GetTaskCount();
+  uint32_t baseRenderTaskCount = taskList.GetTaskCount();
 
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
 
-  DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
+  DALI_TEST_EQUALS(baseRenderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
 
   application.GetScene().Add(view);
 
-  DALI_TEST_EQUALS(renderTaskCount + 2, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
+  DALI_TEST_EQUALS(baseRenderTaskCount + 2, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
 
   view.Unparent();
 
-  DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
+  DALI_TEST_EQUALS(baseRenderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION);
 
   END_TEST;
 }
@@ -1078,6 +1079,87 @@ int UtcDaliSceneViewSetResolution(void)
   END_TEST;
 }
 
+int UtcDaliSceneViewSetResolution02(void)
+{
+  tet_infoline("Test whether framebuffer created well base on inputed resolution");
+  ToolkitTestApplication application;
+  RenderTaskList         renderTaskList = application.GetScene().GetRenderTaskList();
+
+  uint32_t baseRenderTaskCount = renderTaskList.GetTaskCount();
+
+  Scene3D::SceneView view = Scene3D::SceneView::New();
+  application.GetScene().Add(view);
+  view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
+
+  DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
+
+  uint32_t expectWidth  = 83u;
+  uint32_t expectHeight = 207u;
+
+  view.SetResolution(expectWidth, expectHeight);
+
+  DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION);
+
+  tet_printf("Test Framebuffer result target created well\n");
+  view.UseFramebuffer(true);
+
+  RenderTask renderTask = renderTaskList.GetTask(baseRenderTaskCount + 1u);
+  DALI_TEST_CHECK(renderTask);
+
+  FrameBuffer frameBuffer = renderTask.GetFrameBuffer();
+  DALI_TEST_CHECK(frameBuffer);
+
+  DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION);
+
+  Texture renderTargetTexture = frameBuffer.GetColorTexture();
+  DALI_TEST_CHECK(renderTargetTexture);
+  DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION);
+
+  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);
+  DALI_TEST_CHECK(renderTask);
+
+  frameBuffer = renderTask.GetFrameBuffer();
+  DALI_TEST_CHECK(frameBuffer);
+
+  DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION);
+
+  renderTargetTexture = frameBuffer.GetColorTexture();
+  DALI_TEST_CHECK(renderTargetTexture);
+
+  DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION);
+
+  tet_printf("Test Framebuffer result target created well after change resolution\n");
+  expectWidth  = 421u;
+  expectHeight = 103u;
+  view.SetResolution(expectWidth, expectHeight);
+
+  renderTask = renderTaskList.GetTask(baseRenderTaskCount + 1u);
+  DALI_TEST_CHECK(renderTask);
+
+  frameBuffer = renderTask.GetFrameBuffer();
+  DALI_TEST_CHECK(frameBuffer);
+
+  DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION);
+
+  renderTargetTexture = frameBuffer.GetColorTexture();
+  DALI_TEST_CHECK(renderTargetTexture);
+
+  DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION);
+  DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION);
+
+  END_TEST;
+}
+
 namespace
 {
 const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png";
index d4f4034..2b4b498 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -72,8 +72,8 @@ constexpr int32_t  INVALID_INDEX           = -1;
 constexpr uint32_t MAXIMUM_SIZE_SHADOW_MAP = 2048;
 
 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;
+static constexpr std::string_view Y_FLIP_MASK_TEXTURE     = "uYFlipMaskTexture";
+static constexpr float            FLIP_MASK_TEXTURE       = 1.0f;
 
 Dali::Actor CreateSkybox()
 {
@@ -642,8 +642,7 @@ void SceneView::SetShadow(Scene3D::Light light)
   SetShadowLightConstraint(selectedCamera, lightCamera);
 
   // make framebuffer for depth map and set it to render task.
-  Vector3  size                = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
-  uint32_t shadowMapBufferSize = std::min(static_cast<uint32_t>(std::max(size.width, size.height)), MAXIMUM_SIZE_SHADOW_MAP);
+  uint32_t shadowMapBufferSize = std::min(std::max(GetResolutionWidth(), GetResolutionHeight()), MAXIMUM_SIZE_SHADOW_MAP);
   UpdateShadowMapBuffer(shadowMapBufferSize);
 
   // use lightCamera as a camera of shadow render task.
@@ -755,9 +754,7 @@ void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
     // Create new framebuffer with changed multiSamplingLevel.
     if(mRenderTask && mFrameBuffer && mTexture)
     {
-      Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
-
-      mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
+      mFrameBuffer = FrameBuffer::New(GetResolutionWidth(), GetResolutionHeight(), FrameBuffer::Attachment::DEPTH_STENCIL);
       mFrameBuffer.AttachColorTexture(mTexture);
       DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
       mRenderTask.SetFrameBuffer(mFrameBuffer);
@@ -836,7 +833,7 @@ void SceneView::SetAlphaMaskUrl(std::string& alphaMaskUrl)
 {
   if(mAlphaMaskUrl != alphaMaskUrl)
   {
-    mAlphaMaskUrl = alphaMaskUrl;
+    mAlphaMaskUrl           = alphaMaskUrl;
     mMaskingPropertyChanged = true;
     UpdateRenderTask();
   }
@@ -866,7 +863,7 @@ void SceneView::EnableCropToMask(bool enableCropToMask)
 {
   if(mCropToMask != enableCropToMask)
   {
-    mCropToMask = enableCropToMask;
+    mCropToMask             = enableCropToMask;
     mMaskingPropertyChanged = true;
     UpdateRenderTask();
   }
@@ -1115,23 +1112,18 @@ void SceneView::UpdateRenderTask()
     {
       mRenderTask.SetCameraActor(mSelectedCamera);
     }
+    uint32_t width  = GetResolutionWidth();
+    uint32_t height = GetResolutionHeight();
 
-    Vector3     size        = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
-    float aspectRatio = size.width / size.height;
-
-    uint32_t shadowMapBufferSize = std::min(static_cast<uint32_t>(std::max(size.width, size.height)), MAXIMUM_SIZE_SHADOW_MAP);
+    uint32_t shadowMapBufferSize = std::min(std::max(width, height), MAXIMUM_SIZE_SHADOW_MAP);
     UpdateShadowMapBuffer(shadowMapBufferSize);
 
     if(mUseFrameBuffer)
     {
-      uint32_t width  = (mWindowWidth == 0 || mWindowHeight == 0) ? static_cast<uint32_t>(size.width) : mWindowWidth;
-      uint32_t height = (mWindowWidth == 0 || mWindowHeight == 0) ? static_cast<uint32_t>(size.height) : mWindowHeight;
-      aspectRatio     = static_cast<float>(width) / static_cast<float>(height);
-
       Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
       if(!currentFrameBuffer ||
-         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), size.width) ||
-         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height) ||
+         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), width) ||
+         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), height) ||
          mMaskingPropertyChanged ||
          mWindowSizeChanged)
       {
@@ -1169,7 +1161,7 @@ void SceneView::UpdateRenderTask()
         mRenderTask.SetClearColor(Color::TRANSPARENT);
 
         mMaskingPropertyChanged = false;
-        mWindowSizeChanged = false;
+        mWindowSizeChanged      = false;
       }
     }
     else
@@ -1190,7 +1182,11 @@ void SceneView::UpdateRenderTask()
       }
     }
 
-    mSelectedCamera.SetAspectRatio(aspectRatio);
+    if(width > 0u && height > 0u)
+    {
+      float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
+      mSelectedCamera.SetAspectRatio(aspectRatio);
+    }
 
     RotateCamera();
   }
index 769484c..1ddfd27 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
 
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -445,7 +445,7 @@ private:
   float                                          mSkyboxIntensity{1.0f};
   uint8_t                                        mFrameBufferMultiSamplingLevel{0u};
 
-  bool mWindowSizeChanged{false};
+  bool     mWindowSizeChanged{false};
   uint32_t mWindowWidth{0};
   uint32_t mWindowHeight{0};