[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / light / light-impl.h
1 #ifndef DALI_SCENE3D_LIGHT_IMPL_H
2 #define DALI_SCENE3D_LIGHT_IMPL_H
3
4 /*
5  * Copyright (c) 2024 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/object/weak-handle.h>
25 #include <string_view>
26
27 // INTERNAL INCLUDES
28 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
29 #include <dali-scene3d/public-api/light/light.h>
30
31 namespace Dali
32 {
33 namespace Scene3D
34 {
35 /**
36  * @addtogroup dali_scene3d_light
37  * @{
38  */
39
40 namespace Internal
41 {
42 /**
43  * @brief This is the internal base class for custom node of Light.
44  *
45  * @SINCE_2_2.32
46  */
47 class DALI_SCENE3D_API Light : public Toolkit::Internal::Control
48 {
49 public:
50   // Creation & Destruction
51   /**
52    * @brief Creates a new LightImpl instance that does not require touch by default.
53    *
54    * If touch is required, then the user can connect to this class' touch signal.
55    * @SINCE_2_2.32
56    * @return A handle to the Light instance
57    */
58   static Scene3D::Light New();
59
60 protected:
61   /**
62    * @brief Virtual destructor.
63    * @SINCE_2_2.32
64    */
65   virtual ~Light();
66
67 public: // From Internal::Control.
68   /**
69    * @copydoc Dali::Toolkit::Internal::Control::OnInitialize()
70    */
71   void OnInitialize() override;
72
73 protected: // From CustomActorImpl. Note that it will make we can ignore many codes what Internal::Control using now.
74   /**
75    * @copydoc CustomActorImpl::OnSceneConnection()
76    * @note If overridden, then an up-call to Light::OnSceneConnection MUST be made at the end.
77    */
78   void OnSceneConnection(int depth) override;
79
80   /**
81    * @copydoc CustomActorImpl::OnSceneDisconnection()
82    * @note If overridden, then an up-call to Light::OnSceneDisconnection MUST be made at the end.
83    */
84   void OnSceneDisconnection() override;
85
86   /**
87    * @copydoc CustomActorImpl::OnChildAdd()
88    * @note If overridden, then an up-call to Light::OnChildAdd MUST be made at the end.
89    */
90   void OnChildAdd(Actor& child) override;
91
92   /**
93    * @copydoc CustomActorImpl::OnChildRemove()
94    * @note If overridden, then an up-call to Light::OnChildRemove MUST be made at the end.
95    */
96   void OnChildRemove(Actor& child) override;
97
98   /**
99    * @copydoc CustomActorImpl::OnSizeSet()
100    * @note If overridden, then an up-call to Light::OnSizeSet MUST be made at the end.
101    */
102   void OnSizeSet(const Vector3& targetSize) override;
103
104   /**
105    * @copydoc CustomActorImpl::OnSizeAnimation()
106    * @note If overridden, then an up-call to Light::OnSizeAnimation MUST be made at the end.
107    */
108   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
109
110   /**
111    * @copydoc CustomActorImpl::OnRelayout()
112    */
113   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
114
115   /**
116    * @copydoc CustomActorImpl::OnSetResizePolicy()
117    */
118   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
119
120   /**
121    * @copydoc CustomActorImpl::GetNaturalSize()
122    */
123   Vector3 GetNaturalSize() override;
124
125   /**
126    * @copydoc CustomActorImpl::CalculateChildSize()
127    */
128   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
129
130   /**
131    * @copydoc CustomActorImpl::GetHeightForWidth()
132    */
133   float GetHeightForWidth(float width) override;
134
135   /**
136    * @copydoc CustomActorImpl::GetWidthForHeight()
137    */
138   float GetWidthForHeight(float height) override;
139
140   /**
141    * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
142    */
143   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
144
145   /**
146    * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
147    */
148   void OnCalculateRelayoutSize(Dimension::Type dimension) override;
149
150   /**
151    * @copydoc CustomActorImpl::OnLayoutNegotiated()
152    */
153   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
154
155 protected:
156   // Construction
157
158   /**
159    * @brief Light constructor.
160    */
161   Light();
162
163 public: // Public Method
164   /**
165    * @copydoc Scene3D::Light::Enable()
166    */
167   void Enable(bool enable);
168
169   /**
170    * @copydoc Scene3D::Light::IsEnabled()
171    */
172   bool IsEnabled() const;
173
174   /**
175    * @copydoc Scene3D::Light::EnableShadow()
176    */
177   void EnableShadow(bool enable);
178
179   /**
180    * @copydoc Scene3D::Light::IsShadowEnabled()
181    */
182   bool IsShadowEnabled() const;
183
184   /**
185    * @copydoc Scene3D::Light::GetCamera()
186    */
187   CameraActor GetCamera() const;
188
189   /**
190    * @copydoc Scene3D::Light::EnableShadowSoftFiltering()
191    */
192   void EnableShadowSoftFiltering(bool useSoftFiltering);
193
194   /**
195    * @copydoc Scene3D::Light::IsShadowSoftFilteringEnabled()
196    */
197   bool IsShadowSoftFilteringEnabled() const;
198
199   /**
200    * @copydoc Scene3D::Light::SetShadowIntensity()
201    */
202   void SetShadowIntensity(float shadowIntensity);
203
204   /**
205    * @copydoc Scene3D::Light::GetShadowIntensity()
206    */
207   float GetShadowIntensity() const;
208
209   /**
210    * @copydoc Scene3D::Light::SetShadowBias()
211    */
212   void SetShadowBias(float shadowBias);
213
214   /**
215    * @copydoc Scene3D::Light::GetShadowBias()
216    */
217   float GetShadowBias() const;
218
219 public: // Public Static Method
220   /**
221    * @copydoc Scene3D::Light::GetMaximumEnabledLightCount()
222    */
223   static uint32_t GetMaximumEnabledLightCount();
224
225   /**
226    * @brief Retrieves Light Enabled Uniform Name for shader()
227    * @return string_view for LightEnabledUniformName
228    */
229   static std::string_view GetLightCountUniformName();
230
231   /**
232    * @brief Retrieves Light Direction Uniform Name for shader()
233    * @return string_view for LightDirectionUniformName
234    */
235   static std::string_view GetLightDirectionUniformName();
236
237   /**
238    * @brief Retrieves Light Color Uniform Name for shader()
239    * @return string_view for LightColorUniformName
240    */
241   static std::string_view GetLightColorUniformName();
242
243   /**
244    * @brief Retrieves Uniform Name to define shadow is enabled or not.
245    * @return string_view for ShadowEnabledUniformName
246    */
247   static std::string_view GetShadowEnabledUniformName();
248
249   /**
250    * @brief Retrieves Uniform Name for View/Projection matrix of the Shadow.
251    * @return string_view for ShadowViewProjectionMatrixUniformName
252    */
253   static std::string_view GetShadowViewProjectionMatrixUniformName();
254
255 private:
256   void UpdateShadowUniforms();
257
258 private:
259   /// @cond internal
260
261   // Not copyable or movable
262   DALI_INTERNAL Light(const Light&) = delete;            ///< Deleted copy constructor.
263   DALI_INTERNAL Light(Light&&)      = delete;            ///< Deleted move constructor.
264   DALI_INTERNAL Light& operator=(const Light&) = delete; ///< Deleted copy assignment operator.
265   DALI_INTERNAL Light& operator=(Light&&) = delete;      ///< Deleted move assignment operator.
266
267 private:
268   Dali::CameraActor              mLightSourceActor;
269   WeakHandle<Scene3D::SceneView> mParentSceneView;
270   bool                           mIsEnabled{true};
271   bool                           mIsShadowEnabled{false};
272   bool                           mUseSoftFiltering{false};
273   float                          mShadowIntensity{0.5f};
274   float                          mShadowBias{0.001f};
275   /// @endcond
276 };
277
278 /**
279  * @brief Gets implementation from the handle.
280  *
281  * @param handle
282  * @return Implementation
283  * @pre handle is initialized and points to a node
284  */
285 DALI_SCENE3D_API Internal::Light& GetImplementation(Dali::Scene3D::Light& handle);
286
287 /**
288  * @brief Gets implementation from the handle.
289  *
290  * @param handle
291  * @return Implementation
292  * @pre Handle is initialized and points to a node.
293  */
294 DALI_SCENE3D_API const Internal::Light& GetImplementation(const Dali::Scene3D::Light& handle);
295
296 } // namespace Internal
297
298 /**
299  * @}
300  */
301 } // namespace Scene3D
302
303 } // namespace Dali
304
305 #endif // DALI_SCENE3D_LIGHT_IMPL_H