Make API to set MultiSampling level for SceneView 57/287357/5
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 27 Jan 2023 07:00:00 +0000 (16:00 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Tue, 31 Jan 2023 05:09:19 +0000 (14:09 +0900)
Make new API to set FBO's multiSamplingLevel what this scene view will use.

Change-Id: I124cc9e7d6bcaffbfaf0323abd509fb84a36dbe3
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
dali-scene3d/public-api/controls/scene-view/scene-view.cpp
dali-scene3d/public-api/controls/scene-view/scene-view.h

index 1e74b56..50b41cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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) 2022 Wave Coorporation
+ * Copyright (c) 2023 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
@@ -119,16 +119,15 @@ Dali::Texture GetSpecularTexture(Dali::Scene3D::Model model)
   return texture;
 }
 
-
 // For ResourceReady
 static bool gOnRelayoutCallBackCalled = false;
-void OnRelayoutCallback(Actor actor)
+void        OnRelayoutCallback(Actor actor)
 {
   gOnRelayoutCallBackCalled = true;
 }
 
 static bool gResourceReadyCalled = false;
-void OnResourceReady(Control control)
+void        OnResourceReady(Control control)
 {
   gResourceReadyCalled = true;
 }
@@ -327,7 +326,6 @@ int UtcDaliSceneViewOnScene02(void)
   application.SendNotification();
   application.Render();
 
-
   renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
   DALI_TEST_EQUALS(2u, renderTaskCount, TEST_LOCATION);
 
@@ -553,7 +551,7 @@ int UtcDaliSceneViewImageBasedLight02(void)
 
   DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
 
-  Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
+  Dali::Texture diffuseTexture  = GetDiffuseTexture(modelView1);
   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
 
   gResourceReadyCalled = false;
@@ -571,7 +569,7 @@ int UtcDaliSceneViewImageBasedLight02(void)
 
   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
-  diffuseTexture = GetDiffuseTexture(modelView1);
+  diffuseTexture  = GetDiffuseTexture(modelView1);
   specularTexture = GetSpecularTexture(modelView1);
 
   // reset SceneView IBL
@@ -608,7 +606,7 @@ int UtcDaliSceneViewImageBasedLight03(void)
   application.SendNotification();
   application.Render();
 
-  Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1);
+  Dali::Texture diffuseTexture  = GetDiffuseTexture(modelView1);
   Dali::Texture specularTexture = GetSpecularTexture(modelView1);
 
   gResourceReadyCalled = false;
@@ -629,7 +627,7 @@ int UtcDaliSceneViewImageBasedLight03(void)
   modelView1.SetImageBasedLightSource("", "");
   DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION);
   DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION);
-  diffuseTexture = GetDiffuseTexture(modelView1);
+  diffuseTexture  = GetDiffuseTexture(modelView1);
   specularTexture = GetSpecularTexture(modelView1);
 
   // reset SceneView IBL
@@ -710,13 +708,50 @@ int UtcDaliSceneViewUseFramebuffer02(void)
   END_TEST;
 }
 
