[dali_2.3.21] Merge branch 'devel/master'
[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) 2023 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 // EXTERNAL INCLUDES
21 #include <dali/public-api/math/quaternion.h>
22 #include <dali/public-api/rendering/texture.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/api.h>
27 #include <dali-scene3d/public-api/loader/environment-map-data.h>
28
29 namespace Dali::Scene3D::Loader
30 {
31 /**
32  * @brief Defines an environment map with either or both of radiance and irradiance maps.
33  * @SINCE_2_0.7
34  */
35 struct DALI_SCENE3D_API EnvironmentDefinition
36 {
37   struct Textures
38   {
39     Texture  mDiffuse;  // irradiance
40     Texture  mSpecular; // radiance
41     Texture  mBrdf;     // pre-computed brdf
42     uint32_t mSpecularMipmapLevels{1u};
43
44     bool IsLoaded() const
45     {
46       return mDiffuse || mSpecular;
47     }
48   };
49
50   struct RawData
51   {
52     EnvironmentMapData mDiffuse;
53     EnvironmentMapData mSpecular;
54     PixelData          mBrdf;
55   };
56
57   using EnvironmentData = std::pair<EnvironmentDefinition, Textures>;
58   using Vector          = std::vector<EnvironmentData>;
59
60   EnvironmentDefinition() = default;
61
62   EnvironmentDefinition(const EnvironmentDefinition&) = delete;
63   EnvironmentDefinition& operator=(const EnvironmentDefinition&) = delete;
64
65   EnvironmentDefinition(EnvironmentDefinition&&) = default;
66   EnvironmentDefinition& operator=(EnvironmentDefinition&&) = default;
67
68   static Dali::Texture GetBrdfTexture();
69
70   /**
71    * @brief Loads raw pixel data for the given diffuse and specular maps.
72    * @SINCE_2_0.7
73    * @return The raw data for the given diffuse and specular maps
74    * @note This can be done on any thread.
75    */
76   RawData LoadRaw(const std::string& environmentsPath);
77
78   /**
79    * @brief Creates DALi cubemap Textures from the pixel data in @a raw, then returns them in a Textures object.
80    * @SINCE_2_0.7
81    * @return DALi cubemap Textures
82    * @note This must only be called from the event thread.
83    */
84   Textures Load(RawData&& raw);
85
86   /**
87    * @brief Get default intensity value.
88    * @SINCE_2_2.1
89    * @return Default intensity. (1.0f)
90    */
91   static float GetDefaultIntensity();
92
93 private:
94   /// @cond internal
95   static void LoadBrdfTexture();
96   /// @endcond internal
97
98 public: // DATA
99   std::string              mDiffuseMapPath;
100   std::string              mSpecularMapPath;
101   std::shared_ptr<RawData> mRawData;
102   Quaternion               mCubeOrientation = Quaternion::IDENTITY;
103   Vector3                  mYDirection      = Vector3::ONE;
104   float                    mIblIntensity    = 1.0f;
105   bool                     mUseBrdfTexture  = false;
106
107 private:
108   static PixelData mBrdfPixelData;
109   static Texture   mBrdfTexture;
110   static bool      mIsBrdfLoaded;
111 };
112
113 } // namespace Dali::Scene3D::Loader
114
115 #endif // DALI_SCENE3D_LOADER_ENVIRONMENT_DEFINITION_H