7632d8011c4cae5232c4960f709d883e9fe4ac3e
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / scene-view / scene-view-impl.h
1 #ifndef DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
2 #define DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
3
4 /*
5  * Copyright (c) 2022 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/internal/visuals/image/image-visual.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/public-api/actors/camera-actor.h>
25 #include <dali/public-api/actors/layer.h>
26 #include <dali/public-api/adaptor-framework/window.h>
27 #include <dali/public-api/animation/animation.h>
28 #include <dali/public-api/object/weak-handle.h>
29 #include <dali/public-api/render-tasks/render-task.h>
30 #include <dali/public-api/rendering/frame-buffer.h>
31 #include <dali/public-api/rendering/texture.h>
32
33 // INTERNAL INCLUDES
34 #include <dali-scene3d/internal/common/image-based-light-observer.h>
35 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
36
37 namespace Dali
38 {
39 namespace Scene3D
40 {
41 class SceneView;
42
43 namespace Internal
44 {
45 /**
46  * @brief Impl class for SceneView.
47  */
48 class SceneView : public Dali::Toolkit::Internal::Control
49 {
50 public:
51   /**
52    * @brief Creates a new SceneView.
53    *
54    * @return A public handle to the newly allocated SceneView.
55    */
56   static Dali::Scene3D::SceneView New();
57
58   /**
59    * @copydoc SceneView::AddCamera()
60    */
61   void AddCamera(Dali::CameraActor camera);
62
63   /**
64    * @copydoc SceneView::RemoveCamera()
65    */
66   void RemoveCamera(CameraActor camera);
67
68   /**
69    * @copydoc SceneView::GetCameraCount()
70    */
71   uint32_t GetCameraCount() const;
72
73   /**
74    * @copydoc SceneView::GetSelectedCamera()
75    */
76   CameraActor GetSelectedCamera() const;
77
78   /**
79    * @copydoc SceneView::GetCamera()
80    */
81   CameraActor GetCamera(uint32_t index) const;
82
83   /**
84    * @copydoc SceneView::GetCamera()
85    */
86   CameraActor GetCamera(const std::string& name) const;
87
88   /**
89    * @copydoc SceneView::SelectCamera()
90    */
91   void SelectCamera(uint32_t index);
92
93   /**
94    * @copydoc SceneView::SelectCamera()
95    */
96   void SelectCamera(const std::string& name);
97
98   /**
99    * @brief Register an item.
100    *
101    * Some works(e.g, lighting) of SceneView should be propagated to the child 3D items.
102    * SceneView can avoid unnecessary tree traversal to find 3D items by storing only 3D items as a list.
103    *
104    * @param[in] item scene observer to be registered.
105    */
106   void RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
107
108   /**
109    * @brief Unregister an item
110    *
111    * @param[in] item scene observer to be unregistered.
112    */
113   void UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item);
114
115   /**
116    * @copydoc SceneView::SetImageBasedLightSource()
117    */
118   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
119
120   /**
121    * @copydoc SceneView::SetImageBasedLightScaleFactor()
122    */
123   void SetImageBasedLightScaleFactor(float scaleFactor);
124
125   /**
126    * @copydoc SceneView::GetImageBasedLightScaleFactor()
127    */
128   float GetImageBasedLightScaleFactor() const;
129
130   /**
131    * @copydoc SceneView::UseFramebuffer()
132    */
133   void UseFramebuffer(bool useFramebuffer);
134
135   /**
136    * @copydoc SceneView::IsUsingFramebuffer()
137    */
138   bool IsUsingFramebuffer() const;
139
140   /**
141    * @copydoc SceneView::SetSkybox()
142    */
143   void SetSkybox(const std::string& skyboxUrl);
144
145   /**
146    * @copydoc SceneView::SetSkyboxIntensity()
147    */
148   void SetSkyboxIntensity(float intensity);
149
150   /**
151    * @copydoc SceneView::GetSkyboxIntensity()
152    */
153   float GetSkyboxIntensity() const;
154
155   /**
156    * @copydoc SceneView::SetSkyboxOrientation()
157    */
158   void SetSkyboxOrientation(const Quaternion& orientation);
159
160   /**
161    * @copydoc SceneView::GetSkyboxOrientation()
162    */
163   Quaternion GetSkyboxOrientation() const;
164
165 protected:
166   /**
167    * @brief Constructs a new SceneView.
168    */
169   SceneView();
170
171   /**
172    * A reference counted object may only be deleted by calling Unreference()
173    */
174   virtual ~SceneView();
175
176 private:
177   /**
178    * @copydoc CustomActorImpl::OnSceneConnection()
179    */
180   void OnSceneConnection(int depth) override;
181
182   /**
183    * @copydoc CustomActorImpl::OnSceneDisconnection()
184    */
185   void OnSceneDisconnection() override;
186
187   /**
188    * @copydoc Toolkit::Control::OnInitialize()
189    */
190   void OnInitialize() override;
191
192   /**
193    * @copydoc Toolkit::Control::OnChildAdd()
194    */
195   void OnChildAdd(Actor& child) override;
196
197   /**
198    * @copydoc Toolkit::Control::OnChildRemove()
199    */
200   void OnChildRemove(Actor& child) override;
201
202   /**
203    * @copydoc Toolkit::Control::GetHeightForWidth()
204    */
205   float GetHeightForWidth(float width) override;
206
207   /**
208    * @copydoc Toolkit::Control::GetWidthForHeight()
209    */
210   float GetWidthForHeight(float height) override;
211
212   /**
213    * @copydoc Toolkit::Control::OnRelayout()
214    */
215   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
216
217   /**
218    * @copydoc Toolkit::Control::IsResourceReady()
219    */
220   bool IsResourceReady() const override;
221
222   /**
223    * @brief Changes main camera as a input camera
224    *
225    * @param camera CameraActor that will be a main camera of the SceneView
226    */
227   void UpdateCamera(CameraActor camera);
228
229   /**
230    * @brief Updates RenderTask to use selected camera and to make framebuffer
231    */
232   void UpdateRenderTask();
233
234   /**
235    * @brief Callback that will be called when window is resized.
236    */
237   void OnWindowResized(Window window, Window::WindowSize size);
238
239   /**
240    * @brief Updates camera's projection orientation according to the screen orientation.
241    */
242   void RotateCamera();
243
244 private:
245   Toolkit::Visual::Base mVisual;
246
247   /////////////////////////////////////////////////////////////
248   // FrameBuffer and Rendertask to render child objects as a 3D Scene
249   Dali::WeakHandle<Dali::Window>                           mWindow;
250   CameraActor                                              mDefaultCamera;
251   CameraActor                                              mSelectedCamera;
252   std::vector<CameraActor>                                 mCameras;
253   std::vector<Scene3D::Internal::ImageBasedLightObserver*> mItems;
254   Dali::FrameBuffer                                        mRenderTarget;
255   Dali::Texture                                            mTexture;
256   Dali::RenderTask                                         mRenderTask;
257   Layer                                                    mRootLayer;
258   int32_t                                                  mWindowOrientation;
259   Dali::Actor                                              mSkybox;
260   Quaternion                                               mSkyboxOrientation;
261   float                                                    mSkyboxIntensity{1.0f};
262
263   Dali::Texture mSpecularTexture;
264   Dali::Texture mDiffuseTexture;
265   float         mIblScaleFactor{1.0f};
266   bool          mUseFrameBuffer{false};
267   bool          mIBLResourceReady{true};
268   bool          mSkyboxResourceReady{true};
269
270   // TODO : Light Source
271 };
272
273 } // namespace Internal
274
275 // Helpers for public-api forwarding methods
276 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
277 {
278   DALI_ASSERT_ALWAYS(obj);
279   Dali::RefObject& handle = obj.GetImplementation();
280   return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
281 }
282
283 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
284 {
285   DALI_ASSERT_ALWAYS(obj);
286   const Dali::RefObject& handle = obj.GetImplementation();
287   return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
288 }
289
290 } // namespace Scene3D
291
292 } // namespace Dali
293
294 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H