Add ResourceReady for Control
[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/model-view/model-view.h>
34 #include <dali-scene3d/public-api/controls/scene-view/scene-view.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();
71
72   /**
73    * @copydoc SceneView::GetSelectedCamera()
74    */
75   CameraActor GetSelectedCamera();
76
77   /**
78    * @copydoc SceneView::GetCamera()
79    */
80   CameraActor GetCamera(uint32_t index);
81
82   /**
83    * @copydoc SceneView::GetCamera()
84    */
85   CameraActor GetCamera(const std::string& name);
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 ModelView.
99    * Some works like ibl setting should be applied on the only ModelView not the all child actors.
100    * SceneView contains child ModelView list to apply the works effectively.
101    *
102    * @param[in] modelView ModelView to be registered.
103    */
104   void RegisterModelView(Scene3D::ModelView modelView);
105
106   /**
107    * @brief Unregister a ModelView
108    *
109    * @param[in] modelView ModelView to be unregistered.
110    */
111   void UnregisterModelView(Scene3D::ModelView modelView);
112
113   /**
114    * @copydoc SceneView::SetImageBasedLightSource()
115    */
116   void SetImageBasedLightSource(const std::string& diffuse, const std::string& specular, float scaleFactor);
117
118   /**
119    * @copydoc SceneView::UseFramebuffer()
120    */
121   void UseFramebuffer(bool useFramebuffer);
122
123   /**
124    * @copydoc SceneView::IsUsingFramebuffer()
125    */
126   bool IsUsingFramebuffer();
127
128 protected:
129   /**
130    * @brief Constructs a new SceneView.
131    */
132   SceneView();
133
134   /**
135    * A reference counted object may only be deleted by calling Unreference()
136    */
137   virtual ~SceneView();
138
139 private:
140   /**
141    * @copydoc CustomActorImpl::OnSceneConnection()
142    */
143   void OnSceneConnection(int depth) override;
144
145   /**
146    * @copydoc CustomActorImpl::OnSceneDisconnection()
147    */
148   void OnSceneDisconnection() override;
149
150   /**
151    * @copydoc Toolkit::Control::OnInitialize()
152    */
153   void OnInitialize() override;
154
155   /**
156    * @copydoc Toolkit::Control::OnChildAdd()
157    */
158   void OnChildAdd(Actor& child) override;
159
160   /**
161    * @copydoc Toolkit::Control::OnChildRemove()
162    */
163   void OnChildRemove(Actor& child) override;
164
165   /**
166    * @copydoc Toolkit::Control::GetHeightForWidth()
167    */
168   float GetHeightForWidth(float width) override;
169
170   /**
171    * @copydoc Toolkit::Control::GetWidthForHeight()
172    */
173   float GetWidthForHeight(float height) override;
174
175   /**
176    * @copydoc Toolkit::Control::OnRelayout()
177    */
178   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
179
180   /**
181    * @copydoc Toolkit::Control::IsResourceReady()
182    */
183   bool IsResourceReady() const override;
184
185   /**
186    * @brief Changes main camera as a input camera
187    *
188    * @param camera CameraActor that will be a main camera of the SceneView
189    */
190   void UpdateCamera(CameraActor camera);
191
192   /**
193    * @brief Updates RenderTask to use selected camera and to make framebuffer
194    */
195   void UpdateRenderTask();
196
197 private:
198   Toolkit::Visual::Base mVisual;
199
200   /////////////////////////////////////////////////////////////
201   // FrameBuffer and Rendertask to render child objects as a 3D Scene
202   CameraActor                     mDefaultCamera;
203   CameraActor                     mSelectedCamera;
204   std::vector<CameraActor>        mCameras;
205   std::vector<Scene3D::ModelView> mModels;
206   Dali::FrameBuffer               mRenderTarget;
207   Dali::Texture                   mTexture;
208   Dali::RenderTask                mRenderTask;
209
210   Layer mRootLayer;
211
212   Dali::Texture mSpecularTexture;
213   Dali::Texture mDiffuseTexture;
214   float         mIblScaleFactor{1.0f};
215   bool          mUseFrameBuffer{false};
216   bool          mIBLResourceReady{true};
217
218   // TODO : Light Source
219 };
220
221 } // namespace Internal
222
223 // Helpers for public-api forwarding methods
224 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
225 {
226   DALI_ASSERT_ALWAYS(obj);
227   Dali::RefObject& handle = obj.GetImplementation();
228   return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
229 }
230
231 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
232 {
233   DALI_ASSERT_ALWAYS(obj);
234   const Dali::RefObject& handle = obj.GetImplementation();
235   return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
236 }
237
238 } // namespace Scene3D
239
240 } // namespace Dali
241
242 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H