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
+++ /dev/null
-/*
- * 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;
-}
+++ /dev/null
-/*
- * 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;
-}
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);
}
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;
}
}
- 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;
--- /dev/null
+/*
+ * 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;
+}
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)
};
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());
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());
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());
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);
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();
/*
- * 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.
#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
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)
{
void EnvironmentMapLoadTask::Process()
{
- mHasSucceeded = Scene3D::Loader::LoadCubeMapData(mEnvironmentMapUrl, mEnvironmentMapPixelData);
+ mEnvironmentMapData.SetEnvironmentMapType(mEnvironmentMapType);
+ mHasSucceeded = Scene3D::Loader::LoadEnvironmentMap(mEnvironmentMapUrl, mEnvironmentMapData);
}
bool EnvironmentMapLoadTask::IsReady()
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
#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.
// 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
{
* @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.
/**
* 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
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;
/*
- * 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/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>
/*
- * 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.
#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>
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;
}
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;
}
void Model::OnIblDiffuseLoadComplete()
{
- mDiffuseTexture = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+ mDiffuseTexture = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().GetTexture() : Texture();
mIblDiffuseResourceReady = true;
if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
{
void Model::OnIblSpecularLoadComplete()
{
- mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+ mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().GetTexture() : Texture();
mIblSpecularResourceReady = true;
if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
{
/*
- * 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/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;
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;
}
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;
}
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);
}
}
if(!mSkyboxUrl.empty())
{
- SetSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
+ UpdateSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
}
Window window = DevelWindow::Get(Self());
}
}
-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()
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
{
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)
{
void SceneView::OnIblSpecularLoadComplete()
{
- mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+ mSpecularTexture = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().GetTexture() : Texture();
mIblSpecularResourceReady = true;
if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
{
// 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>
/**
* @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()
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.
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
};
--- /dev/null
+#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
/*
- * 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.
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)
#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.
// 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>
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.
*
/**
* @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.
${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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-#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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-#ifndef DALI_SCENE3D_LOADER_CUBE_LOADER_H
-#define DALI_SCENE3D_LOADER_CUBE_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 texture from a cube style image file.
- *
- * @param[in] path The file path.
- * @param[out] cubedata The data structure with all pixel data objects.
- * @return bool True if the loading is succeded.
- */
-bool LoadCubeData(const std::string& path, CubeData& cubedata);
-
-} // namespace Loader
-} // namespace Scene3D
-} // namespace Dali
-
-#endif // DALI_SCENE3D_LOADER_CUBE_LOADER_H
+++ /dev/null
-/*
- * 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
+++ /dev/null
-#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
/*
- * 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.
#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"
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 << "'.";
}
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)
#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
{
struct RawData
{
- CubeData mDiffuse;
- CubeData mSpecular;
- PixelData mBrdf;
+ EnvironmentMapData mDiffuse;
+ EnvironmentMapData mSpecular;
+ PixelData mBrdf;
};
using EnvironmentData = std::pair<EnvironmentDefinition, Textures>;
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;
/**
} // namespace Scene3D
} // namespace Dali
-#endif //DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
+#endif // DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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
--- /dev/null
+/*
+ * 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
--- /dev/null
+#ifndef DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_LOADER_H
+#define DALI_SCENE3D_LOADER_ENVIRONMENT_MAP_LOADER_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/loader/environment-map-data.h>
+#include <dali-scene3d/public-api/common/environment-map.h>
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace Loader
+{
+
+/**
+ * @brief Loads environment map data from a environment map file.
+ *
+ * @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 DALI_SCENE3D_API LoadEnvironmentMap(const std::string& environmentMapUrl, EnvironmentMapData& environmentMapData);
+
+} // namespace Loader
+} // namespace Scene3D
+} // namespace Dali
+
+#endif // 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.
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)
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;
{
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;
}
#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.
// 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
{
* @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