Makes Models use common shader manager
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / shader-option.cpp
1 /*
2  * Copyright (c) 2023 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 // CLASS HEADER
19 #include <dali-scene3d/public-api/loader/shader-option.h>
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 namespace Dali::Scene3D::Loader
25 {
26 namespace
27 {
28 static constexpr std::string_view OPTION_KEYWORD[] =
29   {
30     "GLTF_CHANNELS",
31     "THREE_TEX",
32     "BASECOLOR_TEX",
33     "METALLIC_ROUGHNESS_TEX",
34     "NORMAL_TEX",
35     "OCCLUSION",
36     "EMISSIVE_TEXTURE",
37     "ALPHA_TEST",
38     "SSS",
39     "MATERIAL_SPECULAR_TEXTURE",
40     "MATERIAL_SPECULAR_COLOR_TEXTURE",
41     "SKINNING",
42     "FLIP_V",
43     "COLOR_ATTRIBUTE",
44     "VEC4_TANGENT",
45     "MORPH_POSITION",
46     "MORPH_NORMAL",
47     "MORPH_TANGENT",
48     "MORPH_VERSION_2_0",
49 };
50 static constexpr uint32_t NUMBER_OF_OPTIONS = sizeof(OPTION_KEYWORD) / sizeof(OPTION_KEYWORD[0]);
51 } // namespace
52
53 void ShaderOption::SetTransparency()
54 {
55   mOptionHash |= (1 << NUMBER_OF_OPTIONS);
56 }
57
58 void ShaderOption::AddOption(Type shaderOptionType)
59 {
60   mOptionHash |= (1 << static_cast<uint32_t>(shaderOptionType));
61 }
62
63 uint64_t ShaderOption::GetOptionHash() const
64 {
65   return mOptionHash;
66 }
67
68 void ShaderOption::GetDefines(std::vector<std::string>& defines) const
69 {
70   defines.clear();
71   for(uint32_t i = 0; i < NUMBER_OF_OPTIONS; ++i)
72   {
73     if(mOptionHash & 1 << i)
74     {
75       defines.push_back(OPTION_KEYWORD[i].data());
76     }
77   }
78 }
79
80 std::string_view ShaderOption::GetDefineKeyword(Type shaderOptionType)
81 {
82   return OPTION_KEYWORD[static_cast<uint32_t>(shaderOptionType)];
83 }
84
85 } // namespace Dali::Scene3D::Loader