[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / shader-option.h
1 #ifndef DALI_SCENE3D_LOADER_SHADER_OPTION_H_
2 #define DALI_SCENE3D_LOADER_SHADER_OPTION_H_
3 /*
4  * Copyright (c) 2024 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 INCLUDER
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <memory>
23 #include <string>
24 #include <string_view>
25
26 // INTERNAL INCLUDES
27 #include <dali-scene3d/public-api/api.h>
28
29 namespace Dali::Scene3D::Loader
30 {
31 class DALI_SCENE3D_API ShaderOption
32 {
33 public:
34   enum class Type
35   {
36     GLTF_CHANNELS = 0,          // 00001
37     THREE_TEXTURE,              // 00002
38     BASE_COLOR_TEXTURE,         // 00004
39     METALLIC_ROUGHNESS_TEXTURE, // 00008
40     NORMAL_TEXTURE,             // 00010
41     OCCLUSION,                  // 00020
42     EMISSIVE,                   // 00040
43     ALPHA_TEST,                 // 00080
44     SUBSURFACE,                 // 00100
45     SPECULAR,                   // 00200
46     SPECULAR_COLOR,             // 00400
47     SKINNING,                   // 00800
48     FLIP_UVS_VERTICAL,          // 01000
49     COLOR_ATTRIBUTE,            // 02000
50     VEC4_TANGENT,               // 04000
51     MORPH_POSITION,             // 08000
52     MORPH_NORMAL,               // 10000
53     MORPH_TANGENT,              // 20000
54     MORPH_VERSION_2_0,          // 40000
55     SL_VERSION_LOW,             // 80000
56   };
57
58   struct MacroDefinition
59   {
60     std::string macro;
61     std::string definition;
62   };
63
64   ShaderOption() = default;
65   ShaderOption(const ShaderOption& rhs);
66   ShaderOption& operator=(const ShaderOption& rhs);
67
68   using HashType = uint64_t;
69
70 public:
71   /**
72    * @brief Sets transparency option.
73    * @SINCE_2_2.33
74    */
75   void SetTransparency();
76
77   /**
78    * @brief Adds new shader definition option.
79    *
80    * If the option is already added, nothin is changed.
81    * @SINCE_2_2.33
82    * @param[in] shaderOptionType Option to be added,
83    */
84   void AddOption(Type shaderOptionType);
85
86   /**
87    * @brief Adds macro definitions for joints based on the number of joint sets.
88    * @SINCE_2_2.52
89    */
90   void AddJointMacros(size_t numberOfJointSets);
91
92   /**
93    * @brief Enables empty preprocessor definitions to be defined to a value.
94    * @SINCE_2_2.52
95    */
96   void AddMacroDefinition(std::string macro, std::string definition);
97
98   /**
99    * @brief Retrieves current shader option hash
100    *
101    * @SINCE_2_2.33
102    * @return Hash value of currently added options.
103    */
104   HashType GetOptionHash() const;
105
106   /**
107    * @brief Retrieves a list of define keywords.
108    *
109    * @SINCE_2_2.33
110    * @param[out] defines A list of define keywords those are used in this option.
111    */
112   void GetDefines(std::vector<std::string>& defines) const;
113
114   /**
115    * @brief Retrieves a single shader define keyword of input type.
116    *
117    * @SINCE_2_2.33
118    * @param[in] shaderOptionType Shader definition option type to know its keyword.
119    * @return string keyword of shader define.
120    */
121   static std::string_view GetDefineKeyword(Type shaderOptionType);
122
123   /**
124    * @brief Get any macro definitions.
125    * @SINCE_2_2.52
126    */
127   const std::vector<MacroDefinition>& GetMacroDefinitions() const;
128
129 private:
130   HashType mOptionHash{0u};
131
132   std::vector<MacroDefinition> mMacros;
133 };
134
135 } // namespace Dali::Scene3D::Loader
136
137 #endif // DALI_SCENE3D_LOADER_SHADER_OPTION_H_