2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/devel-api/adaptor-framework/environment-variable.h>
20 #include <dali/devel-api/adaptor-framework/image-loading.h>
23 #include "dali-scene3d/public-api/loader/cube-map-loader.h"
24 #include "dali-scene3d/public-api/loader/environment-definition.h"
25 #include "dali-scene3d/public-api/loader/utils.h"
29 #define TOKEN_STRING(x) #x
30 std::string GetDaliImagePath()
32 return (nullptr == DALI_IMAGE_DIR) ? Dali::EnvironmentVariable::GetEnvironmentVariable(TOKEN_STRING(DALI_IMAGE_DIR)) : DALI_IMAGE_DIR;
35 static constexpr float DEFAULT_INTENSITY = 1.0f;
36 } // unnamed namespace
46 const std::string PRE_COMPUTED_BRDF_TEXTURE_FILE_NAME = "brdfLUT.png";
49 EnvironmentDefinition::RawData
50 EnvironmentDefinition::LoadRaw(const std::string& environmentsPath) const
53 auto loadFn = [&environmentsPath](const std::string& path, CubeData& cd) {
57 for(auto& face : cd.data)
59 face.push_back(PixelData::New(new uint8_t[3]{0xff, 0xff, 0xff}, 3, 1, 1, Pixel::RGB888, PixelData::DELETE_ARRAY));
62 else if(!LoadCubeMapData(environmentsPath + path, cd))
64 ExceptionFlinger(ASSERT_LOCATION) << "Failed to load cubemap texture from '" << path << "'.";
68 loadFn(mDiffuseMapPath, raw.mDiffuse);
69 loadFn(mSpecularMapPath, raw.mSpecular);
73 Devel::PixelBuffer pixelBuffer = LoadImageFromFile(GetDaliImagePath() + PRE_COMPUTED_BRDF_TEXTURE_FILE_NAME);
76 raw.mBrdf = Devel::PixelBuffer::Convert(pixelBuffer);
82 EnvironmentDefinition::Textures EnvironmentDefinition::Load(RawData&& raw) const
86 // This texture should have 6 faces and only one mipmap
87 if(!raw.mDiffuse.data.empty())
89 textures.mDiffuse = raw.mDiffuse.CreateTexture();
92 // This texture should have 6 faces and 6 mipmaps
93 if(!raw.mSpecular.data.empty())
95 textures.mSpecular = raw.mSpecular.CreateTexture();
100 textures.mBrdf = Texture::New(TextureType::TEXTURE_2D, raw.mBrdf.GetPixelFormat(), raw.mBrdf.GetWidth(), raw.mBrdf.GetHeight());
101 textures.mBrdf.Upload(raw.mBrdf);
106 float EnvironmentDefinition::GetDefaultIntensity()
108 return DEFAULT_INTENSITY;
111 } // namespace Loader
112 } // namespace Scene3D