Rotate camera when window orientation is changed.
[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/public-api/controls/model/model.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 a Model.
100    * Some works like ibl setting should be applied on the only Model not the all child actors.
101    * SceneView contains child Model list to apply the works effectively.
102    *
103    * @param[in] model Model to be registered.
104    */
105   void RegisterModel(Scene3D::Model model);
106
107   /**
108    * @brief Unregister a Model
109    *
110    * @param[in] model Model to be unregistered.
111    */
112   void UnregisterModel(Scene3D::Model model);
113
114   /**
115    * @copydoc SceneView::SetImageBasedLightSource()
116    */
117   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
118
119   /**
120    * @copydoc SceneView::SetImageBasedLightScaleFactor()
121    */
122   void SetImageBasedLightScaleFactor(float scaleFactor);
123
124   /**
125    * @copydoc SceneView::GetImageBasedLightScaleFactor()
126    */
127   float GetImageBasedLightScaleFactor() const;
128
129   /**
130    * @copydoc SceneView::UseFramebuffer()
131    */
132   void UseFramebuffer(bool useFramebuffer);
133
134   /**
135    * @copydoc SceneView::IsUsingFramebuffer()
136    */
137   bool IsUsingFramebuffer() const;
138
139 protected:
140   /**
141    * @brief Constructs a new SceneView.
142    */
143   SceneView();
144
145   /**
146    * A reference counted object may only be deleted by calling Unreference()
147    */
148   virtual ~SceneView();
149
150 private:
151   /**
152    * @copydoc CustomActorImpl::OnSceneConnection()
153    */
154   void OnSceneConnection(int depth) override;
155
156   /**
157    * @copydoc CustomActorImpl::OnSceneDisconnection()
158    */
159   void OnSceneDisconnection() override;
160
161   /**
162    * @copydoc Toolkit::Control::OnInitialize()
163    */
164   void OnInitialize() override;
165
166   /**
167    * @copydoc Toolkit::Control::OnChildAdd()
168    */
169   void OnChildAdd(Actor& child) override;
170
171   /**
172    * @copydoc Toolkit::Control::OnChildRemove()
173    */
174   void OnChildRemove(Actor& child) override;
175
176   /**
177    * @copydoc Toolkit::Control::GetHeightForWidth()
178    */
179   float GetHeightForWidth(float width) override;
180
181   /**
182    * @copydoc Toolkit::Control::GetWidthForHeight()
183    */
184   float GetWidthForHeight(float height) override;
185
186   /**
187    * @copydoc Toolkit::Control::OnRelayout()
188    */
189   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
190
191   /**
192    * @copydoc Toolkit::Control::IsResourceReady()
193    */
194   bool IsResourceReady() const override;
195
196   /**
197    * @brief Changes main camera as a input camera
198    *
199    * @param camera CameraActor that will be a main camera of the SceneView
200    */
201   void UpdateCamera(CameraActor camera);
202
203   /**
204    * @brief Updates RenderTask to use selected camera and to make framebuffer
205    */
206   void UpdateRenderTask();
207
208   /**
209    * @brief Callback that will be called when window is resized.
210    */
211   void OnWindowResized(Window window, Window::WindowSize size);
212
213   /**
214    * @brief Update camera's projection orientation according to the screen orientation.
215    */
216   void RotateCamera();
217
218 private:
219   Toolkit::Visual::Base mVisual;
220
221   /////////////////////////////////////////////////////////////
222   // FrameBuffer and Rendertask to render child objects as a 3D Scene
223   CameraActor                 mDefaultCamera;
224   CameraActor                 mSelectedCamera;
225   std::vector<CameraActor>    mCameras;
226   std::vector<Scene3D::Model> mModels;
227   Dali::FrameBuffer           mRenderTarget;
228   Dali::Texture               mTexture;
229   Dali::RenderTask            mRenderTask;
230   Layer                       mRootLayer;
231   int32_t                     mWindowOrientation;
232
233   Dali::Texture mSpecularTexture;
234   Dali::Texture mDiffuseTexture;
235   float         mIblScaleFactor{1.0f};
236   bool          mUseFrameBuffer{false};
237   bool          mIBLResourceReady{true};
238
239   // TODO : Light Source
240 };
241
242 } // namespace Internal
243
244 // Helpers for public-api forwarding methods
245 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
246 {
247   DALI_ASSERT_ALWAYS(obj);
248   Dali::RefObject& handle = obj.GetImplementation();
249   return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
250 }
251
252 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
253 {
254   DALI_ASSERT_ALWAYS(obj);
255   const Dali::RefObject& handle = obj.GetImplementation();
256   return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
257 }
258
259 } // namespace Scene3D
260
261 } // namespace Dali
262
263 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H