[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / shader-manager.h
1 #ifndef DALI_SCENE3D_LOADER_SHADER_MANAGER_H_
2 #define DALI_SCENE3D_LOADER_SHADER_MANAGER_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 INCLUDER
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/rendering/shader.h>
23 #include <memory>
24
25 // INTERNAL INCLUDES
26 #include <dali-scene3d/public-api/api.h>
27 #include <dali-scene3d/public-api/light/light.h>
28 #include <dali-scene3d/public-api/loader/index.h>
29 #include <dali-scene3d/public-api/loader/material-definition.h>
30 #include <dali-scene3d/public-api/loader/mesh-definition.h>
31 #include <dali-scene3d/public-api/loader/renderer-state.h>
32 #include <dali-scene3d/public-api/loader/shader-option.h>
33
34 namespace Dali::Scene3D::Loader
35 {
36 struct NodeDefinition;
37 class ResourceBundle;
38 class ShaderManager;
39 typedef IntrusivePtr<ShaderManager> ShaderManagerPtr;
40
41 /**
42  * @brief This class is to manage Shaders.
43  *
44  * This class could be used as factory class to create Dali::Shader.
45  * And once created Dali::Shader is kept in this manager and will be returned when the same Dali::Shader is requested to be created.
46  * @SINCE_2_2.34
47  */
48 class DALI_SCENE3D_API ShaderManager : public RefObject
49 {
50 public:
51   ShaderManager();
52   ~ShaderManager();
53
54   /**
55    * @brief Produces a Dali::Shader for the input materialDefinition and meshDefinition.
56    *
57    * Returns a cached Dali::Shader if the requested Dali::Shader has already been created once.
58    * (Although the input materialDefinition and meshDefinition are not identical to those used to create the cached Dali::Shader, they share the cached one.)
59    * @SINCE_2_2.34
60    * @param[in] materialDefinition MaterialDefinition that includes information of material to create Shader.
61    * @param[in] meshDefinition meshDefinition that includes information of mesh to create Shader.
62    * @return ShaderOption for the materialDefinition and meshDefinition.
63    */
64   ShaderOption ProduceShaderOption(const MaterialDefinition& materialDefinition, const MeshDefinition& meshDefinition);
65
66   /**
67    * @brief Produces a Dali::Shader for the input ShaderOption.
68    *
69    * Returns a cached Dali::Shader if the requested Dali::Shader has already been created once.
70    * @SINCE_2_2.34
71    * @param[in] shaderOption shader option to create Shader.
72    * @return Dali::Shader of the shader option
73    */
74   Dali::Shader ProduceShader(const ShaderOption& shaderOption);
75
76   /**
77    * @brief Returns RendererState of the input materialDefinition.
78    * @SINCE_2_2.34
79    * @param[in] materialDefinition MaterialDefinition to get RendererState
80    * @return RendererState of the materialDefinition.
81    */
82   RendererState::Type GetRendererState(const MaterialDefinition& materialDefinition);
83
84   /**
85    * @brief Adds new lights for each of shaders.
86    * @SINCE_2_2.34
87    * @param[in] light Light object to be newly added.
88    * @return True when the new light object is added successfully.
89    */
90   bool AddLight(Scene3D::Light light);
91
92   /**
93    * @brief Removes light from each of shaders.
94    * @SINCE_2_2.34
95    * @param[in] light Light object to be removed.
96    */
97   void RemoveLight(Scene3D::Light light);
98
99   /**
100    * @brief Retrieves added light counts.
101    * @SINCE_2_2.34
102    * @return The number of added light count.
103    */
104   uint32_t GetLightCount() const;
105
106   /**
107    * @brief Set a shadow to this scene by input light.
108    * @SINCE_2_2.34
109    * @param[in] light Light object to make shadow.
110    */
111   void SetShadow(Scene3D::Light light);
112
113   /**
114    * @brief Removes Shadow from this SceneView.
115    * @SINCE_2_2.34
116    */
117   void RemoveShadow();
118
119   /**
120    * @brief Update uniform properties of shadow for the input light.
121    * @SINCE_2_2.34
122    * @param[in] light Light object to update shadow uniform.
123    */
124   void UpdateShadowUniform(Scene3D::Light light);
125
126 private:
127   /// @cond internal
128   /**
129    * @brief Sets constraint to the shaders with light of light index.
130    * @param[in] lightIndex index of light that will be connected with shaders by constraint.
131    */
132   DALI_INTERNAL void SetLightConstraint(uint32_t lightIndex);
133
134   /**
135    * @brief Sets constraint to a shader with light of light index.
136    * @param[in] lightIndex index of light that will be connected with input shader by constraint.
137    * @param[in] shader Shader that the constraint will be applied.
138    */
139   DALI_INTERNAL void SetLightConstraintToShader(uint32_t lightIndex, Dali::Shader shader);
140
141   /**
142    * @brief Removes constraint of shaders and light of light index.
143    * @param[in] lightIndex index of light that will be disconnected with shaders.
144    */
145   DALI_INTERNAL void RemoveLightConstraint(uint32_t lightIndex);
146
147   /**
148    * @brief Sets uniform about the shadow.
149    * @param[in] shader Shader that the constraint will be applied.
150    */
151   DALI_INTERNAL void SetShadowUniformToShader(Dali::Shader shader);
152
153   /**
154    * @brief Sets properties and constraint to the shaders.
155    */
156   DALI_INTERNAL void SetShadowProperty();
157
158   /**
159    * @brief Sets constraint to a shader about shadow
160    * @param[in] shader Shader that the constraint will be applied.
161    */
162   DALI_INTERNAL void SetShadowConstraintToShader(Dali::Shader shader);
163
164   /// @endcond
165 private:
166   struct Impl;
167   const std::unique_ptr<Impl> mImpl;
168 };
169
170 } // namespace Dali::Scene3D::Loader
171
172 #endif // DALI_SCENE3D_LOADER_SHADER_MANAGER_H_