Merge changes I776588c1,I7292a2fb into 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) 2023 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/public-api/actors/custom-actor-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 CustomActorImpl
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   /**
220    * @copydoc Scene3D::Light::GetMaximumEnabledLightCount()
221    */
222   static uint32_t GetMaximumEnabledLightCount();
223
224   /**
225    * @brief Retrieves Light Enabled Uniform Name for shader()
226    * @return string_view for LightEnabledUniformName
227    */
228   static std::string_view GetLightCountUniformName();
229
230   /**
231    * @brief Retrieves Light Direction Uniform Name for shader()
232    * @return string_view for LightDirectionUniformName
233    */
234   static std::string_view GetLightDirectionUniformName();
235
236   /**
237    * @brief Retrieves Light Color Uniform Name for shader()
238    * @return string_view for LightColorUniformName
239    */
240   static std::string_view GetLightColorUniformName();
241
242   /**
243    * @brief Retrieves Uniform Name to define shadow is enabled or not.
244    * @return string_view for ShadowEnabledUniformName
245    */
246   static std::string_view GetShadowEnabledUniformName();
247
248   /**
249    * @brief Retrieves Uniform Name for View/Projection matrix of the Shadow.
250    * @return string_view for ShadowViewProjectionMatrixUniformName
251    */
252   static std::string_view GetShadowViewProjectionMatrixUniformName();
253
254 private:
255   void UpdateShadowUniforms();
256
257 private:
258   /// @cond internal
259
260   // Not copyable or movable
261   DALI_INTERNAL        Light(const Light&)     = delete; ///< Deleted copy constructor.
262   DALI_INTERNAL        Light(Light&&)          = delete; ///< Deleted move constructor.
263   DALI_INTERNAL Light& operator=(const Light&) = delete; ///< Deleted copy assignment operator.
264   DALI_INTERNAL Light& operator=(Light&&)      = delete; ///< Deleted move assignment operator.
265
266 private:
267   Dali::CameraActor              mLightSourceActor;
268   WeakHandle<Scene3D::SceneView> mParentSceneView;
269   bool                           mIsEnabled{true};
270   bool                           mIsShadowEnabled{false};
271   bool                           mUseSoftFiltering{false};
272   float                          mShadowIntensity{0.5f};
273   float                          mShadowBias{0.001f};
274   /// @endcond
275 };
276
277 /**
278  * @brief Gets implementation from the handle.
279  *
280  * @param handle
281  * @return Implementation
282  * @pre handle is initialized and points to a node
283  */
284 DALI_SCENE3D_API Internal::Light& GetImplementation(Dali::Scene3D::Light& handle);
285
286 /**
287  * @brief Gets implementation from the handle.
288  *
289  * @param handle
290  * @return Implementation
291  * @pre Handle is initialized and points to a node.
292  */
293 DALI_SCENE3D_API const Internal::Light& GetImplementation(const Dali::Scene3D::Light& handle);
294
295 } // namespace Internal
296
297 /**
298  * @}
299  */
300 } // namespace Scene3D
301
302 } // namespace Dali
303
304 #endif // DALI_SCENE3D_LIGHT_IMPL_H