Change ModelView to Model
[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/animation/animation.h>
27 #include <dali/public-api/object/weak-handle.h>
28 #include <dali/public-api/render-tasks/render-task.h>
29 #include <dali/public-api/rendering/frame-buffer.h>
30 #include <dali/public-api/rendering/texture.h>
31
32 // INTERNAL INCLUDES
33 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
34 #include <dali-scene3d/public-api/controls/model/model.h>
35
36 namespace Dali
37 {
38 namespace Scene3D
39 {
40 class SceneView;
41
42 namespace Internal
43 {
44 /**
45  * @brief Impl class for SceneView.
46  */
47 class SceneView : public Dali::Toolkit::Internal::Control
48 {
49 public:
50   /**
51    * @brief Creates a new SceneView.
52    *
53    * @return A public handle to the newly allocated SceneView.
54    */
55   static Dali::Scene3D::SceneView New();
56
57   /**
58    * @copydoc SceneView::AddCamera()
59    */
60   void AddCamera(Dali::CameraActor camera);
61
62   /**
63    * @copydoc SceneView::RemoveCamera()
64    */
65   void RemoveCamera(CameraActor camera);
66
67   /**
68    * @copydoc SceneView::GetCameraCount()
69    */
70   uint32_t GetCameraCount() const;
71
72   /**
73    * @copydoc SceneView::GetSelectedCamera()
74    */
75   CameraActor GetSelectedCamera() const;
76
77   /**
78    * @copydoc SceneView::GetCamera()
79    */
80   CameraActor GetCamera(uint32_t index) const;
81
82   /**
83    * @copydoc SceneView::GetCamera()
84    */
85   CameraActor GetCamera(const std::string& name) const;
86
87   /**
88    * @copydoc SceneView::SelectCamera()
89    */
90   void SelectCamera(uint32_t index);
91
92   /**
93    * @copydoc SceneView::SelectCamera()
94    */
95   void SelectCamera(const std::string& name);
96
97   /**
98    * @brief Register a Model.
99    * Some works like ibl setting should be applied on the only Model not the all child actors.
100    * SceneView contains child Model list to apply the works effectively.
101    *
102    * @param[in] model Model to be registered.
103    */
104   void RegisterModel(Scene3D::Model model);
105
106   /**
107    * @brief Unregister a Model
108    *
109    * @param[in] model Model to be unregistered.
110    */
111   void UnregisterModel(Scene3D::Model model);
112
113   /**
114    * @copydoc SceneView::SetImageBasedLightSource()
115    */
116   void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
117
118   /**
119    * @copydoc SceneView::SetImageBasedLightScaleFactor()
120    */
121   void SetImageBasedLightScaleFactor(float scaleFactor);
122
123   /**
124    * @copydoc SceneView::GetImageBasedLightScaleFactor()
125    */
126   float GetImageBasedLightScaleFactor() const;
127
128   /**
129    * @copydoc SceneView::UseFramebuffer()
130    */
131   void UseFramebuffer(bool useFramebuffer);
132
133   /**
134    * @copydoc SceneView::IsUsingFramebuffer()
135    */
136   bool IsUsingFramebuffer() const;
137
138 protected:
139   /**
140    * @brief Constructs a new SceneView.
141    */
142   SceneView();
143
144   /**
145    * A reference counted object may only be deleted by calling Unreference()
146    */
147   virtual ~SceneView();
148
149 private:
150   /**
151    * @copydoc CustomActorImpl::OnSceneConnection()
152    */
153   void OnSceneConnection(int depth) override;
154
155   /**
156    * @copydoc CustomActorImpl::OnSceneDisconnection()
157    */
158   void OnSceneDisconnection() override;
159
160   /**
161    * @copydoc Toolkit::Control::OnInitialize()
162    */
163   void OnInitialize() override;
164
165   /**
166    * @copydoc Toolkit::Control::OnChildAdd()
167    */
168   void OnChildAdd(Actor& child) override;
169
170   /**
171    * @copydoc Toolkit::Control::OnChildRemove()
172    */
173   void OnChildRemove(Actor& child) override;
174
175   /**
176    * @copydoc Toolkit::Control::GetHeightForWidth()
177    */
178   float GetHeightForWidth(float width) override;
179
180   /**
181    * @copydoc Toolkit::Control::GetWidthForHeight()
182    */
183   float GetWidthForHeight(float height) override;
184
185   /**
186    * @copydoc Toolkit::Control::OnRelayout()
187    */
188   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
189
190   /**
191    * @copydoc Toolkit::Control::IsResourceReady()
192    */
193   bool IsResourceReady() const override;
194
195   /**
196    * @brief Changes main camera as a input camera
197    *
198    * @param camera CameraActor that will be a main camera of the SceneView
199    */
200   void UpdateCamera(CameraActor camera);
201
202   /**
203    * @brief Updates RenderTask to use selected camera and to make framebuffer
204    */
205   void UpdateRenderTask();
206
207 private:
208   Toolkit::Visual::Base mVisual;
209
210   /////////////////////////////////////////////////////////////
211   // FrameBuffer and Rendertask to render child objects as a 3D Scene
212   CameraActor                 mDefaultCamera;
213   CameraActor                 mSelectedCamera;
214   std::vector<CameraActor>    mCameras;
215   std::vector<Scene3D::Model> mModels;
216   Dali::FrameBuffer           mRenderTarget;
217   Dali::Texture               mTexture;
218   Dali::RenderTask            mRenderTask;
219
220   Layer mRootLayer;
221
222   Dali::Texture mSpecularTexture;
223   Dali::Texture mDiffuseTexture;
224   float         mIblScaleFactor{1.0f};
225   bool          mUseFrameBuffer{false};
226   bool          mIBLResourceReady{true};
227
228   // TODO : Light Source
229 };
230
231 } // namespace Internal
232
233 // Helpers for public-api forwarding methods
234 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
235 {
236   DALI_ASSERT_ALWAYS(obj);
237   Dali::RefObject& handle = obj.GetImplementation();
238   return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
239 }
240
241 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
242 {
243   DALI_ASSERT_ALWAYS(obj);
244   const Dali::RefObject& handle = obj.GetImplementation();
245   return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
246 }
247
248 } // namespace Scene3D
249
250 } // namespace Dali
251
252 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H