Supports cube map images in scene-loader
[platform/core/uifw/dali-toolkit.git] / dali-scene-loader / public-api / cube-data.cpp
1 /*
2  * Copyright (c) 2022 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 // FILE HEADER
19 #include "dali-scene-loader/public-api/cube-data.h"
20
21 // EXTERNAL INCLUDES
22 #include "dali/public-api/rendering/texture.h"
23
24 namespace Dali
25 {
26 namespace SceneLoader
27 {
28
29 Texture CubeData::CreateTexture() const
30 {
31   Texture texture = Texture::New(TextureType::TEXTURE_CUBE, data[0][0].GetPixelFormat(), data[0][0].GetWidth(), data[0][0].GetHeight());
32   for(size_t iSide = 0u, iEndSize = data.size(); iSide < iEndSize; ++iSide)
33   {
34     auto& side = data[iSide];
35     for(size_t iMipLevel = 0u, iEndMipLevel = data[0].size(); iMipLevel < iEndMipLevel; ++iMipLevel)
36     {
37       texture.Upload(side[iMipLevel], CubeMapLayer::POSITIVE_X + iSide, iMipLevel, 0u, 0u, side[iMipLevel].GetWidth(), side[iMipLevel].GetHeight());
38     }
39   }
40
41   // If mipmap is not defined explicitly, use GenerateMipmaps.
42   // TODO: Maybe we can use better way to know it already has mipmap or not.
43   if(data.size() > 0u && data[0].size() == 1u)
44   {
45     texture.GenerateMipmaps();
46   }
47
48   return texture;
49 }
50
51 } // namespace SceneLoader
52 } // namespace Dali