Use EnvironmentMapLoadTask to load Equirectangular projection image. 72/286172/38
authorseungho baek <sbsh.baek@samsung.com>
Thu, 29 Dec 2022 15:22:07 +0000 (00:22 +0900)
committerseungho baek <sbsh.baek@samsung.com>
Thu, 26 Jan 2023 07:17:23 +0000 (16:17 +0900)
 - Changes SkymapType to EnvironmentMapType
 - TODO: To make IBL image support Equirectangular projection

Change-Id: I34dce88acdd1271dce54af18bc8080d8e452144a
Signed-off-by: seungho baek <sbsh.baek@samsung.com>
31 files changed:
automated-tests/resources/equirectangular.png [new file with mode: 0644]
automated-tests/src/dali-scene3d/CMakeLists.txt
automated-tests/src/dali-scene3d/utc-Dali-CubeLoader.cpp [deleted file]
automated-tests/src/dali-scene3d/utc-Dali-CubeMapLoader.cpp [deleted file]
automated-tests/src/dali-scene3d/utc-Dali-EnvironmentDefinition.cpp
automated-tests/src/dali-scene3d/utc-Dali-EnvironmentMapLoader.cpp [new file with mode: 0644]
automated-tests/src/dali-scene3d/utc-Dali-KtxLoader.cpp
automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp
dali-scene3d/internal/common/environment-map-load-task.cpp
dali-scene3d/internal/common/environment-map-load-task.h
dali-scene3d/internal/common/model-load-task.cpp
dali-scene3d/internal/controls/model/model-impl.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/common/environment-map.h [new file with mode: 0644]
dali-scene3d/public-api/controls/scene-view/scene-view.cpp
dali-scene3d/public-api/controls/scene-view/scene-view.h
dali-scene3d/public-api/file.list
dali-scene3d/public-api/loader/cube-data.cpp [deleted file]
dali-scene3d/public-api/loader/cube-data.h [deleted file]
dali-scene3d/public-api/loader/cube-loader.cpp [deleted file]
dali-scene3d/public-api/loader/cube-map-loader.cpp [deleted file]
dali-scene3d/public-api/loader/cube-map-loader.h [deleted file]
dali-scene3d/public-api/loader/environment-definition.cpp
dali-scene3d/public-api/loader/environment-definition.h
dali-scene3d/public-api/loader/environment-map-data.cpp [new file with mode: 0644]
dali-scene3d/public-api/loader/environment-map-data.h [new file with mode: 0644]
dali-scene3d/public-api/loader/environment-map-loader.cpp [new file with mode: 0644]
dali-scene3d/public-api/loader/environment-map-loader.h [moved from dali-scene3d/public-api/loader/cube-loader.h with 54% similarity]
dali-scene3d/public-api/loader/ktx-loader.cpp
dali-scene3d/public-api/loader/ktx-loader.h

