1 #ifndef DALI_SCENE3D_LOADER_SHADER_MANAGER_H_
2 #define DALI_SCENE3D_LOADER_SHADER_MANAGER_H_
4 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/rendering/shader.h>
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>
34 namespace Dali::Scene3D::Loader
36 struct NodeDefinition;
39 typedef IntrusivePtr<ShaderManager> ShaderManagerPtr;
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.
46 class DALI_SCENE3D_API ShaderManager : public RefObject
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.
60 Dali::Shader ProduceShader(const MaterialDefinition& materialDefinition, const MeshDefinition& meshDefinition);
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
68 Dali::Shader ProduceShader(const ShaderOption& shaderOption);
71 * @brief Returns RendererState of the input materialDefinition.
72 * @param[in] materialDefinition MaterialDefinition to get RendererState
73 * @return RendererState of the materialDefinition.
75 RendererState::Type GetRendererState(const MaterialDefinition& materialDefinition);
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.
82 bool AddLight(Scene3D::Light light);
85 * @brief Removes light from each of shaders.
86 * @param[in] light Light object to be removed.
88 void RemoveLight(Scene3D::Light light);
91 * @brief Retrieves added light counts.
92 * @return The number of added light count.
94 uint32_t GetLightCount() const;
97 * @brief Set a shadow to this scene by input light.
99 * @param[in] light Light object to make shadow.
101 void SetShadow(Scene3D::Light light);
104 * @brief Removes Shadow from this SceneView.
109 * @brief Update uniform properties of shadow for the input light.
110 * @param[in] light Light object to update shadow uniform.
112 void UpdateShadowUniform(Scene3D::Light light);
116 * @brief Sets constraint to the shaders with light of light index.
117 * @param[in] lightIndex index of light that will be connected with shaders by constraint.
119 DALI_INTERNAL void SetLightConstraint(uint32_t lightIndex);
122 * @brief Sets constraint to a shader with light of light index.
123 * @param[in] lightIndex index of light that will be connected with input shader by constraint.
124 * @param[in] shader Shader that the constraint will be applied.
126 DALI_INTERNAL void SetLightConstraintToShader(uint32_t lightIndex, Dali::Shader shader);
129 * @brief Removes constraint of shaders and light of light index.
130 * @param[in] lightIndex index of light that will be disconnected with shaders.
132 DALI_INTERNAL void RemoveLightConstraint(uint32_t lightIndex);
135 * @brief Sets uniform about the shadow.
136 * @param[in] shader Shader that the constraint will be applied.
138 DALI_INTERNAL void SetShadowUniformToShader(Dali::Shader shader);
141 * @brief Sets properties and constraint to the shaders.
143 DALI_INTERNAL void SetShadowProperty();
146 * @brief Sets constraint to a shader about shadow
147 * @param[in] shader Shader that the constraint will be applied.
149 DALI_INTERNAL void SetShadowConstraintToShader(Dali::Shader shader);
152 const std::unique_ptr<Impl> mImpl;
155 } // namespace Dali::Scene3D::Loader
157 #endif // DALI_SCENE3D_LOADER_SHADER_MANAGER_H_