utc-Dali-AnimationDefinition.cpp
utc-Dali-AnimatedProperty.cpp
utc-Dali-CameraParameters.cpp
+ utc-Dali-CubeLoader.cpp
+ utc-Dali-CubeMapLoader.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-scene-loader/public-api/cube-loader.h"
+#include <dali-test-suite-utils.h>
+#include <string_view>
+
+#include <fstream>
+
+using namespace Dali;
+using namespace Dali::SceneLoader;
+
+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-scene-loader/public-api/cube-map-loader.h"
+#include <dali-test-suite-utils.h>
+#include <string_view>
+
+#include <fstream>
+
+using namespace Dali;
+using namespace Dali::SceneLoader;
+
+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;
+}
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * 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.
int UtcDaliKtxLoaderFailNonexistent(void)
{
CubeData data;
- DALI_TEST_CHECK(!LoadCubeMapData("non-existent.ktx", data));
+ DALI_TEST_CHECK(!LoadKtxData("non-existent.ktx", data));
END_TEST;
}
int UtcDaliKtxLoaderFailInvalid1(void)
{
CubeData data;
- DALI_TEST_CHECK(!LoadCubeMapData(TEST_RESOURCE_DIR "/invalid.svg", data)); // file smaller than KTX header
+ DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/invalid.svg", data)); // file smaller than KTX header
END_TEST;
}
int UtcDaliKtxLoaderFailInvalid2(void)
{
CubeData data;
- DALI_TEST_CHECK(!LoadCubeMapData(TEST_RESOURCE_DIR "/anim.gif", data)); // not a KTX
+ DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/anim.gif", data)); // not a KTX
END_TEST;
}
int UtcDaliKtxLoaderFailTruncated(void)
{
CubeData data;
- DALI_TEST_CHECK(!LoadCubeMapData(TEST_RESOURCE_DIR "/truncated.ktx", data));
+ DALI_TEST_CHECK(!LoadKtxData(TEST_RESOURCE_DIR "/truncated.ktx", data));
END_TEST;
}
{
CubeData cubeData;
auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
- DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
+ DALI_TEST_CHECK(LoadKtxData(path, cubeData));
DALI_TEST_EQUAL(6u, cubeData.data.size());
for (auto& face: cubeData.data)
for (auto i : pathFormats)
{
CubeData cubeData;
- DALI_TEST_CHECK(LoadCubeMapData(resPath + i.first + ".ktx", cubeData));
+ DALI_TEST_CHECK(LoadKtxData(resPath + i.first + ".ktx", cubeData));
DALI_TEST_EQUAL(cubeData.data[0][0].GetPixelFormat(), i.second);
}
{
CubeData cubeData;
auto path = TEST_RESOURCE_DIR "/forest_radiance.ktx";
- DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
+ DALI_TEST_CHECK(LoadKtxData(path, cubeData));
TestApplication app;
auto texture = cubeData.CreateTexture();
{
CubeData cubeData;
auto path = TEST_RESOURCE_DIR "/papermill_E_diffuse-64.ktx";
- DALI_TEST_CHECK(LoadCubeMapData(path, cubeData));
+ DALI_TEST_CHECK(LoadKtxData(path, cubeData));
TestApplication app;
auto texture = cubeData.CreateTexture();
#include "model-view-impl.h"
// EXTERNAL INCLUDES
-#include <dali/devel-api/adaptor-framework/image-loading.h>
-#include <dali/devel-api/adaptor-framework/pixel-buffer.h>
#include <dali-toolkit/dali-toolkit.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/internal/controls/control/control-data-impl.h>
#include <dali-scene-loader/public-api/scene-definition.h>
#include <dali-scene-loader/public-api/shader-definition-factory.h>
#include <dali-scene-loader/public-api/controls/model-view/model-view.h>
+#include <dali-scene-loader/public-api/cube-map-loader.h>
+#include <dali-scene-loader/public-api/cube-data.h>
using namespace Dali;
Texture LoadCubeMap(const std::string& cubeMapPath)
{
- std::filesystem::path modelPath(cubeMapPath);
- std::string extension = modelPath.extension();
- std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
-
- Texture cubeTexture;
- if(extension == KTX_EXTENSION)
+ Texture cubeTexture;
+ SceneLoader::CubeData cubeData;
+ if(SceneLoader::LoadCubeMapData(cubeMapPath, cubeData))
{
- SceneLoader::CubeData cubeData;
- if(SceneLoader::LoadCubeMapData(cubeMapPath, cubeData))
- {
- cubeTexture = cubeData.CreateTexture();
- }
- else
- {
- DALI_LOG_ERROR("Fail to load cube map, %s\n", cubeMapPath.c_str());
- }
+ cubeTexture = cubeData.CreateTexture();
+ }
+ else
+ {
+ DALI_LOG_ERROR("Fail to load cube map, %s\n", cubeMapPath.c_str());
}
return cubeTexture;
--- /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-scene-loader/public-api/cube-data.h"
+
+// EXTERNAL INCLUDES
+#include "dali/public-api/rendering/texture.h"
+
+namespace Dali
+{
+namespace SceneLoader
+{
+
+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 SceneLoader
+} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE_LOADER_CUBE_DATA_H
+#define DALI_SCENE_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-scene-loader/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 SceneLoader
+{
+/**
+ * @brief Stores the pixel data objects for each face of the cube texture and their mipmaps.
+ */
+class DALI_SCENE_LOADER_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 SceneLoader
+} // namespace Dali
+
+#endif // DALI_SCENE_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-scene-loader/public-api/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 SceneLoader
+{
+bool LoadCubeData(const std::string& path, CubeData& cubedata)
+{
+ Texture cubeTexture;
+ // 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 SceneLoader
+} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE_LOADER_CUBE_LOADER_H
+#define DALI_SCENE_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-scene-loader/public-api/api.h>
+#include <dali-scene-loader/public-api/cube-data.h>
+
+namespace Dali
+{
+namespace SceneLoader
+{
+
+/**
+ * @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 SceneLoader
+} // namespace Dali
+
+#endif // DALI_SCENE_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-scene-loader/public-api/cube-map-loader.h>
+
+// INTERNAL INCLUDES
+#include <dali-scene-loader/public-api/ktx-loader.h>
+#include <dali-scene-loader/public-api/cube-loader.h>
+
+// EXTERNAL INCLUDES
+#include <filesystem>
+
+namespace Dali
+{
+namespace
+{
+
+const std::string_view KTX_EXTENSION = ".ktx";
+
+}
+
+namespace SceneLoader
+{
+
+bool LoadCubeMapData(const std::string& path, CubeData& cubedata)
+{
+ std::filesystem::path modelPath(path);
+ std::string extension = modelPath.extension();
+ std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
+
+ return (extension == KTX_EXTENSION) ? SceneLoader::LoadKtxData(path, cubedata) : SceneLoader::LoadCubeData(path, cubedata);
+}
+
+} // namespace SceneLoader
+} // namespace Dali
--- /dev/null
+#ifndef DALI_SCENE_LOADER_CUBE_MAP_LOADER_H
+#define DALI_SCENE_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-scene-loader/public-api/api.h>
+#include <dali-scene-loader/public-api/cube-data.h>
+
+namespace Dali
+{
+namespace SceneLoader
+{
+
+/**
+ * @brief Loads cube map data texture from a cube map 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 LoadCubeMapData(const std::string& path, CubeData& cubedata);
+
+} // namespace SceneLoader
+} // namespace Dali
+
+#endif // DALI_SCENE_LOADER_CUBE_MAP_LOADER_H
// INTERNAL INCLUDES
#include "dali-scene-loader/public-api/environment-definition.h"
#include "dali-scene-loader/public-api/utils.h"
+#include "dali-scene-loader/public-api/cube-map-loader.h"
namespace
{
// INTERNAL INCLUDES
#include "dali-scene-loader/public-api/api.h"
-#include "dali-scene-loader/public-api/ktx-loader.h"
+#include "dali-scene-loader/public-api/cube-data.h"
// EXTERNAL INCLUDES
#include "dali/public-api/math/quaternion.h"
${scene_loader_public_api_dir}/animation-definition.cpp
${scene_loader_public_api_dir}/blend-shape-details.cpp
${scene_loader_public_api_dir}/camera-parameters.cpp
+ ${scene_loader_public_api_dir}/cube-data.cpp
+ ${scene_loader_public_api_dir}/cube-loader.cpp
+ ${scene_loader_public_api_dir}/cube-map-loader.cpp
${scene_loader_public_api_dir}/customization.cpp
${scene_loader_public_api_dir}/dli-loader.cpp
${scene_loader_public_api_dir}/environment-definition.cpp
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * 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.
*/
// FILE HEADER
-#include "dali-scene-loader/public-api/ktx-loader.h"
+#include <dali-scene-loader/public-api/ktx-loader.h>
// EXTERNAL INCLUDES
#include <fstream>
#include <memory>
-#include "dali/public-api/rendering/texture.h"
+#include <dali/public-api/rendering/texture.h>
namespace Dali
{
return true;
}
-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());
- }
- }
-
- return texture;
-}
-
-bool LoadCubeMapData(const std::string& path, CubeData& cubedata)
+bool LoadKtxData(const std::string& path, CubeData& cubedata)
{
std::fstream fp(path, std::ios::in | std::ios::binary);
if(fp.is_open() == false)
#ifndef DALI_SCENE_LOADER_KTX_LOADER_H
#define DALI_SCENE_LOADER_KTX_LOADER_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * 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.
*/
// INTERNAL INCLUDES
-#include "dali-scene-loader/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"
+#include <dali-scene-loader/public-api/api.h>
+#include <dali-scene-loader/public-api/cube-data.h>
namespace Dali
{
namespace SceneLoader
{
-/**
- * @brief Stores the pixel data objects for each face of the cube texture and their mipmaps.
- */
-struct DALI_SCENE_LOADER_API CubeData
-{
- std::vector<std::vector<PixelData> > data;
-
- Texture CreateTexture() const;
-};
/**
* @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.
+ * @return bool True if the loading is succeded.
*/
-DALI_SCENE_LOADER_API bool LoadCubeMapData(const std::string& path, CubeData& cubedata);
+bool LoadKtxData(const std::string& path, CubeData& cubedata);
} // namespace SceneLoader
} // namespace Dali