+int UtcDaliSceneViewFramebufferMultiSamplingLevel(void)
+{
+  ToolkitTestApplication application;
+
+  Scene3D::SceneView view = Scene3D::SceneView::New();
+  view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100));
+
+  application.GetScene().Add(view);
+
+  application.SendNotification();
+  application.Render();
+
+  uint8_t expectValue        = 0u; // Default MultiSamplingLevel is 0.
+  uint8_t multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
+  DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
+
+  expectValue = 4u; // Change value.
+  view.UseFramebuffer(true);
+  view.SetFramebufferMultiSamplingLevel(expectValue);
+
+  multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
+  DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
+
+  // Note : we don't check multi sampling level is applied to framebuffer, or not.
+  view.UseFramebuffer(false);
+  expectValue = 2u; // Change value.
+  view.SetFramebufferMultiSamplingLevel(expectValue);
+
+  application.SendNotification();
+  application.Render();
+
+  multiSamplingLevel = view.GetFramebufferMultiSamplingLevel();
+  DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliSceneViewResourceReady(void)
 {
   ToolkitTestApplication application;
 
   gOnRelayoutCallBackCalled = false;
-  gResourceReadyCalled = false;
-  Scene3D::SceneView view = Scene3D::SceneView::New();
+  gResourceReadyCalled      = false;
+  Scene3D::SceneView view   = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
   view.OnRelayoutSignal().Connect(OnRelayoutCallback);
   view.ResourceReadySignal().Connect(OnResourceReady);
@@ -737,7 +772,7 @@ int UtcDaliSceneViewResourceReady(void)
   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
 
   gOnRelayoutCallBackCalled = false;
-  gResourceReadyCalled = false;
+  gResourceReadyCalled      = false;
 
   view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
 
@@ -757,7 +792,7 @@ int UtcDaliSceneViewSetSkybox(void)
 {
   ToolkitTestApplication application;
 
-  gResourceReadyCalled = false;
+  gResourceReadyCalled    = false;
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
   view.ResourceReadySignal().Connect(OnResourceReady);
@@ -792,7 +827,7 @@ int UtcDaliSceneViewSetSkyboxEquirectangular(void)
 {
   ToolkitTestApplication application;
 
-  gResourceReadyCalled = false;
+  gResourceReadyCalled    = false;
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
   view.ResourceReadySignal().Connect(OnResourceReady);
@@ -828,7 +863,7 @@ int UtcDaliSceneViewSetSkyboxEmpty(void)
 {
   ToolkitTestApplication application;
 
-  gResourceReadyCalled = false;
+  gResourceReadyCalled    = false;
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
   view.ResourceReadySignal().Connect(OnResourceReady);
@@ -851,7 +886,7 @@ int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void)
 {
   ToolkitTestApplication application;
 
-  gResourceReadyCalled = false;
+  gResourceReadyCalled    = false;
   Scene3D::SceneView view = Scene3D::SceneView::New();
   view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
   view.ResourceReadySignal().Connect(OnResourceReady);
@@ -927,7 +962,7 @@ int UtcDaliSceneViewSetImageBasedLightAndSkybox(void)
 int UtcDaliSceneViewCreateAndRemoveRenderTask(void)
 {
   ToolkitTestApplication application;
-  RenderTaskList taskList = application.GetScene().GetRenderTaskList();
+  RenderTaskList         taskList = application.GetScene().GetRenderTaskList();
 
   uint32_t renderTaskCount = taskList.GetTaskCount();
 
index 5c189c2..86446d4 100644 (file)
 #include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/rendering/frame-buffer-devel.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/math/math-utils.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <string_view>
 
 // INTERNAL INCLUDES
@@ -62,8 +62,6 @@ DALI_TYPE_REGISTRATION_END()
 Property::Index   RENDERING_BUFFER    = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
 constexpr int32_t DEFAULT_ORIENTATION = 0;
 
-constexpr uint8_t DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL = 4u;
-
 static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
 
 Dali::Actor CreateSkybox()
@@ -302,13 +300,13 @@ void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver*
 void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor)
 {
   bool needIblReset = false;
-  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+  bool isOnScene    = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
   if(mDiffuseIblUrl != diffuseUrl)
   {
     mDiffuseIblUrl = diffuseUrl;
     if(mDiffuseIblUrl.empty())
     {
-      needIblReset             = true;
+      needIblReset = true;
     }
     else
     {
@@ -322,7 +320,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
     mSpecularIblUrl = specularUrl;
     if(mSpecularIblUrl.empty())
     {
-      needIblReset              = true;
+      needIblReset = true;
     }
     else
     {
@@ -427,6 +425,32 @@ bool SceneView::IsUsingFramebuffer() const
   return mUseFrameBuffer;
 }
 
+void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
+{
+  if(mFrameBufferMultiSamplingLevel != multiSamplingLevel)
+  {
+    mFrameBufferMultiSamplingLevel = 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.AttachColorTexture(mTexture);
+      DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
+      mRenderTask.SetFrameBuffer(mFrameBuffer);
+
+      // Note : we don't need to create new visual since visual's url is depend on mTexture.
+    }
+  }
+}
+
+uint8_t SceneView::GetFramebufferMultiSamplingLevel() const
+{
+  return mFrameBufferMultiSamplingLevel;
+}
+
 void SceneView::SetSkybox(const std::string& skyboxUrl)
 {
   if(mSkyboxUrl != skyboxUrl)
@@ -638,7 +662,7 @@ void SceneView::UpdateRenderTask()
         mTexture     = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(size.width), unsigned(size.height));
         mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
         mFrameBuffer.AttachColorTexture(mTexture);
-        DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL);
+        DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
         Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(mFrameBuffer, 0u);
 
         Property::Map imagePropertyMap;
@@ -709,9 +733,9 @@ void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentM
   bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
   if(mSkyboxUrl != skyboxUrl || mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
   {
-    mSkyboxDirty         = true;
-    mSkyboxResourceReady = false;
-    mSkyboxUrl           = skyboxUrl;
+    mSkyboxDirty              = true;
+    mSkyboxResourceReady      = false;
+    mSkyboxUrl                = skyboxUrl;
     mSkyboxEnvironmentMapType = skyboxEnvironmentMapType;
   }
 
@@ -770,7 +794,7 @@ void SceneView::OnSkyboxLoadComplete()
   Shader skyboxShader;
   if(mSkyboxEnvironmentMapType == Scene3D::EnvironmentMapType::CUBEMAP)
   {
-    skyboxShader   = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+    skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
   }
   else
   {
index e8e1650..8b175fe 100644 (file)
@@ -31,9 +31,9 @@
 #include <dali/public-api/rendering/texture.h>
 
 // INTERNAL INCLUDES
-#include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
 #include <dali-scene3d/internal/common/environment-map-load-task.h>
 #include <dali-scene3d/internal/common/image-based-light-observer.h>
+#include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
 
 namespace Dali
 {
@@ -139,6 +139,16 @@ public:
   bool IsUsingFramebuffer() const;
 
   /**
+   * @copydoc SceneView::SetFramebufferMultiSamplingLevel()
+   */
+  void SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel);
+
+  /**
+   * @copydoc SceneView::GetFramebufferMultiSamplingLevel()
+   */
+  uint8_t GetFramebufferMultiSamplingLevel() const;
+
+  /**
    * @copydoc SceneView::SetSkybox()
    */
   void SetSkybox(const std::string& skyboxUrl);
@@ -298,14 +308,15 @@ private:
   Dali::Actor                                              mSkybox;
   Quaternion                                               mSkyboxOrientation;
   float                                                    mSkyboxIntensity{1.0f};
+  uint8_t                                                  mFrameBufferMultiSamplingLevel{0u};
 
   // Asynchronous Loading.
-  EnvironmentMapLoadTaskPtr       mSkyboxLoadTask;
-  EnvironmentMapLoadTaskPtr       mIblDiffuseLoadTask;
-  EnvironmentMapLoadTaskPtr       mIblSpecularLoadTask;
-  std::string                     mSkyboxUrl;
-  std::string                     mDiffuseIblUrl;
-  std::string                     mSpecularIblUrl;
+  EnvironmentMapLoadTaskPtr mSkyboxLoadTask;
+  EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
+  EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
+  std::string               mSkyboxUrl;
+  std::string               mDiffuseIblUrl;
+  std::string               mSpecularIblUrl;
 
   Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
   Dali::Texture               mSkyboxTexture;
index 3013720..68bb529 100644 (file)
@@ -127,6 +127,16 @@ bool SceneView::IsUsingFramebuffer() const
   return GetImpl(*this).IsUsingFramebuffer();
 }
 
+void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
+{
+  GetImpl(*this).SetFramebufferMultiSamplingLevel(multiSamplingLevel);
+}
+
+uint8_t SceneView::GetFramebufferMultiSamplingLevel() const
+{
+  return GetImpl(*this).GetFramebufferMultiSamplingLevel();
+}
+
 void SceneView::SetSkybox(const std::string& skyboxUrl)
 {
   GetImpl(*this).SetSkybox(skyboxUrl);
index fdb61e4..1a3407f 100644 (file)
@@ -317,6 +317,28 @@ public:
   bool IsUsingFramebuffer() const;
 
   /**
+   * @brief Sets Multisampling level when we use Framebuffer.
+   * Default is 0.
+   *
+   * @SINCE_2_2.12
+   * @note Only applied if SceneView is using Framebuffer and Framebuffer Multisampling extension is supported.
+   *
+   * @param[in] multiSamplingLevel Level of multisampling if we use Framebuffer.
+   */
+  void SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel);
+
+  /**
+   * @brief Gets Multisampling level that user set.
+   * Default is 0.
+   *
+   * @SINCE_2_2.12
+   * @note This API doesn't check whether Multisampling extension is supported or not.
+   *
+   * @return MultisamplingLevel that user set.
+   */
+  uint8_t GetFramebufferMultiSamplingLevel() const;
+
+  /**
    * @brief Sets Skybox for this scene.
    * Skybox texture starts to be loaded when SceneView is onScene.
    * And Skybox texture is asynchronously loaded. When loading is finished, ResourceReady is emitted.