Apply Light using Shader Manager
[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/loader/index.h>
28 #include <dali-scene3d/public-api/loader/material-definition.h>
29 #include <dali-scene3d/public-api/loader/mesh-definition.h>
30 #include <dali-scene3d/public-api/loader/renderer-state.h>
31 #include <dali-scene3d/public-api/loader/shader-option.h>
32 #include <dali-scene3d/public-api/light/light.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  * This class could be used as factory class to create Dali::Shader.
44  * And once created Dali::Shader is kept in this manager and will be returned when the same Dali::Shader is requested to be created.
45  */
46 class DALI_SCENE3D_API ShaderManager : public RefObject
47 {
48 public:
49   ShaderManager();
50   ~ShaderManager();
51
52   /**
53    * @brief Produces a Dali::Shader for the input materialDefinition and meshDefinition.
54    * Returns a cached Dali::Shader if the requested Dali::Shader has already been created once.
55    * (Although the input materialDefinition and meshDefinition are not identical to those used to create the cached Dali::Shader, they share the cached one.)
56    * @param[in] materialDefinition MaterialDefinition that includes information of material to create Shader.
57    * @param[in] meshDefinition meshDefinition that includes information of mesh to create Shader.
58    * @return Dali::Shader for the materialDefinition and meshDefinition.
59    */
60   Dali::Shader ProduceShader(const MaterialDefinition& materialDefinition, const MeshDefinition& meshDefinition);
61
62   /**
63    * @brief Produces a Dali::Shader for the input ShaderOption
64    * Returns a cached Dali::Shader if the requested Dali::Shader has already been created once.
65    * @param[in] shaderOption shader option to create Shader.
66    * @return Dali::Shader of the shader option
67    */
68   Dali::Shader ProduceShader(const ShaderOption& shaderOption);
69
70   /**
71    * @brief Returns RendererState of the input materialDefinition.
72    * @param[in] materialDefinition MaterialDefinition to get RendererState
73    * @return RendererState of the materialDefinition.
74    */
75   RendererState::Type GetRendererState(const MaterialDefinition& materialDefinition);
76
77   /**
78    * @brief Adds new lights for each of shaders.
79    * @param[in] light Light object to be newly added.
80    * @return True when the new light object is added successfully.
81    */
82   bool AddLight(Scene3D::Light light);
83
84   /**
85    * @brief Removes light from each of shaders.
86    * @param[in] light Light object to be removed.
87    */
88   void RemoveLight(Scene3D::Light light);
89
90   /**
91    * @brief Retrieves added light counts.
92    * @return The number of added light count.
93    */
94   uint32_t GetLightCount() const;
95
96 private:
97   /**
98    * @brief Sets constraint to the shaders with light of light index.
99    * @param[in] lightIndex index of light that will be connected with shaders by constraint.
100    */
101   DALI_INTERNAL void SetLightConstraint(uint32_t lightIndex);
102
103   /**
104    * @brief Sets constraint to a shader with light of light index.
105    * @param[in] lightIndex index of light that will be connected with input shader by constraint.
106    * @param[in] shader Shader that the constraint will be applied.
107    */
108   DALI_INTERNAL void SetLightConstraintToShader(uint32_t lightIndex, Dali::Shader shader);
109
110   /**
111    * @brief Removes constraint of shaders and light of light index.
112    * @param[in] lightIndex index of light that will be disconnected with shaders.
113    */
114   DALI_INTERNAL void RemoveLightConstraint(uint32_t lightIndex);
115 private:
116   struct Impl;
117   const std::unique_ptr<Impl> mImpl;
118 };
119
120 } // namespace Dali::Scene3D::Loader
121
122 #endif // DALI_SCENE3D_LOADER_SHADER_MANAGER_H_