diff --git a/automated-tests/resources/equirectangular.png b/automated-tests/resources/equirectangular.png
new file mode 100644 (file)
index 0000000..2da8243
Binary files /dev/null and b/automated-tests/resources/equirectangular.png differ
index ef86b06..1f80def 100755 (executable)
@@ -12,8 +12,7 @@ SET(TC_SOURCES
   utc-Dali-AnimatedProperty.cpp
   utc-Dali-BvhLoader.cpp
   utc-Dali-CameraParameters.cpp
-  utc-Dali-CubeLoader.cpp
-  utc-Dali-CubeMapLoader.cpp
+  utc-Dali-EnvironmentMapLoader.cpp
   utc-Dali-DliLoader.cpp
   utc-Dali-EnvironmentDefinition.cpp
   utc-Dali-FacialAnimation.cpp
diff --git a/automated-tests/src/dali-scene3d/utc-Dali-CubeLoader.cpp b/automated-tests/src/dali-scene3d/utc-Dali-CubeLoader.cpp
deleted file mode 100644 (file)
index 57482c3..0000000
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// Enable debug log for test coverage
-#define DEBUG_ENABLED 1
-
-#include "dali-scene3d/public-api/loader/cube-loader.h"
-#include <dali-test-suite-utils.h>
-#include <string_view>
-
-#include <fstream>
-
-using namespace Dali;
-using namespace Dali::Scene3D::Loader;
-
-int UtcDaliCubeLoaderFailNonexistent(void)
-{
-  CubeData data;
-  DALI_TEST_CHECK(!LoadCubeData("non-existent.jpg", data));
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderFailInvalid1(void)
-{
-  CubeData data;
-  DALI_TEST_CHECK(!LoadCubeData(TEST_RESOURCE_DIR "/gallery-small-1.jpg", data)); // Wrong sized image
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderSuccess01(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";  // cross horizontal
-  DALI_TEST_CHECK(LoadCubeData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 512;
-    DALI_TEST_EQUAL(size, face[0].GetWidth());
-    DALI_TEST_EQUAL(size, face[0].GetHeight());
-    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderSuccess02(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap_cross_vertical.png"; // cross vertical
-  DALI_TEST_CHECK(LoadCubeData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 256;
-    DALI_TEST_EQUAL(size, face[0].GetWidth());
-    DALI_TEST_EQUAL(size, face[0].GetHeight());
-    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderSuccess03(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/cubemap_array_horizontal.png"; // array horizontal
-  DALI_TEST_CHECK(LoadCubeData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 100;
-    DALI_TEST_EQUAL(size, face[0].GetWidth());
-    DALI_TEST_EQUAL(size, face[0].GetHeight());
-    DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderSuccess04(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/cubemap_array_vertical.png"; // array horizontal
-  DALI_TEST_CHECK(LoadCubeData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 100;
-    DALI_TEST_EQUAL(size, face[0].GetWidth());
-    DALI_TEST_EQUAL(size, face[0].GetHeight());
-    DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeLoaderCubeDataCreateTexture(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
-  DALI_TEST_CHECK(LoadCubeData(path, cubeData));
-
-  TestApplication app;
-  auto texture = cubeData.CreateTexture();
-
-  DALI_TEST_CHECK(texture);
-  DALI_TEST_EQUAL(512u, texture.GetWidth());
-  DALI_TEST_EQUAL(512u, texture.GetHeight());
-
-  END_TEST;
-}
diff --git a/automated-tests/src/dali-scene3d/utc-Dali-CubeMapLoader.cpp b/automated-tests/src/dali-scene3d/utc-Dali-CubeMapLoader.cpp
deleted file mode 100644 (file)
index d00a15b..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// Enable debug log for test coverage
-#define DEBUG_ENABLED 1
-
-#include "dali-scene3d/public-api/loader/cube-map-loader.h"
-#include <dali-test-suite-utils.h>
-#include <string_view>
-
-#include <fstream>
-
-using namespace Dali;
-using namespace Dali::Scene3D::Loader;
-
-int UtcDaliCubeMapLoaderFailNonexistent(void)
-{
-  CubeData data;
-  DALI_TEST_CHECK(!LoadCubeMapData("non-existent.jpg", data));
-  END_TEST;
-}
-
-int UtcDaliCubeMapLoaderFailInvalid1(void)
-{
-  CubeData data;
-  DALI_TEST_CHECK(!LoadCubeMapData(TEST_RESOURCE_DIR "/gallery-small-1.jpg", data)); // Wrong sized image
-  END_TEST;
-}
-
-int UtcDaliCubeMapLoaderSuccess01(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
-  DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 64;
-    for (auto& mipData: face)
-    {
-      DALI_TEST_EQUAL(size, mipData.GetWidth());
-      DALI_TEST_EQUAL(size, mipData.GetHeight());
-      DALI_TEST_EQUAL(Pixel::Format::RGB888, mipData.GetPixelFormat());
-      size /= 2;
-    }
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeMapLoaderSuccess02(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";  // cross horizontal
-  DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
-
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
-  {
-    uint32_t size = 512;
-    DALI_TEST_EQUAL(size, face[0].GetWidth());
-    DALI_TEST_EQUAL(size, face[0].GetHeight());
-    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
-  }
-
-  END_TEST;
-}
-
-int UtcDaliCubeMapLoaderCubeDataCreateTexture01(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
-  DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
-
-  TestApplication app;
-  auto texture = cubeData.CreateTexture();
-
-  DALI_TEST_CHECK(texture);
-  DALI_TEST_EQUAL(64u, texture.GetWidth());
-  DALI_TEST_EQUAL(64u, texture.GetHeight());
-
-  END_TEST;
-}
-
-int UtcDaliCubeMapLoaderCubeDataCreateTexture02(void)
-{
-  CubeData cubeData;
-  auto path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
-  DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
-
-  TestApplication app;
-  auto texture = cubeData.CreateTexture();
-
-  DALI_TEST_CHECK(texture);
-  DALI_TEST_EQUAL(512u, texture.GetWidth());
-  DALI_TEST_EQUAL(512u, texture.GetHeight());
-
-  END_TEST;
-}
index 8286bc3..5dd2f1c 100644 (file)
@@ -30,14 +30,14 @@ int UtcDaliEnvironmentDefinitionLoadRawDefault(void)
   EnvironmentDefinition envDef;
   auto rawData = envDef.LoadRaw("");
 
-  DALI_TEST_EQUAL(rawData.mDiffuse.data.size(), 6u);
-  for (auto& face: rawData.mDiffuse.data)
+  DALI_TEST_EQUAL(rawData.mDiffuse.mPixelData.size(), 6u);
+  for (auto& face: rawData.mDiffuse.mPixelData)
   {
     DALI_TEST_EQUAL(face.size(), 1u);
   }
 
-  DALI_TEST_EQUAL(rawData.mSpecular.data.size(), 6u);
-  for (auto& face: rawData.mSpecular.data)
+  DALI_TEST_EQUAL(rawData.mSpecular.mPixelData.size(), 6u);
+  for (auto& face: rawData.mSpecular.mPixelData)
   {
     DALI_TEST_EQUAL(face.size(), 1u);
   }
@@ -64,8 +64,8 @@ int UtcDaliEnvironmentDefinitionLoadRawSuccess(void)
   EnvironmentDefinition envDef { "forest_irradiance.ktx", "forest_radiance.ktx" };
   auto rawData = envDef.LoadRaw(TEST_RESOURCE_DIR "/");
 
-  DALI_TEST_EQUAL(rawData.mDiffuse.data.size(), 6u);
-  for (auto& face: rawData.mDiffuse.data)
+  DALI_TEST_EQUAL(rawData.mDiffuse.mPixelData.size(), 6u);
+  for (auto& face: rawData.mDiffuse.mPixelData)
   {
     DALI_TEST_EQUAL(face.size(), 1u);
     uint32_t size = 64u;
@@ -78,8 +78,8 @@ int UtcDaliEnvironmentDefinitionLoadRawSuccess(void)
     }
   }
 
-  DALI_TEST_EQUAL(rawData.mSpecular.data.size(), 6u);
-  for (auto& face: rawData.mSpecular.data)
+  DALI_TEST_EQUAL(rawData.mSpecular.mPixelData.size(), 6u);
+  for (auto& face: rawData.mSpecular.mPixelData)
   {
     DALI_TEST_EQUAL(face.size(), 5u);
     uint32_t size = 64u;
diff --git a/automated-tests/src/dali-scene3d/utc-Dali-EnvironmentMapLoader.cpp b/automated-tests/src/dali-scene3d/utc-Dali-EnvironmentMapLoader.cpp
new file mode 100644 (file)
index 0000000..602d369
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// Enable debug log for test coverage
+#define DEBUG_ENABLED 1
+
+#include <dali-test-suite-utils.h>
+#include <string_view>
+#include "dali-scene3d/public-api/loader/environment-map-loader.h"
+
+#include <fstream>
+
+using namespace Dali;
+using namespace Dali::Scene3D::Loader;
+
+int UtcDaliEnvironmentMapLoaderFailNonexistent(void)
+{
+  EnvironmentMapData environmentMapData;
+  DALI_TEST_CHECK(!LoadEnvironmentMap("non-existent.jpg", environmentMapData));
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderSuccess01(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    uint32_t size = 64;
+    for(auto& mipData : face)
+    {
+      DALI_TEST_EQUAL(size, mipData.GetWidth());
+      DALI_TEST_EQUAL(size, mipData.GetHeight());
+      DALI_TEST_EQUAL(Pixel::Format::RGB888, mipData.GetPixelFormat());
+      size /= 2;
+    }
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderAutoType01(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png"; // cross horizontal
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::CUBEMAP);
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    uint32_t size = 512;
+    DALI_TEST_EQUAL(size, face[0].GetWidth());
+    DALI_TEST_EQUAL(size, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderAutoType02(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap_cross_vertical.png"; // cross vertical
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::CUBEMAP);
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    uint32_t size = 256;
+    DALI_TEST_EQUAL(size, face[0].GetWidth());
+    DALI_TEST_EQUAL(size, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderAutoType03(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/cubemap_array_horizontal.png"; // array horizontal
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::CUBEMAP);
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    uint32_t size = 100;
+    DALI_TEST_EQUAL(size, face[0].GetWidth());
+    DALI_TEST_EQUAL(size, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderAutoType04(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/cubemap_array_vertical.png"; // array horizontal
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::CUBEMAP);
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    uint32_t size = 100;
+    DALI_TEST_EQUAL(size, face[0].GetWidth());
+    DALI_TEST_EQUAL(size, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderAutoType05(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/equirectangular.png"; // no cube map
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
+  DALI_TEST_EQUAL(1u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    DALI_TEST_EQUAL(20, face[0].GetWidth());
+    DALI_TEST_EQUAL(10, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGB888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderEquirectangularMapType01(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png"; // no cube map
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::AUTO);
+  environmentMapData.SetEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  DALI_TEST_EQUAL(environmentMapData.GetEnvironmentMapType(), Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
+  DALI_TEST_EQUAL(1u, environmentMapData.mPixelData.size());
+  for(auto& face : environmentMapData.mPixelData)
+  {
+    DALI_TEST_EQUAL(2048, face[0].GetWidth());
+    DALI_TEST_EQUAL(1536, face[0].GetHeight());
+    DALI_TEST_EQUAL(Pixel::Format::RGBA8888, face[0].GetPixelFormat());
+  }
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderEnvironmentMapDataCreateTexture01(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  TestApplication app;
+  auto            texture = environmentMapData.GetTexture();
+
+  DALI_TEST_CHECK(texture);
+  DALI_TEST_EQUAL(64u, texture.GetWidth());
+  DALI_TEST_EQUAL(64u, texture.GetHeight());
+
+  END_TEST;
+}
+
+int UtcDaliEnvironmentMapLoaderEnvironmentMapDataCreateTexture02(void)
+{
+  EnvironmentMapData environmentMapData;
+  auto               path = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
+  DALI_TEST_CHECK(LoadEnvironmentMap(path, environmentMapData));
+
+  TestApplication app;
+  auto            texture = environmentMapData.GetTexture();
+
+  DALI_TEST_CHECK(texture);
+  DALI_TEST_EQUAL(512u, texture.GetWidth());
+  DALI_TEST_EQUAL(512u, texture.GetHeight());
+
+  END_TEST;
+}
index 55f48d7..18b9d08 100644 (file)
@@ -29,40 +29,40 @@ using namespace Dali::Scene3D::Loader;
 
 int UtcDaliKtxLoaderFailNonexistent(void)
 {
-  CubeData data;
-  DALI_TEST_CHECK(!LoadKtxData("non-existent.ktx", data));
+  EnvironmentMapData environmentMapData;
+  DALI_TEST_CHECK(!LoadKtxData("non-existent.ktx", environmentMapData));
   END_TEST;
 }
 
 int UtcDaliKtxLoaderFailInvalid1(void)
 {
-  CubeData data;
-  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/invalid.svg", data)); // file smaller than KTX header
+  EnvironmentMapData environmentMapData;
+  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/invalid.svg", environmentMapData)); // file smaller than KTX header
   END_TEST;
 }
 
 int UtcDaliKtxLoaderFailInvalid2(void)
 {
-  CubeData data;
-  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/anim.gif", data)); // not a KTX
+  EnvironmentMapData environmentMapData;
+  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/anim.gif", environmentMapData)); // not a KTX
   END_TEST;
 }
 
 int UtcDaliKtxLoaderFailTruncated(void)
 {
-  CubeData data;
-  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/truncated.ktx", data));
+  EnvironmentMapData environmentMapData;
+  DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/truncated.ktx", environmentMapData));
   END_TEST;
 }
 
 int UtcDaliKtxLoaderSuccess(void)
 {
-  CubeData cubeData;
+  EnvironmentMapData environmentMapData;
   auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
-  DALI_TEST_CHECK(LoadKtxData(path, cubeData));
+  DALI_TEST_CHECK(LoadKtxData(path, environmentMapData));
 
-  DALI_TEST_EQUAL(6u, cubeData.data.size());
-  for (auto& face: cubeData.data)
+  DALI_TEST_EQUAL(6u, environmentMapData.mPixelData.size());
+  for (auto& face: environmentMapData.mPixelData)
   {
     uint32_t size = 64;
     for (auto& mipData: face)
@@ -102,27 +102,27 @@ int UtcDaliKtxLoaderFormats(void)
   };
   for (auto i : pathFormats)
   {
-    CubeData cubeData;
-    DALI_TEST_CHECK(LoadKtxData(resPath + i.first + ".ktx", cubeData));
-    DALI_TEST_EQUAL(cubeData.data[0][0].GetPixelFormat(), i.second);
+    EnvironmentMapData environmentMapData;
+    DALI_TEST_CHECK(LoadKtxData(resPath + i.first + ".ktx", environmentMapData));
+    DALI_TEST_EQUAL(environmentMapData.mPixelData[0][0].GetPixelFormat(), i.second);
   }
 
   END_TEST;
 }
 
-int UtcDaliKtxLoaderCubeDataCreateTexture1(void)
+int UtcDaliKtxLoaderEnvironmentMApDataCreateTexture1(void)
 {
   uint32_t pixelBufferSize = 3;
   uint8_t* pixelBuffer = new uint8_t[pixelBufferSize];
 
-  CubeData cubeData;
-  cubeData.data.push_back({});
+  EnvironmentMapData environmentMapData;
+  environmentMapData.mPixelData.push_back({});
 
   auto pixelData = PixelData::New(pixelBuffer, pixelBufferSize, 1, 1, Pixel::Format::RGB888, PixelData::DELETE_ARRAY);
-  cubeData.data[0].push_back(pixelData);
+  environmentMapData.mPixelData[0].push_back(pixelData);
 
   TestApplication app;
-  auto texture = cubeData.CreateTexture();
+  auto texture = environmentMapData.GetTexture();
 
   DALI_TEST_CHECK(texture);
   DALI_TEST_EQUAL(1u, texture.GetWidth());
@@ -131,14 +131,14 @@ int UtcDaliKtxLoaderCubeDataCreateTexture1(void)
   END_TEST;
 }
 
-int UtcDaliKtxLoaderCubeDataCreateTexture2(void)
+int UtcDaliKtxLoaderEnvironmentMApDataCreateTexture2(void)
 {
-  CubeData cubeData;
+  EnvironmentMapData environmentMapData;
   auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
-  DALI_TEST_CHECK(LoadKtxData(path, cubeData));
+  DALI_TEST_CHECK(LoadKtxData(path, environmentMapData));
 
   TestApplication app;
-  auto texture = cubeData.CreateTexture();
+  auto texture = environmentMapData.GetTexture();
 
   DALI_TEST_CHECK(texture);
   DALI_TEST_EQUAL(64u, texture.GetWidth());
@@ -147,14 +147,14 @@ int UtcDaliKtxLoaderCubeDataCreateTexture2(void)
   END_TEST;
 }
 
-int UtcDaliKtxLoaderCubeDataCreateTexture3(void)
+int UtcDaliKtxLoaderEnvironmentMApDataCreateTexture3(void)
 {
-  CubeData cubeData;
+  EnvironmentMapData environmentMapData;
   auto path = TEST_RESOURCE_DIR "/papermill_E_diffuse-64.ktx";
-  DALI_TEST_CHECK(LoadKtxData(path, cubeData));
+  DALI_TEST_CHECK(LoadKtxData(path, environmentMapData));
 
   TestApplication app;
-  auto texture = cubeData.CreateTexture();
+  auto texture = environmentMapData.GetTexture();
 
   DALI_TEST_CHECK(texture);
   DALI_TEST_EQUAL(64u, texture.GetWidth());
index ed3af58..1e74b56 100644 (file)
@@ -802,7 +802,8 @@ int UtcDaliSceneViewSetSkyboxEquirectangular(void)
   application.Render();
 
   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
-  view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE, Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR);
+  view.SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
+  view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE);
 
   gResourceReadyCalled = false;
   DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
@@ -860,7 +861,7 @@ int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void)
   application.Render();
 
   uint32_t childCount = view.GetChildAt(0u).GetChildCount();
-  view.SetSkybox("", Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR);
+  view.SetSkybox("");
   DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION);
 
   view.Unparent();
index 82d8646..d230e99 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.
@@ -19,7 +19,7 @@
 #include <dali-scene3d/internal/common/environment-map-load-task.h>
 
 // INTERNAL INCLUDES
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
+#include <dali-scene3d/public-api/loader/environment-map-loader.h>
 
 
 namespace Dali
@@ -29,9 +29,10 @@ namespace Scene3D
 namespace Internal
 {
 
-EnvironmentMapLoadTask::EnvironmentMapLoadTask(const std::string& environmentMapUrl, CallbackBase* callback)
+EnvironmentMapLoadTask::EnvironmentMapLoadTask(const std::string& environmentMapUrl, Dali::Scene3D::EnvironmentMapType environmentMapType, CallbackBase* callback)
 : AsyncTask(callback),
   mEnvironmentMapUrl(environmentMapUrl),
+  mEnvironmentMapType(environmentMapType),
   mIsReady(true),
   mHasSucceeded(false)
 {
@@ -43,7 +44,8 @@ EnvironmentMapLoadTask::~EnvironmentMapLoadTask()
 
 void EnvironmentMapLoadTask::Process()
 {
-  mHasSucceeded = Scene3D::Loader::LoadCubeMapData(mEnvironmentMapUrl, mEnvironmentMapPixelData);
+  mEnvironmentMapData.SetEnvironmentMapType(mEnvironmentMapType);
+  mHasSucceeded = Scene3D::Loader::LoadEnvironmentMap(mEnvironmentMapUrl, mEnvironmentMapData);
 }
 
 bool EnvironmentMapLoadTask::IsReady()
@@ -56,14 +58,9 @@ bool EnvironmentMapLoadTask::HasSucceeded() const
   return mHasSucceeded;
 }
 
-Dali::Scene3D::Loader::CubeData EnvironmentMapLoadTask::GetEnvironmentMap() const
+Dali::Scene3D::Loader::EnvironmentMapData& EnvironmentMapLoadTask::GetEnvironmentMap()
 {
-  Dali::Scene3D::Loader::CubeData environmentMapPixelData;
-  if(mIsReady && mHasSucceeded && !mEnvironmentMapPixelData.data.empty())
-  {
-    environmentMapPixelData = mEnvironmentMapPixelData;
-  }
-  return environmentMapPixelData;
+  return mEnvironmentMapData;
 }
 
 } // namespace Internal
index 8b1ac7c..d9a936b 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE3D_ENVIRONMENT_MAP_LOAD_TASK_H
 
 /*
- * 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.
@@ -26,6 +26,8 @@
 // INTERNAL INCLUDES
 #include <dali-scene3d/public-api/loader/load-result.h>
 #include <dali-scene3d/public-api/loader/scene-definition.h>
+#include <dali-scene3d/public-api/common/environment-map.h>
+#include <dali-scene3d/public-api/loader/environment-map-data.h>
 
 namespace Dali
 {
@@ -44,7 +46,7 @@ public:
    * @param[in] environmentMapUrl The url of the environment map image file.
    * @param[in] callback The callback that is called when the operation is completed.
    */
-  EnvironmentMapLoadTask(const std::string& environmentMapUrl, CallbackBase* callback);
+  EnvironmentMapLoadTask(const std::string& environmentMapUrl, Dali::Scene3D::EnvironmentMapType environmentMapType, CallbackBase* callback);
 
   /**
    * Destructor.
@@ -70,11 +72,9 @@ public:
 
   /**
    * Retrieves loaded Environment Map
-   * @return CubeData loaded from url.
-   *
-   * TODO: Supports Equirectangular environment map
+   * @return EnvironmentMapData that is loaded from url.
    */
-  Dali::Scene3D::Loader::CubeData GetEnvironmentMap() const;
+  Dali::Scene3D::Loader::EnvironmentMapData& GetEnvironmentMap();
 
 private:
   // Undefined
@@ -84,8 +84,9 @@ private:
   EnvironmentMapLoadTask& operator=(const EnvironmentMapLoadTask& task) = delete;
 
 private:
-  std::string                     mEnvironmentMapUrl;
-  Dali::Scene3D::Loader::CubeData mEnvironmentMapPixelData;
+  std::string                               mEnvironmentMapUrl;
+  Dali::Scene3D::Loader::EnvironmentMapData mEnvironmentMapData;
+  Dali::Scene3D::EnvironmentMapType         mEnvironmentMapType{Dali::Scene3D::EnvironmentMapType::AUTO};
 
   bool mIsReady;
   bool mHasSucceeded;
index bfd9256..c5d97f9 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.
@@ -25,7 +25,6 @@
 // INTERNAL INCLUDES
 #include <dali-scene3d/public-api/loader/animation-definition.h>
 #include <dali-scene3d/public-api/loader/camera-parameters.h>
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
 #include <dali-scene3d/public-api/loader/dli-loader.h>
 #include <dali-scene3d/public-api/loader/gltf2-loader.h>
 #include <dali-scene3d/public-api/loader/light-parameters.h>
index d936271..3345bfc 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.
@@ -35,7 +35,6 @@
 #include <dali-scene3d/public-api/controls/model/model.h>
 #include <dali-scene3d/public-api/loader/animation-definition.h>
 #include <dali-scene3d/public-api/loader/camera-parameters.h>
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
 #include <dali-scene3d/public-api/loader/dli-loader.h>
 #include <dali-scene3d/public-api/loader/gltf2-loader.h>
 #include <dali-scene3d/public-api/loader/light-parameters.h>
@@ -315,7 +314,7 @@ void Model::SetImageBasedLightSource(const std::string& diffuseUrl, const std::s
         Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
         mIblDiffuseLoadTask.Reset();
       }
-      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, MakeCallback(this, &Model::OnIblDiffuseLoadComplete));
+      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &Model::OnIblDiffuseLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblDiffuseLoadTask);
       mIblDiffuseDirty = false;
     }
@@ -327,7 +326,7 @@ void Model::SetImageBasedLightSource(const std::string& diffuseUrl, const std::s
         Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
         mIblSpecularLoadTask.Reset();
       }
-      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, MakeCallback(this, &Model::OnIblSpecularLoadComplete));
+      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &Model::OnIblSpecularLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblSpecularLoadTask);
       mIblSpecularDirty = false;
     }
@@ -728,7 +727,7 @@ void Model::OnModelLoadComplete()
 
 void Model::OnIblDiffuseLoadComplete()
 {
-  mDiffuseTexture = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mDiffuseTexture = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().GetTexture() : Texture();
   mIblDiffuseResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
@@ -739,7 +738,7 @@ void Model::OnIblDiffuseLoadComplete()
 
 void Model::OnIblSpecularLoadComplete()
 {
-  mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().GetTexture() : Texture();
   mIblSpecularResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
index bb44ab7..5c189c2 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.
@@ -39,7 +39,6 @@
 // INTERNAL INCLUDES
 #include <dali-scene3d/internal/controls/model/model-impl.h>
 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
 
 using namespace Dali;
 
@@ -367,7 +366,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
         Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
         mIblDiffuseLoadTask.Reset();
       }
-      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
+      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblDiffuseLoadTask);
       mIblDiffuseDirty = false;
     }
@@ -379,7 +378,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
         Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
         mIblSpecularLoadTask.Reset();
       }
-      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
+      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblSpecularLoadTask);
       mIblSpecularDirty = false;
     }
@@ -428,62 +427,19 @@ bool SceneView::IsUsingFramebuffer() const
   return mUseFrameBuffer;
 }
 
-void SceneView::SetSkybox(const std::string& skyboxUrl, Scene3D::SceneView::SkyboxType skyboxType)
+void SceneView::SetSkybox(const std::string& skyboxUrl)
 {
-  mSkyboxEnvironmentMapType = skyboxType;
-  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
   if(mSkyboxUrl != skyboxUrl)
   {
-    mSkyboxDirty         = true;
-    mSkyboxResourceReady = false;
-    mSkyboxUrl           = skyboxUrl;
+    UpdateSkybox(skyboxUrl, mSkyboxEnvironmentMapType);
   }
+}
 
-  if(mSkyboxUrl.empty())
-  {
-    if(mSkyboxLoadTask)
-    {
-      Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-      mSkyboxLoadTask.Reset();
-    }
-    if(mSkyboxImageLoader)
-    {
-      mSkyboxImageLoader.Cancel(mSkyboxImageId);
-    }
-    mSkyboxDirty         = false;
-    mSkyboxResourceReady = true;
-  }
-  else
+void SceneView::SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
+{
+  if(mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
   {
-    if(isOnScene && mSkyboxDirty)
-    {
-      if(mSkyboxLoadTask)
-      {
-        Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-        mSkyboxLoadTask.Reset();
-      }
-      if(mSkyboxImageLoader)
-      {
-        mSkyboxImageLoader.Cancel(mSkyboxImageId);
-      }
-      if(mSkyboxEnvironmentMapType == Scene3D::SceneView::SkyboxType::CUBEMAP)
-      {
-        mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
-        Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
-      }
-      else
-      {
-        mSkyboxImageLoader = Dali::Toolkit::AsyncImageLoader::New();
-        mSkyboxImageLoader.ImageLoadedSignal().Connect(this, &SceneView::OnSkyboxEquirectangularLoadComplete);
-        mSkyboxImageId = mSkyboxImageLoader.Load(mSkyboxUrl);
-      }
-      mSkyboxDirty = false;
-    }
-  }
-
-  if(IsResourceReady())
-  {
-    Control::SetResourceReady(false);
+    UpdateSkybox(mSkyboxUrl, skyboxEnvironmentMapType);
   }
 }
 
@@ -536,7 +492,7 @@ void SceneView::OnSceneConnection(int depth)
 
   if(!mSkyboxUrl.empty())
   {
-    SetSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
+    UpdateSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
   }
 
   Window window = DevelWindow::Get(Self());
@@ -748,11 +704,47 @@ void SceneView::RotateCamera()
   }
 }
 
-void SceneView::OnSkyboxEquirectangularLoadComplete(uint32_t loadedTaskId, PixelData pixelData)
+void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
 {
-  mSkyboxTexture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
-  mSkyboxTexture.Upload(pixelData, 0, 0, 0, 0, pixelData.GetWidth(), pixelData.GetHeight());
-  OnSkyboxLoadComplete();
+  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+  if(mSkyboxUrl != skyboxUrl || mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
+  {
+    mSkyboxDirty         = true;
+    mSkyboxResourceReady = false;
+    mSkyboxUrl           = skyboxUrl;
+    mSkyboxEnvironmentMapType = skyboxEnvironmentMapType;
+  }
+
+  if(mSkyboxUrl.empty())
+  {
+    if(mSkyboxLoadTask)
+    {
+      Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+      mSkyboxLoadTask.Reset();
+    }
+    mSkyboxDirty         = false;
+    mSkyboxResourceReady = true;
+  }
+  else
+  {
+    if(isOnScene && mSkyboxDirty)
+    {
+      if(mSkyboxLoadTask)
+      {
+        Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+        mSkyboxLoadTask.Reset();
+      }
+
+      mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, mSkyboxEnvironmentMapType, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
+      Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
+      mSkyboxDirty = false;
+    }
+  }
+
+  if(IsResourceReady())
+  {
+    Control::SetResourceReady(false);
+  }
 }
 
 void SceneView::OnSkyboxLoadComplete()
@@ -774,13 +766,11 @@ void SceneView::OnSkyboxLoadComplete()
     Control::SetResourceReady(false);
   }
 
+  mSkyboxTexture = (mSkyboxLoadTask->HasSucceeded()) ? mSkyboxLoadTask->GetEnvironmentMap().GetTexture() : Texture();
   Shader skyboxShader;
-  if(mSkyboxEnvironmentMapType == Scene3D::SceneView::SkyboxType::CUBEMAP)
+  if(mSkyboxEnvironmentMapType == Scene3D::EnvironmentMapType::CUBEMAP)
   {
-    mSkyboxTexture = (mSkyboxLoadTask->HasSucceeded()) ? mSkyboxLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
     skyboxShader   = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
-    Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-    mSkyboxLoadTask.Reset();
   }
   else
   {
@@ -795,11 +785,13 @@ void SceneView::OnSkyboxLoadComplete()
     skyboxRenderer.SetTextures(skyboxTextures);
     skyboxRenderer.SetShader(skyboxShader);
   }
+
+  mSkyboxLoadTask.Reset();
 }
 
 void SceneView::OnIblDiffuseLoadComplete()
 {
-  mDiffuseTexture          = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mDiffuseTexture          = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().GetTexture() : Texture();
   mIblDiffuseResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
@@ -810,7 +802,7 @@ void SceneView::OnIblDiffuseLoadComplete()
 
 void SceneView::OnIblSpecularLoadComplete()
 {
-  mSpecularTexture          = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mSpecularTexture          = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().GetTexture() : Texture();
   mIblSpecularResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
index fc17fa7..e8e1650 100644 (file)
@@ -21,7 +21,6 @@
 // EXTERNAL INCLUDES
 #include <dali-toolkit/internal/visuals/image/image-visual.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include <dali-toolkit/public-api/image-loader/async-image-loader.h>
 #include <dali/public-api/actors/camera-actor.h>
 #include <dali/public-api/actors/layer.h>
 #include <dali/public-api/adaptor-framework/window.h>
@@ -142,7 +141,12 @@ public:
   /**
    * @copydoc SceneView::SetSkybox()
    */
-  void SetSkybox(const std::string& skyboxUrl, Scene3D::SceneView::SkyboxType skyboxType);
+  void SetSkybox(const std::string& skyboxUrl);
+
+  /**
+   * @copydoc SceneView::SetSkyboxEnvironmentMapType()
+   */
+  void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
 
   /**
    * @copydoc SceneView::SetSkyboxIntensity()
@@ -244,9 +248,12 @@ private:
   void RotateCamera();
 
   /**
-   * @brief Asynchronously skybox (Equirectangular) loading finished.
+   * @brief UpdateSkybox with skybox url and skybox environment map type.
+   *
+   * @param[in] skyboxUrl image url for skybox.
+   * @param[in] skyboxEnvironmentMapType The environment type of skybox.
    */
-  void OnSkyboxEquirectangularLoadComplete(uint32_t loadedTaskId, PixelData pixelData);
+  void UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
 
   /**
    * @brief Asynchronously skybox loading finished.
@@ -299,21 +306,19 @@ private:
   std::string                     mSkyboxUrl;
   std::string                     mDiffuseIblUrl;
   std::string                     mSpecularIblUrl;
-  Dali::Toolkit::AsyncImageLoader mSkyboxImageLoader;
-  uint32_t                        mSkyboxImageId{0u};
-
-  Scene3D::SceneView::SkyboxType mSkyboxEnvironmentMapType{Scene3D::SceneView::SkyboxType::CUBEMAP};
-  Dali::Texture                  mSkyboxTexture;
-  Dali::Texture                  mDiffuseTexture;
-  Dali::Texture                  mSpecularTexture;
-  float                          mIblScaleFactor{1.0f};
-  bool                           mUseFrameBuffer{false};
-  bool                           mSkyboxResourceReady{true};
-  bool                           mIblDiffuseResourceReady{true};
-  bool                           mIblSpecularResourceReady{true};
-  bool                           mSkyboxDirty{false};
-  bool                           mIblDiffuseDirty{false};
-  bool                           mIblSpecularDirty{false};
+
+  Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
+  Dali::Texture               mSkyboxTexture;
+  Dali::Texture               mDiffuseTexture;
+  Dali::Texture               mSpecularTexture;
+  float                       mIblScaleFactor{1.0f};
+  bool                        mUseFrameBuffer{false};
+  bool                        mSkyboxResourceReady{true};
+  bool                        mIblDiffuseResourceReady{true};
+  bool                        mIblSpecularResourceReady{true};
+  bool                        mSkyboxDirty{false};
+  bool                        mIblDiffuseDirty{false};
+  bool                        mIblSpecularDirty{false};
 
   // TODO : Light Source
 };
diff --git a/dali-scene3d/public-api/common/environment-map.h b/dali-scene3d/public-api/common/environment-map.h
new file mode 100644 (file)
index 0000000..a07139e
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef DALI_SCENE3D_COMMON_ENVIRONMENT_MAP_H
+#define DALI_SCENE3D_COMMON_ENVIRONMENT_MAP_H
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+namespace Scene3D
+{
+
+/**
+ * @brief The Environment Map types
+ * @SINCE_2_2.11
+ */
+enum class EnvironmentMapType
+{
+  AUTO,           ///< Automatically detects the type of input environment map.
+                  ///  DALi finds the closest aspect ratio of the input texture to guess the environment map type.
+  CUBEMAP,        ///< Environment map in cubemap
+                  ///  DALi supports cross and array type of cube map for the vertical and horizontal direction.
+                  ///  For example, if the aspect ratio of a texture is 4x3, the texture is classified as a horizontal cross type.
+                  ///  On the other hand, if the aspect ratio is 6x1, it can be sorted as a horizontal array.
+  EQUIRECTANGULAR ///< Environment map in equirectangular projection. Usually equirectangular image has 2x1 aspect ratio.
+};
+
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_COMMON_ENVIRONMENT_MAP_H
index 732c1d6..3013720 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.
@@ -127,9 +127,14 @@ bool SceneView::IsUsingFramebuffer() const
   return GetImpl(*this).IsUsingFramebuffer();
 }
 
-void SceneView::SetSkybox(const std::string& skyboxUrl, SkyboxType skyboxType)
+void SceneView::SetSkybox(const std::string& skyboxUrl)
 {
-  GetImpl(*this).SetSkybox(skyboxUrl, skyboxType);
+  GetImpl(*this).SetSkybox(skyboxUrl);
+}
+
+void SceneView::SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
+{
+  GetImpl(*this).SetSkyboxEnvironmentMapType(skyboxEnvironmentMapType);
 }
 
 void SceneView::SetSkyboxIntensity(float intensity)
index e538d29..fdb61e4 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE3D_SCENE_VIEW_H
 
 /*
- * 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.
@@ -20,6 +20,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/common/environment-map.h>
 
 // EXTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/control.h>
@@ -104,16 +105,6 @@ class DALI_SCENE3D_API SceneView : public Dali::Toolkit::Control
 {
 public:
   /**
-   * @brief The skybox types
-   * @SINCE_2_2.6
-   */
-  enum class SkyboxType
-  {
-    CUBEMAP,        ///< Skybox in cubemap
-    EQUIRECTANGULAR ///< Skybox in equirectangular projection
-  };
-
-  /**
    * @brief Create an initialized SceneView.
    *
    * @SINCE_2_1.38
@@ -327,13 +318,23 @@ public:
 
   /**
    * @brief Sets Skybox for this scene.
-   * Skybox texture is asynchronously loaded. When loading is finished, ResourceReady is emitted.
+   * Skybox texture starts to be loaded when SceneView is onScene.
+   * And Skybox texture is asynchronously loaded. When loading is finished, ResourceReady is emitted.
    *
    * @SINCE_2_2.0
    * @param[in] skyboxUrl image url for skybox.
-   * @param[in] skyboxType The environment type of skymap (by default it is cubemap).
+   * @note Default SkyboxEnvironmentMapType is Cube Map. Use SetSkyboxEnvironmentMapType method to set type explicitly.
+   */
+  void SetSkybox(const std::string& skyboxUrl);
+
+  /**
+   * @brief Sets Skybox environment map type for this skybox.
+   * If skybox texture already starts to be loaded, when the type is changed, the load request is canceled and re-starts to load with new type.
+   *
+   * @SINCE_2_2.11
+   * @param[in] skyboxEnvironmentMapType The environment type of skybox (by default it is cubemap).
    */
-  void SetSkybox(const std::string& skyboxUrl, SkyboxType skyboxType = SkyboxType::CUBEMAP);
+  void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
 
   /**
    * @brief Sets Skybox intensity.
index 29a1b33..3fc4638 100644 (file)
@@ -9,9 +9,8 @@ set(scene3d_src_files ${scene3d_src_files}
        ${scene3d_public_api_dir}/loader/blend-shape-details.cpp
        ${scene3d_public_api_dir}/loader/bvh-loader.cpp
        ${scene3d_public_api_dir}/loader/camera-parameters.cpp
-       ${scene3d_public_api_dir}/loader/cube-data.cpp
-       ${scene3d_public_api_dir}/loader/cube-loader.cpp
-       ${scene3d_public_api_dir}/loader/cube-map-loader.cpp
+       ${scene3d_public_api_dir}/loader/environment-map-data.cpp
+       ${scene3d_public_api_dir}/loader/environment-map-loader.cpp
        ${scene3d_public_api_dir}/loader/customization.cpp
        ${scene3d_public_api_dir}/loader/dli-loader.cpp
        ${scene3d_public_api_dir}/loader/environment-definition.cpp
diff --git a/dali-scene3d/public-api/loader/cube-data.cpp b/dali-scene3d/public-api/loader/cube-data.cpp
deleted file mode 100644 (file)
index 2714cc8..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// FILE HEADER
-#include "dali-scene3d/public-api/loader/cube-data.h"
-
-// EXTERNAL INCLUDES
-#include "dali/public-api/rendering/texture.h"
-
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
-{
-Texture CubeData::CreateTexture() const
-{
-  Texture texture = Texture::New(TextureType::TEXTURE_CUBE, data[0][0].GetPixelFormat(), data[0][0].GetWidth(), data[0][0].GetHeight());
-  for(size_t iSide = 0u, iEndSize = data.size(); iSide < iEndSize; ++iSide)
-  {
-    auto& side = data[iSide];
-    for(size_t iMipLevel = 0u, iEndMipLevel = data[0].size(); iMipLevel < iEndMipLevel; ++iMipLevel)
-    {
-      texture.Upload(side[iMipLevel], CubeMapLayer::POSITIVE_X + iSide, iMipLevel, 0u, 0u, side[iMipLevel].GetWidth(), side[iMipLevel].GetHeight());
-    }
-  }
-
-  // If mipmap is not defined explicitly, use GenerateMipmaps.
-  // TODO: Maybe we can use better way to know it already has mipmap or not.
-  if(data.size() > 0u && data[0].size() == 1u)
-  {
-    texture.GenerateMipmaps();
-  }
-
-  return texture;
-}
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
diff --git a/dali-scene3d/public-api/loader/cube-data.h b/dali-scene3d/public-api/loader/cube-data.h
deleted file mode 100644 (file)
index 961e0b2..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#ifndef DALI_SCENE3D_LOADER_CUBE_DATA_H
-#define DALI_SCENE3D_LOADER_CUBE_DATA_H
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include "dali-scene3d/public-api/api.h"
-
-// EXTERNAL INCLUDES
-#include "dali/public-api/common/vector-wrapper.h"
-#include "dali/public-api/images/pixel-data.h"
-#include "dali/public-api/rendering/texture.h"
-
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
-{
-/**
- * @brief Stores the pixel data objects for each face of the cube texture and their mipmaps.
- */
-class DALI_SCENE3D_API CubeData
-{
-public:
-  /**
-   * @brief Create cube texture from image file
-   * @return Texture loaded cube texture.
-   */
-  Texture CreateTexture() const;
-
-public:
-  std::vector<std::vector<PixelData> > data;
-};
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
-
-#endif // DALI_SCENE3D_LOADER_CUBE_DATA_H
diff --git a/dali-scene3d/public-api/loader/cube-loader.cpp b/dali-scene3d/public-api/loader/cube-loader.cpp
deleted file mode 100644 (file)
index 96cafcb..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// FILE HEADER
-#include <dali-scene3d/public-api/loader/cube-loader.h>
-
-// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/image-loading.h>
-#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
-#include <dali/public-api/common/vector-wrapper.h>
-#include <dali/public-api/rendering/texture.h>
-#include <dali/integration-api/debug.h>
-#include <string.h>
-
-namespace Dali
-{
-namespace
-{
-/**
- * @brief cube map face index
- * Cube map layer order is as fallows:
- * POSITIVE_X, NEGATIVE_X, POSITIVE_Y, NEGATIVE_Y, POSITIVE_Z, NEGATIVE_Z. @see CubeMapLayer
- * The indices are for 4 kind of environment cube map. Cross_horizontal, Array_horizontal, Cross_vertical, and Array_vertical.
- */
-const uint32_t CUBEMAP_INDEX_X[4][6] = {{2, 0, 1, 1, 1, 3}, {0, 1, 2, 3, 4, 5}, {1, 1, 1, 1, 0, 2}, {0, 0, 0, 0, 0, 0}};
-const uint32_t CUBEMAP_INDEX_Y[4][6] = {{1, 1, 0, 2, 1, 1}, {0, 0, 0, 0, 0, 0}, {1, 3, 0, 2, 1, 1}, {0, 1, 2, 3, 4, 5}};
-
-enum CubeType
-{
-  CROSS_HORIZONTAL = 0, // Cross horizontal style cube map
-  ARRAY_HORIZONTAL,     // array horizontal style cube map
-  CROSS_VERTICAL,       // Cross vertical style cube map
-  ARRAY_VERTICAL,       // array vertical style cube map
-  NONE
-};
-
-uint8_t* GetCroppedBuffer(uint8_t* sourceBuffer, uint32_t bytesPerPixel, uint32_t width, uint32_t height, uint32_t xOffset, uint32_t yOffset, uint32_t xFaceSize, uint32_t yFaceSize)
-{
-  uint32_t byteSize   = bytesPerPixel * xFaceSize * yFaceSize;
-  uint8_t* destBuffer = reinterpret_cast<uint8_t*>(malloc(byteSize + 4u));
-
-  int32_t srcStride  = width * bytesPerPixel;
-  int32_t destStride = xFaceSize * bytesPerPixel;
-  int32_t srcOffset  = xOffset * bytesPerPixel + yOffset * srcStride;
-  int32_t destOffset = 0;
-  for(uint16_t row = yOffset; row < yOffset + yFaceSize; ++row)
-  {
-    memcpy(destBuffer + destOffset, sourceBuffer + srcOffset, destStride);
-    srcOffset += srcStride;
-    destOffset += destStride;
-  }
-
-  return destBuffer;
-}
-
-PixelData GetCubeFace(Devel::PixelBuffer pixelBuffer, uint32_t faceIndex, CubeType cubeType, uint32_t faceSize)
-{
-  PixelData pixelData;
-  if(cubeType != NONE)
-  {
-    uint8_t* imageBuffer   = pixelBuffer.GetBuffer();
-    uint32_t bytesPerPixel = Pixel::GetBytesPerPixel(pixelBuffer.GetPixelFormat());
-    uint32_t imageWidth    = pixelBuffer.GetWidth();
-    uint32_t imageHeight   = pixelBuffer.GetHeight();
-
-    uint32_t xOffset = CUBEMAP_INDEX_X[cubeType][faceIndex] * faceSize;
-    uint32_t yOffset = CUBEMAP_INDEX_Y[cubeType][faceIndex] * faceSize;
-
-    uint8_t* tempImageBuffer = GetCroppedBuffer(imageBuffer, bytesPerPixel, imageWidth, imageHeight, xOffset, yOffset, faceSize, faceSize);
-    pixelData                = PixelData::New(tempImageBuffer, faceSize * faceSize * bytesPerPixel, faceSize, faceSize, pixelBuffer.GetPixelFormat(), PixelData::FREE);
-  }
-  return pixelData;
-}
-} // namespace
-
-namespace Scene3D
-{
-namespace Loader
-{
-bool LoadCubeData(const std::string& path, CubeData& cubedata)
-{
-  // Diffuse Cube Map
-  if(path.empty())
-  {
-    return false;
-  }
-
-  Devel::PixelBuffer pixelBuffer = LoadImageFromFile(path);
-  if(pixelBuffer)
-  {
-    uint32_t imageWidth  = pixelBuffer.GetWidth();
-    uint32_t imageHeight = pixelBuffer.GetHeight();
-
-    uint32_t faceSize = 0;
-    CubeType cubeType = NONE;
-    if(imageWidth / 4 == imageHeight / 3)
-    {
-      cubeType = CROSS_HORIZONTAL;
-      faceSize = imageWidth / 4;
-    }
-    else if(imageWidth / 6 == imageHeight)
-    {
-      cubeType = ARRAY_HORIZONTAL;
-      faceSize = imageHeight;
-    }
-    else if(imageWidth / 3 == imageHeight / 4)
-    {
-      cubeType = CROSS_VERTICAL;
-      faceSize = imageHeight / 4;
-    }
-    else if(imageWidth == imageHeight / 6)
-    {
-      cubeType = ARRAY_VERTICAL;
-      faceSize = imageWidth;
-    }
-    else
-    {
-      DALI_LOG_ERROR("The image is not a cube map\n");
-      return false;
-    }
-
-    cubedata.data.resize(6);
-    for(uint32_t i = 0; i < 6; ++i)
-    {
-      cubedata.data[i].resize(1);
-    }
-    for(uint32_t i = 0; i < 6; ++i)
-    {
-      cubedata.data[i][0] = GetCubeFace(pixelBuffer, i, cubeType, faceSize);
-    }
-
-    return true;
-  }
-  return false;
-}
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
diff --git a/dali-scene3d/public-api/loader/cube-map-loader.cpp b/dali-scene3d/public-api/loader/cube-map-loader.cpp
deleted file mode 100644 (file)
index f3a5aa0..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// FILE HEADER
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
-
-// INTERNAL INCLUDES
-#include <dali-scene3d/public-api/loader/cube-loader.h>
-#include <dali-scene3d/public-api/loader/ktx-loader.h>
-
-// EXTERNAL INCLUDES
-#include <dali/integration-api/debug.h>
-#include <filesystem>
-
-namespace Dali
-{
-namespace
-{
-const std::string_view KTX_EXTENSION = ".ktx";
-}
-
-namespace Scene3D
-{
-namespace Loader
-{
-bool LoadCubeMapData(const std::string& cubeMapUrl, CubeData& cubedata)
-{
-  std::filesystem::path modelPath(cubeMapUrl);
-  std::string           extension = modelPath.extension();
-  std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
-
-  return (extension == KTX_EXTENSION) ? Dali::Scene3D::Loader::LoadKtxData(cubeMapUrl, cubedata) : Dali::Scene3D::Loader::LoadCubeData(cubeMapUrl, cubedata);
-}
-
-Texture LoadCubeMap(const std::string& cubeMapUrl)
-{
-  Texture                         cubeTexture;
-  Dali::Scene3D::Loader::CubeData cubeData;
-  if(Dali::Scene3D::Loader::LoadCubeMapData(cubeMapUrl, cubeData))
-  {
-    cubeTexture = cubeData.CreateTexture();
-  }
-  else
-  {
-    DALI_LOG_ERROR("Fail to load cube map, %s\n", cubeMapUrl.c_str());
-  }
-
-  return cubeTexture;
-}
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
diff --git a/dali-scene3d/public-api/loader/cube-map-loader.h b/dali-scene3d/public-api/loader/cube-map-loader.h
deleted file mode 100644 (file)
index 0ead0a5..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef DALI_SCENE3D_LOADER_CUBE_MAP_LOADER_H
-#define DALI_SCENE3D_LOADER_CUBE_MAP_LOADER_H
-/*
- * Copyright (c) 2022 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali-scene3d/public-api/api.h>
-#include <dali-scene3d/public-api/loader/cube-data.h>
-
-namespace Dali
-{
-namespace Scene3D
-{
-namespace Loader
-{
-/**
- * @brief Loads cube map data from a cube map file.
- *
- * @param[in] cubeMapUrl The cube map file url.
- * @param[out] cubedata The data structure with all pixel data objects.
- * @return bool True if the loading is succeded.
- */
-bool LoadCubeMapData(const std::string& cubeMapUrl, CubeData& cubedata);
-
-/**
- * @brief Loads cube map data from a cube map file and return texture.
- *
- * @param[in] cubeMapUrl The cube map file path.
- * @return Texture the loaded cube map texture.
- */
-Texture LoadCubeMap(const std::string& cubeMapUrl);
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
-
-#endif // DALI_SCENE3D_LOADER_CUBE_MAP_LOADER_H
index 0c76617..deafbc2 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.
@@ -20,7 +20,7 @@
 #include <dali/devel-api/adaptor-framework/image-loading.h>
 
 // INTERNAL INCLUDES
-#include "dali-scene3d/public-api/loader/cube-map-loader.h"
+#include "dali-scene3d/public-api/loader/environment-map-loader.h"
 #include "dali-scene3d/public-api/loader/environment-definition.h"
 #include "dali-scene3d/public-api/loader/utils.h"
 
@@ -50,16 +50,16 @@ EnvironmentDefinition::RawData
 EnvironmentDefinition::LoadRaw(const std::string& environmentsPath) const
 {
   RawData raw;
-  auto    loadFn = [&environmentsPath](const std::string& path, CubeData& cd) {
+  auto    loadFn = [&environmentsPath](const std::string& path, EnvironmentMapData& environmentMapData) {
     if(path.empty())
     {
-      cd.data.resize(6);
-      for(auto& face : cd.data)
+      environmentMapData.mPixelData.resize(6);
+      for(auto& face : environmentMapData.mPixelData)
       {
         face.push_back(PixelData::New(new uint8_t[3]{0xff, 0xff, 0xff}, 3, 1, 1, Pixel::RGB888, PixelData::DELETE_ARRAY));
       }
     }
-    else if(!LoadCubeMapData(environmentsPath + path, cd)) // TODO: supporting EQUIRECTANGULAR
+    else if(!LoadEnvironmentMap(environmentsPath + path, environmentMapData))
     {
       ExceptionFlinger(ASSERT_LOCATION) << "Failed to load cubemap texture from '" << path << "'.";
     }
@@ -84,15 +84,15 @@ EnvironmentDefinition::Textures EnvironmentDefinition::Load(RawData&& raw) const
   Textures textures;
 
   // This texture should have 6 faces and only one mipmap
-  if(!raw.mDiffuse.data.empty())
+  if(!raw.mDiffuse.mPixelData.empty())
   {
-    textures.mDiffuse = raw.mDiffuse.CreateTexture();
+    textures.mDiffuse = raw.mDiffuse.GetTexture();
   }
 
   // This texture should have 6 faces and 6 mipmaps
-  if(!raw.mSpecular.data.empty())
+  if(!raw.mSpecular.mPixelData.empty())
   {
-    textures.mSpecular = raw.mSpecular.CreateTexture();
+    textures.mSpecular = raw.mSpecular.GetTexture();
   }
 
   if(raw.mBrdf)
index a6f1946..8f1525d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
 #define DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
 /*
- * 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.
 
 // INTERNAL INCLUDES
 #include "dali-scene3d/public-api/api.h"
-#include "dali-scene3d/public-api/loader/cube-data.h"
+#include "dali-scene3d/public-api/loader/environment-map-data.h"
 
 // EXTERNAL INCLUDES
+#include <memory>
 #include "dali/public-api/math/quaternion.h"
 #include "dali/public-api/rendering/texture.h"
-#include <memory>
 
 namespace Dali
 {
@@ -52,9 +52,9 @@ struct DALI_SCENE3D_API EnvironmentDefinition
 
   struct RawData
   {
-    CubeData  mDiffuse;
-    CubeData  mSpecular;
-    PixelData mBrdf;
+    EnvironmentMapData mDiffuse;
+    EnvironmentMapData mSpecular;
+    PixelData          mBrdf;
   };
 
   using EnvironmentData = std::pair<EnvironmentDefinition, Textures>;
@@ -62,10 +62,10 @@ struct DALI_SCENE3D_API EnvironmentDefinition
 
   EnvironmentDefinition() = default;
 
-  EnvironmentDefinition(const EnvironmentDefinition&) = delete;
+  EnvironmentDefinition(const EnvironmentDefinition&)            = delete;
   EnvironmentDefinition& operator=(const EnvironmentDefinition&) = delete;
 
-  EnvironmentDefinition(EnvironmentDefinition&&) = default;
+  EnvironmentDefinition(EnvironmentDefinition&&)            = default;
   EnvironmentDefinition& operator=(EnvironmentDefinition&&) = default;
 
   /**
@@ -101,4 +101,4 @@ public: // DATA
 } // namespace Scene3D
 } // namespace Dali
 
-#endif //DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
+#endif // DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
diff --git a/dali-scene3d/public-api/loader/environment-map-data.cpp b/dali-scene3d/public-api/loader/environment-map-data.cpp
new file mode 100644 (file)
index 0000000..fdbd159
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// FILE HEADER
+#include <dali-scene3d/public-api/loader/environment-map-data.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/rendering/texture.h>
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+Texture EnvironmentMapData::GetTexture()
+{
+  if(mEnvironmentMapTexture)
+  {
+    return mEnvironmentMapTexture;
+  }
+
+  if(!mPixelData.empty())
+  {
+    if(mEnvironmentMapType == Scene3D::EnvironmentMapType::CUBEMAP)
+    {
+      mEnvironmentMapTexture = Texture::New(TextureType::TEXTURE_CUBE, mPixelData[0][0].GetPixelFormat(), mPixelData[0][0].GetWidth(), mPixelData[0][0].GetHeight());
+      for(size_t iSide = 0u, iEndSize = mPixelData.size(); iSide < iEndSize; ++iSide)
+      {
+        auto& side = mPixelData[iSide];
+        for(size_t iMipLevel = 0u, iEndMipLevel = mPixelData[0].size(); iMipLevel < iEndMipLevel; ++iMipLevel)
+        {
+          mEnvironmentMapTexture.Upload(side[iMipLevel], CubeMapLayer::POSITIVE_X + iSide, iMipLevel, 0u, 0u, side[iMipLevel].GetWidth(), side[iMipLevel].GetHeight());
+        }
+      }
+
+      // If mipmap is not defined explicitly, use GenerateMipmaps.
+      // TODO: Maybe we can use better way to know it already has mipmap or not.
+      if(mPixelData.size() > 0u && mPixelData[0].size() == 1u)
+      {
+        mEnvironmentMapTexture.GenerateMipmaps();
+      }
+    }
+    else
+    {
+      mEnvironmentMapTexture = Texture::New(TextureType::TEXTURE_2D, mPixelData[0][0].GetPixelFormat(), mPixelData[0][0].GetWidth(), mPixelData[0][0].GetHeight());
+      mEnvironmentMapTexture.Upload(mPixelData[0][0], 0, 0, 0, 0, mPixelData[0][0].GetWidth(), mPixelData[0][0].GetHeight());
+    }
+  }
+  return mEnvironmentMapTexture;
+}
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
diff --git a/dali-scene3d/public-api/loader/environment-map-data.h b/dali-scene3d/public-api/loader/environment-map-data.h
new file mode 100644 (file)
index 0000000..7f3ee8c
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_DATA_H
+#define DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_DATA_H
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/public-api/api.h>
+#include <dali-scene3d/public-api/common/environment-map.h>
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/rendering/texture.h>
+#include <dali/public-api/rendering/shader.h>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+/**
+ * @brief Stores the pixel data objects for environment map texture.
+ * EnvironmentMapData supports cube map that contains textures for 6 faces, or
+ * an equirectangular image.
+ */
+class DALI_SCENE3D_API EnvironmentMapData
+{
+public:
+  /**
+   * @brief Retrieves environment map texture from image file
+   * @return texture for loaded environment map.
+   */
+  Texture GetTexture();
+
+  /**
+   * @brief Sets environment map type
+   * @param[in] environmentMapType environment map type
+   */
+  void SetEnvironmentMapType(Dali::Scene3D::EnvironmentMapType environmentMapType)
+  {
+    if(mEnvironmentMapType != environmentMapType)
+    {
+      mEnvironmentMapTexture.Reset();
+      mEnvironmentMapType = environmentMapType;
+    }
+  }
+
+  /**
+   * @brief Retrieves environment map type.
+   * @return environment map type
+   */
+  Dali::Scene3D::EnvironmentMapType GetEnvironmentMapType() const
+  {
+    return mEnvironmentMapType;
+  }
+
+public:
+  std::vector<std::vector<PixelData> > mPixelData;
+
+private:
+  Dali::Texture                     mEnvironmentMapTexture;
+  Dali::Shader                      mEnvironmentMapShader;
+  Dali::Scene3D::EnvironmentMapType mEnvironmentMapType{Dali::Scene3D::EnvironmentMapType::AUTO};
+};
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_DATA_H
diff --git a/dali-scene3d/public-api/loader/environment-map-loader.cpp b/dali-scene3d/public-api/loader/environment-map-loader.cpp
new file mode 100644 (file)
index 0000000..175c19a
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// FILE HEADER
+#include <dali-scene3d/public-api/loader/environment-map-loader.h>
+
+// INTERNAL INCLUDES
+#include <dali-scene3d/public-api/loader/ktx-loader.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+#include <string.h>
+#include <filesystem>
+
+namespace Dali
+{
+namespace
+{
+const std::string_view KTX_EXTENSION = ".ktx";
+
+static constexpr uint32_t NUMBER_OF_ENVIRONMENT_MAP_TYPE = 5;
+static constexpr uint32_t NUMBER_OF_CUBE_MAP_TYPE        = 4;
+
+/**
+ * @brief cube map face index
+ * Cube map layer order is as fallows:
+ * POSITIVE_X, NEGATIVE_X, POSITIVE_Y, NEGATIVE_Y, POSITIVE_Z, NEGATIVE_Z. @see CubeMapLayer
+ * The indices are for 4 kind of environment cube map. Cross_horizontal, Array_horizontal, Cross_vertical, and Array_vertical.
+ */
+static constexpr uint32_t CUBEMAP_INDEX_X[NUMBER_OF_CUBE_MAP_TYPE][6] = {{2, 0, 1, 1, 1, 3}, {0, 1, 2, 3, 4, 5}, {1, 1, 1, 1, 0, 2}, {0, 0, 0, 0, 0, 0}};
+static constexpr uint32_t CUBEMAP_INDEX_Y[NUMBER_OF_CUBE_MAP_TYPE][6] = {{1, 1, 0, 2, 1, 1}, {0, 0, 0, 0, 0, 0}, {1, 3, 0, 2, 1, 1}, {0, 1, 2, 3, 4, 5}};
+
+static constexpr Vector2 NUMBER_OF_CUBE_FACE[NUMBER_OF_CUBE_MAP_TYPE] =
+{
+  Vector2(4, 3),
+  Vector2(6, 1),
+  Vector2(3, 4),
+  Vector2(1, 6)
+};
+
+static constexpr float expectedAspectRatios[NUMBER_OF_ENVIRONMENT_MAP_TYPE] =
+{
+  4.0f / 3.0f,
+  6.0f / 1.0f,
+  3.0f / 4.0f,
+  1.0f / 6.0f,
+  2.0f / 1.0f
+};
+
+enum CubeType
+{
+  CROSS_HORIZONTAL = 0, // Cross horizontal style cube map
+  ARRAY_HORIZONTAL,     // array horizontal style cube map
+  CROSS_VERTICAL,       // Cross vertical style cube map
+  ARRAY_VERTICAL,       // array vertical style cube map
+  NONE
+};
+
+uint8_t* GetCroppedBuffer(uint8_t* sourceBuffer, uint32_t bytesPerPixel, uint32_t width, uint32_t height, uint32_t xOffset, uint32_t yOffset, uint32_t xFaceSize, uint32_t yFaceSize)
+{
+  uint32_t byteSize   = bytesPerPixel * xFaceSize * yFaceSize;
+  uint8_t* destBuffer = reinterpret_cast<uint8_t*>(malloc(byteSize + 4u));
+
+  int32_t srcStride  = width * bytesPerPixel;
+  int32_t destStride = xFaceSize * bytesPerPixel;
+  int32_t srcOffset  = xOffset * bytesPerPixel + yOffset * srcStride;
+  int32_t destOffset = 0;
+  for(uint16_t row = yOffset; row < yOffset + yFaceSize; ++row)
+  {
+    memcpy(destBuffer + destOffset, sourceBuffer + srcOffset, destStride);
+    srcOffset += srcStride;
+    destOffset += destStride;
+  }
+
+  return destBuffer;
+}
+
+PixelData GetCubeFace(Devel::PixelBuffer pixelBuffer, uint32_t faceIndex, CubeType cubeType, float faceWidth, float faceHeight)
+{
+  PixelData pixelData;
+  if(cubeType != NONE)
+  {
+    uint8_t* imageBuffer   = pixelBuffer.GetBuffer();
+    uint32_t bytesPerPixel = Pixel::GetBytesPerPixel(pixelBuffer.GetPixelFormat());
+    uint32_t imageWidth    = pixelBuffer.GetWidth();
+    uint32_t imageHeight   = pixelBuffer.GetHeight();
+
+    uint32_t xOffset = CUBEMAP_INDEX_X[cubeType][faceIndex] * static_cast<uint32_t>(faceWidth);
+    uint32_t yOffset = CUBEMAP_INDEX_Y[cubeType][faceIndex] * static_cast<uint32_t>(faceHeight);
+
+    uint32_t finalFaceWidth  = (xOffset + static_cast<uint32_t>(faceWidth) < imageWidth) ? static_cast<uint32_t>(faceWidth) : imageWidth - xOffset;
+    uint32_t finalFaceHeight = (yOffset + static_cast<uint32_t>(faceHeight) < imageHeight) ? static_cast<uint32_t>(faceHeight) : imageHeight - yOffset;
+    uint8_t* tempImageBuffer = GetCroppedBuffer(imageBuffer, bytesPerPixel, imageWidth, imageHeight, xOffset, yOffset, finalFaceWidth, finalFaceHeight);
+    pixelData                = PixelData::New(tempImageBuffer, finalFaceWidth * finalFaceHeight * bytesPerPixel, finalFaceWidth, finalFaceHeight, pixelBuffer.GetPixelFormat(), PixelData::FREE);
+  }
+  return pixelData;
+}
+
+/**
+ * @brief Loads environment map data texture from an image url.
+ *
+ * @param[in] environmentMapUrl The environment map file url.
+ * @param[out] environmentMapData The data structure with all pixel data objects.
+ * @return bool True if the loading is succeded.
+ */
+bool LoadEnvironmentMapData(const std::string& environmentMapUrl, Scene3D::Loader::EnvironmentMapData& environmentMapData)
+{
+  // Diffuse Environment Map
+  if(environmentMapUrl.empty())
+  {
+    return false;
+  }
+
+  Devel::PixelBuffer pixelBuffer = LoadImageFromFile(environmentMapUrl);
+  if(pixelBuffer)
+  {
+    CubeType cubeType    = NONE;
+    uint32_t imageWidth  = pixelBuffer.GetWidth();
+    uint32_t imageHeight = pixelBuffer.GetHeight();
+    /**
+     * If the environment map type is not EQUIRECTANGULAR,
+     * The type should be defined internally.
+     * DALi checkes aspect ratio of input image and find the closest type.
+     * If the environment map type is CUBEMAP, DALi determines which of the following styles is closest:
+     * cross horizontal, cross vertical, array horizontal, and array vertical.
+     * When the environment map type is AUTO, it finds the closest type, including the Equirectangular type.
+     */
+    if(environmentMapData.GetEnvironmentMapType() != Scene3D::EnvironmentMapType::EQUIRECTANGULAR)
+    {
+      float aspectRatio = (float)imageWidth / (float)imageHeight;
+
+      float    minDistance = FLT_MAX;
+      uint32_t typeCount   = (environmentMapData.GetEnvironmentMapType() == Scene3D::EnvironmentMapType::CUBEMAP) ? NUMBER_OF_CUBE_MAP_TYPE : NUMBER_OF_ENVIRONMENT_MAP_TYPE;
+      for(uint32_t i = 0; i < typeCount; ++i)
+      {
+        float distance = fabs(aspectRatio - expectedAspectRatios[i]);
+        if(distance < minDistance)
+        {
+          minDistance = distance;
+          cubeType    = static_cast<CubeType>(i);
+        }
+      }
+    }
+
+    if(cubeType != NONE)
+    {
+      float faceWidth = imageWidth, faceHeight = imageHeight;
+      faceWidth /= NUMBER_OF_CUBE_FACE[static_cast<uint32_t>(cubeType)].x;
+      faceHeight /= NUMBER_OF_CUBE_FACE[static_cast<uint32_t>(cubeType)].y;
+      environmentMapData.mPixelData.resize(6);
+      for(uint32_t i = 0; i < 6; ++i)
+      {
+        environmentMapData.mPixelData[i].resize(1);
+      }
+      for(uint32_t i = 0; i < 6; ++i)
+      {
+        environmentMapData.mPixelData[i][0] = GetCubeFace(pixelBuffer, i, cubeType, faceWidth, faceHeight);
+      }
+      environmentMapData.SetEnvironmentMapType(Scene3D::EnvironmentMapType::CUBEMAP);
+    }
+    else
+    {
+      environmentMapData.mPixelData.resize(1);
+      environmentMapData.mPixelData[0].resize(1);
+      environmentMapData.mPixelData[0][0] = Devel::PixelBuffer::Convert(pixelBuffer);
+      environmentMapData.SetEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR);
+    }
+    return true;
+  }
+  return false;
+}
+} // namespace
+
+namespace Scene3D
+{
+namespace Loader
+{
+
+bool LoadEnvironmentMap(const std::string& environmentMapUrl, EnvironmentMapData& environmentMapData)
+{
+  std::filesystem::path modelPath(environmentMapUrl);
+  std::string           extension = modelPath.extension();
+  std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
+
+  return (extension == KTX_EXTENSION) ? Dali::Scene3D::Loader::LoadKtxData(environmentMapUrl, environmentMapData) : LoadEnvironmentMapData(environmentMapUrl, environmentMapData);
+}
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
@@ -1,7 +1,7 @@
-#ifndef DALI_SCENE3D_LOADER_CUBE_LOADER_H
-#define DALI_SCENE3D_LOADER_CUBE_LOADER_H
+#ifndef DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_LOADER_H
+#define DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_LOADER_H
 /*
- * 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.
@@ -19,7 +19,8 @@
 
 // INTERNAL INCLUDES
 #include <dali-scene3d/public-api/api.h>
-#include <dali-scene3d/public-api/loader/cube-data.h>
+#include <dali-scene3d/public-api/loader/environment-map-data.h>
+#include <dali-scene3d/public-api/common/environment-map.h>
 
 namespace Dali
 {
@@ -27,17 +28,18 @@ namespace Scene3D
 {
 namespace Loader
 {
+
 /**
- * @brief Loads cube map data texture from a cube style image file.
+ * @brief Loads environment map data from a environment map file.
  *
- * @param[in] path The file path.
- * @param[out] cubedata The data structure with all pixel data objects.
+ * @param[in] environmentMapUrl The environment map file url.
+ * @param[out] environmentMapData The data structure with all pixel data objects.
  * @return bool True if the loading is succeded.
  */
-bool LoadCubeData(const std::string& path, CubeData& cubedata);
+bool DALI_SCENE3D_API LoadEnvironmentMap(const std::string& environmentMapUrl, EnvironmentMapData& environmentMapData);
 
 } // namespace Loader
 } // namespace Scene3D
 } // namespace Dali
 
-#endif // DALI_SCENE3D_LOADER_CUBE_LOADER_H
+#endif // DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_LOADER_H
index c2e7159..2b52734 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.
@@ -185,7 +185,7 @@ bool ConvertPixelFormat(const uint32_t ktxPixelFormat, Pixel::Format& format)
   return true;
 }
 
-bool LoadKtxData(const std::string& path, CubeData& cubedata)
+bool LoadKtxData(const std::string& path, EnvironmentMapData& environmentMapData)
 {
   std::fstream fp(path, std::ios::in | std::ios::binary);
   if(fp.is_open() == false)
@@ -215,10 +215,10 @@ bool LoadKtxData(const std::string& path, CubeData& cubedata)
   header.pixelDepth            = std::max(header.pixelDepth, 1u);
   header.pixelHeight           = std::max(header.pixelHeight, 1u);
 
-  cubedata.data.resize(header.numberOfFaces);
+  environmentMapData.mPixelData.resize(header.numberOfFaces);
   for(uint32_t face = 0u; face < header.numberOfFaces; ++face)
   {
-    cubedata.data[face].resize(header.numberOfMipmapLevels);
+    environmentMapData.mPixelData[face].resize(header.numberOfMipmapLevels);
   }
 
   Pixel::Format daliformat = Pixel::RGB888;
@@ -247,13 +247,14 @@ bool LoadKtxData(const std::string& path, CubeData& cubedata)
         {
           return false;
         }
-        cubedata.data[face][mipmapLevel] = PixelData::New(img.release(), byteSize, header.pixelWidth, header.pixelHeight, daliformat, PixelData::DELETE_ARRAY);
+        environmentMapData.mPixelData[face][mipmapLevel] = PixelData::New(img.release(), byteSize, header.pixelWidth, header.pixelHeight, daliformat, PixelData::DELETE_ARRAY);
       }
     }
 
     header.pixelHeight /= 2u;
     header.pixelWidth /= 2u;
   }
+  environmentMapData.SetEnvironmentMapType(Scene3D::EnvironmentMapType::CUBEMAP);
 
   return true;
 }
index 63d27a6..fcb3b7d 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef DALI_SCENE3D_LOADER_KTX_LOADER_H
 #define DALI_SCENE3D_LOADER_KTX_LOADER_H
 /*
- * 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.
@@ -19,7 +19,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-scene3d/public-api/api.h>
-#include <dali-scene3d/public-api/loader/cube-data.h>
+#include <dali-scene3d/public-api/loader/environment-map-data.h>
 
 namespace Dali
 {
@@ -31,10 +31,10 @@ namespace Loader
  * @brief Loads cube map data texture from a ktx file.
  *
  * @param[in] path The file path.
- * @param[out] cubedata The data structure with all pixel data objects.
+ * @param[out] environmentMapData The data structure with all pixel data objects.
  * @return bool True if the loading is succeded.
  */
-bool LoadKtxData(const std::string& path, CubeData& cubedata);
+bool LoadKtxData(const std::string& path, EnvironmentMapData& environmentMapData);
 
 } // namespace Loader
 } // namespace Scene3D