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