Merge "Add GetLineBoundingRectangle API." into devel/master
[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   /**
140    * @copydoc SceneView::SetSkybox()
141    */
142   void SetSkybox(const std::string& skyboxUrl);
143
144   /**
145    * @copydoc SceneView::SetSkyboxIntensity()
146    */
147   void SetSkyboxIntensity(float intensity);
148
149   /**
150    * @copydoc SceneView::GetSkyboxIntensity()
151    */
152   float GetSkyboxIntensity() const;
153
154   /**
155    * @copydoc SceneView::SetSkyboxOrientation()
156    */
157   void SetSkyboxOrientation(const Quaternion& orientation);
158
159   /**
160    * @copydoc SceneView::GetSkyboxOrientation()
161    */
162   Quaternion GetSkyboxOrientation() const;
163
164 protected:
165   /**
166    * @brief Constructs a new SceneView.
167    */
168   SceneView();
169
170   /**
171    * A reference counted object may only be deleted by calling Unreference()
172    */
173   virtual ~SceneView();
174
175 private:
176   /**
177    * @copydoc CustomActorImpl::OnSceneConnection()
178    */
179   void OnSceneConnection(int depth) override;
180
181   /**
182    * @copydoc CustomActorImpl::OnSceneDisconnection()
183    */
184   void OnSceneDisconnection() override;
185
186   /**
187    * @copydoc Toolkit::Control::OnInitialize()
188    */
189   void OnInitialize() override;
190
191   /**
192    * @copydoc Toolkit::Control::OnChildAdd()
193    */
194   void OnChildAdd(Actor& child) override;
195
196   /**
197    * @copydoc Toolkit::Control::OnChildRemove()
198    */
199   void OnChildRemove(Actor& child) override;
200
201   /**
202    * @copydoc Toolkit::Control::GetHeightForWidth()
203    */
204   float GetHeightForWidth(float width) override;
205
206   /**
207    * @copydoc Toolkit::Control::GetWidthForHeight()
208    */
209   float GetWidthForHeight(float height) override;
210
211   /**
212    * @copydoc Toolkit::Control::OnRelayout()
213    */
214   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
215
216   /**
217    * @copydoc Toolkit::Control::IsResourceReady()
218    */
219   bool IsResourceReady() const override;
220
221   /**
222    * @brief Changes main camera as a input camera
223    *
224    * @param camera CameraActor that will be a main camera of the SceneView
225    */
226   void UpdateCamera(CameraActor camera);
227
228   /**
229    * @brief Updates RenderTask to use selected camera and to make framebuffer
230    */
231   void UpdateRenderTask();
232
233   /**
234    * @brief Callback that will be called when window is resized.
235    */
236   void OnWindowResized(Window window, Window::WindowSize size);
237
238   /**
239    * @brief Update camera's projection orientation according to the screen orientation.
240    */
241   void RotateCamera();
242
243 private:
244   Toolkit::Visual::Base mVisual;
245
246   /////////////////////////////////////////////////////////////
247   // FrameBuffer and Rendertask to render child objects as a 3D Scene
248   CameraActor                 mDefaultCamera;
249   CameraActor                 mSelectedCamera;
250   std::vector<CameraActor>    mCameras;
251   std::vector<Scene3D::Model> mModels;
252   Dali::FrameBuffer           mRenderTarget;
253   Dali::Texture               mTexture;
254   Dali::RenderTask            mRenderTask;
255   Layer                       mRootLayer;
256   int32_t                     mWindowOrientation;
257   Dali::Actor                 mSkybox;
258   Quaternion                  mSkyboxOrientation;
259   float                       mSkyboxIntensity{1.0f};
260
261   Dali::Texture mSpecularTexture;
262   Dali::Texture mDiffuseTexture;
263   float         mIblScaleFactor{1.0f};
264   bool          mUseFrameBuffer{false};
265   bool          mIBLResourceReady{true};
266   bool          mSkyboxResourceReady{true};
267
268   // TODO : Light Source
269 };
270
271 } // namespace Internal
272
273 // Helpers for public-api forwarding methods
274 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
275 {
276   DALI_ASSERT_ALWAYS(obj);
277   Dali::RefObject& handle = obj.GetImplementation();
278   return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
279 }
280
281 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
282 {
283   DALI_ASSERT_ALWAYS(obj);
284   const Dali::RefObject& handle = obj.GetImplementation();
285   return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
286 }
287
288 } // namespace Scene3D
289
290 } // namespace Dali
291
292 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H