[dali_2.1.1] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / environment-definition.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // INTERNAL INCLUDES
19 #include "dali-scene-loader/public-api/environment-definition.h"
20 #include "dali-scene-loader/public-api/utils.h"
21
22 namespace Dali
23 {
24 namespace SceneLoader
25 {
26 EnvironmentDefinition::RawData
27 EnvironmentDefinition::LoadRaw(const std::string& environmentsPath) const
28 {
29   RawData raw;
30   auto    loadFn = [&environmentsPath](const std::string& path, CubeData& cd) {
31     if(path.empty())
32     {
33       cd.data.resize(6);
34       for(auto& face : cd.data)
35       {
36         face.push_back(PixelData::New(new uint8_t[3]{0xff, 0xff, 0xff}, 3, 1, 1, Pixel::RGB888, PixelData::DELETE_ARRAY));
37       }
38     }
39     else if(!LoadCubeMapData(environmentsPath + path, cd))
40     {
41       ExceptionFlinger(ASSERT_LOCATION) << "Failed to load cubemap texture from '" << path << "'.";
42     }
43   };
44
45   loadFn(mDiffuseMapPath, raw.mDiffuse);
46   loadFn(mSpecularMapPath, raw.mSpecular);
47   return raw;
48 }
49
50 EnvironmentDefinition::Textures EnvironmentDefinition::Load(RawData&& raw) const
51 {
52   Textures textures;
53
54   // This texture should have 6 faces and only one mipmap
55   if(!raw.mDiffuse.data.empty())
56   {
57     textures.mDiffuse = raw.mDiffuse.CreateTexture();
58   }
59
60   // This texture should have 6 faces and 6 mipmaps
61   if(!raw.mSpecular.data.empty())
62   {
63     textures.mSpecular = raw.mSpecular.CreateTexture();
64   }
65   return textures;
66 }
67
68 } // namespace SceneLoader
69 } // namespace Dali