Asynchronous loading of Scene3D resources
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / environment-definition.h
1 #ifndef DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
2 #define DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H
3 /*
4  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 // INTERNAL INCLUDES
21 #include "dali-scene3d/public-api/api.h"
22 #include "dali-scene3d/public-api/loader/cube-data.h"
23
24 // EXTERNAL INCLUDES
25 #include "dali/public-api/math/quaternion.h"
26 #include "dali/public-api/rendering/texture.h"
27 #include <memory>
28
29 namespace Dali
30 {
31 namespace Scene3D
32 {
33 namespace Loader
34 {
35 /**
36  * @brief Defines an environment map with either or both of radiance
37  *  and irradiance maps.
38  */
39 struct DALI_SCENE3D_API EnvironmentDefinition
40 {
41   struct Textures
42   {
43     Texture mDiffuse;  // irradiance
44     Texture mSpecular; // radiance
45     Texture mBrdf;     // pre-computed brdf
46
47     bool IsLoaded() const
48     {
49       return mDiffuse || mSpecular;
50     }
51   };
52
53   struct RawData
54   {
55     CubeData  mDiffuse;
56     CubeData  mSpecular;
57     PixelData mBrdf;
58   };
59
60   using EnvironmentData = std::pair<EnvironmentDefinition, Textures>;
61   using Vector          = std::vector<EnvironmentData>;
62
63   EnvironmentDefinition() = default;
64
65   EnvironmentDefinition(const EnvironmentDefinition&) = delete;
66   EnvironmentDefinition& operator=(const EnvironmentDefinition&) = delete;
67
68   EnvironmentDefinition(EnvironmentDefinition&&) = default;
69   EnvironmentDefinition& operator=(EnvironmentDefinition&&) = default;
70
71   /**
72    * @brief Loads raw pixel data for the given diffuse and specular maps.
73    * @note This can be done on any thread.
74    */
75   RawData LoadRaw(const std::string& environmentsPath) const;
76
77   /**
78    * @brief Creates DALi cubemap Textures from the pixel data in @a raw, then
79    *  returns them in a Textures object.
80    * @note This must only be called from the event thread.
81    */
82   Textures Load(RawData&& raw) const;
83
84   /**
85    * @brief Get default intensity value.
86    * @return Default intensity. (1.0f)
87    */
88   static float GetDefaultIntensity();
89
90 public: // DATA
91   std::string              mDiffuseMapPath;
92   std::string              mSpecularMapPath;
93   std::shared_ptr<RawData> mRawData;
94   Quaternion               mCubeOrientation = Quaternion::IDENTITY;
95   Vector3                  mYDirection      = Vector3::ONE;
96   float                    mIblIntensity    = 1.0f;
97   bool                     mUseBrdfTexture  = false;
98 };
99
100 } // namespace Loader
101 } // namespace Scene3D
102 } // namespace Dali
103
104 #endif //DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H