bb46c5f4d83adaec4d83b9a69bdfb3040084fec5
[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   /**
61    * @copydoc Scene3D::Light::Enable()
62    */
63   void Enable(bool enable);
64
65   /**
66    * @copydoc Scene3D::Light::IsEnabled()
67    */
68   bool IsEnabled() const;
69
70   /**
71    * @copydoc Scene3D::Light::EnableShadow()
72    */
73   void EnableShadow(bool enable);
74
75   /**
76    * @copydoc Scene3D::Light::IsShadowEnabled()
77    */
78   bool IsShadowEnabled() const;
79
80   /**
81    * @copydoc Scene3D::Light::GetCamera()
82    */
83   CameraActor GetCamera() const;
84
85   /**
86    * @copydoc Scene3D::Light::EnableShadowSoftFiltering()
87    */
88   void EnableShadowSoftFiltering(bool useSoftFiltering);
89
90   /**
91    * @copydoc Scene3D::Light::IsShadowSoftFilteringEnabled()
92    */
93   bool IsShadowSoftFilteringEnabled() const;
94
95   /**
96    * @copydoc Scene3D::Light::SetShadowIntensity()
97    */
98   void SetShadowIntensity(float shadowIntensity);
99
100   /**
101    * @copydoc Scene3D::Light::GetShadowIntensity()
102    */
103   float GetShadowIntensity() const;
104
105   /**
106    * @copydoc Scene3D::Light::SetShadowBias()
107    */
108   void SetShadowBias(float shadowBias);
109
110   /**
111    * @copydoc Scene3D::Light::GetShadowBias()
112    */
113   float GetShadowBias() const;
114
115 protected:
116   /**
117    * @brief Virtual destructor.
118    * @SINCE_2_2.32
119    */
120   virtual ~Light();
121
122 protected: // From CustomActorImpl
123   /**
124    * @copydoc CustomActorImpl::OnSceneConnection()
125    * @note If overridden, then an up-call to Light::OnSceneConnection MUST be made at the end.
126    */
127   void OnSceneConnection(int depth) override;
128
129   /**
130    * @copydoc CustomActorImpl::OnSceneDisconnection()
131    * @note If overridden, then an up-call to Light::OnSceneDisconnection MUST be made at the end.
132    */
133   void OnSceneDisconnection() override;
134
135   /**
136    * @copydoc CustomActorImpl::OnChildAdd()
137    * @note If overridden, then an up-call to Light::OnChildAdd MUST be made at the end.
138    */
139   void OnChildAdd(Actor& child) override;
140
141   /**
142    * @copydoc CustomActorImpl::OnChildRemove()
143    * @note If overridden, then an up-call to Light::OnChildRemove MUST be made at the end.
144    */
145   void OnChildRemove(Actor& child) override;
146
147   /**
148    * @copydoc CustomActorImpl::OnSizeSet()
149    * @note If overridden, then an up-call to Light::OnSizeSet MUST be made at the end.
150    */
151   void OnSizeSet(const Vector3& targetSize) override;
152
153   /**
154    * @copydoc CustomActorImpl::OnSizeAnimation()
155    * @note If overridden, then an up-call to Light::OnSizeAnimation MUST be made at the end.
156    */
157   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
158
159   /**
160    * @copydoc CustomActorImpl::OnRelayout()
161    */
162   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
163
164   /**
165    * @copydoc CustomActorImpl::OnSetResizePolicy()
166    */
167   void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
168
169   /**
170    * @copydoc CustomActorImpl::GetNaturalSize()
171    */
172   Vector3 GetNaturalSize() override;
173
174   /**
175    * @copydoc CustomActorImpl::CalculateChildSize()
176    */
177   float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
178
179   /**
180    * @copydoc CustomActorImpl::GetHeightForWidth()
181    */
182   float GetHeightForWidth(float width) override;
183
184   /**
185    * @copydoc CustomActorImpl::GetWidthForHeight()
186    */
187   float GetWidthForHeight(float height) override;
188
189   /**
190    * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
191    */
192   bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
193
194   /**
195    * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
196    */
197   void OnCalculateRelayoutSize(Dimension::Type dimension) override;
198
199   /**
200    * @copydoc CustomActorImpl::OnLayoutNegotiated()
201    */
202   void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
203
204 protected:
205   // Construction
206
207   /**
208    * @brief Light constructor.
209    */
210   Light();
211
212   /**
213    * @brief Second phase initialization.
214    */
215   void Initialize();
216
217 public: // Public Method
218   /**
219    * @copydoc Scene3D::Light::GetMaximumEnabledLightCount()
220    */
221   static uint32_t GetMaximumEnabledLightCount();
222
223   /**
224    * @brief Retrieves Light Enabled Uniform Name for shader()
225    * @return string_view for LightEnabledUniformName
226    */
227   static std::string_view GetLightCountUniformName();
228
229   /**
230    * @brief Retrieves Light Direction Uniform Name for shader()
231    * @return string_view for LightDirectionUniformName
232    */
233   static std::string_view GetLightDirectionUniformName();
234
235   /**
236    * @brief Retrieves Light Color Uniform Name for shader()
237    * @return string_view for LightColorUniformName
238    */
239   static std::string_view GetLightColorUniformName();
240
241   /**
242    * @brief Retrieves Uniform Name to define shadow is enabled or not.
243    * @return string_view for ShadowEnabledUniformName
244    */
245   static std::string_view GetShadowEnabledUniformName();
246
247   /**
248    * @brief Retrieves Uniform Name for View/Projection matrix of the Shadow.
249    * @return string_view for ShadowViewProjectionMatrixUniformName
250    */
251   static std::string_view GetShadowViewProjectionMatrixUniformName();
252
253 private:
254   void UpdateShadowUniforms();
255
256 private:
257   /// @cond internal
258
259   // Not copyable or movable
260   DALI_INTERNAL Light(const Light&) = delete;            ///< Deleted copy constructor.
261   DALI_INTERNAL Light(Light&&)      = delete;            ///< Deleted move constructor.
262   DALI_INTERNAL Light& operator=(const Light&) = delete; ///< Deleted copy assignment operator.
263   DALI_INTERNAL Light& operator=(Light&&) = delete;      ///< Deleted move assignment operator.
264
265 private:
266   Dali::CameraActor              mLightSourceActor;
267   WeakHandle<Scene3D::SceneView> mParentSceneView;
268   bool                           mIsEnabled{true};
269   bool                           mIsShadowEnabled{false};
270   bool                           mUseSoftFiltering{false};
271   float                          mShadowIntensity{0.5f};
272   float                          mShadowBias{0.001f};
273   /// @endcond
274 };
275
276 /**
277  * @brief Gets implementation from the handle.
278  *
279  * @param handle
280  * @return Implementation
281  * @pre handle is initialized and points to a node
282  */
283 DALI_SCENE3D_API Internal::Light& GetImplementation(Dali::Scene3D::Light& handle);
284
285 /**
286  * @brief Gets implementation from the handle.
287  *
288  * @param handle
289  * @return Implementation
290  * @pre Handle is initialized and points to a node.
291  */
292 DALI_SCENE3D_API const Internal::Light& GetImplementation(const Dali::Scene3D::Light& handle);
293
294 } // namespace Internal
295
296 /**
297  * @}
298  */
299 } // namespace Scene3D
300
301 } // namespace Dali
302
303 #endif // DALI_SCENE3D_LIGHT_IMPL_H