1 #ifndef DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
2 #define DALI_SCENE3D_INTERNAL_SCENE_VIEW_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali-toolkit/internal/visuals/image/image-visual.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/integration-api/adaptor-framework/scene-holder.h>
25 #include <dali/public-api/actors/camera-actor.h>
26 #include <dali/public-api/actors/layer.h>
27 #include <dali/public-api/adaptor-framework/window.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/object/weak-handle.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
32 #include <dali/public-api/rendering/texture.h>
35 #include <dali-scene3d/internal/common/environment-map-load-task.h>
36 #include <dali-scene3d/internal/common/light-observer.h>
37 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
38 #include <dali-scene3d/public-api/loader/shader-manager.h>
49 * @brief Impl class for SceneView.
51 class SceneView : public Dali::Toolkit::Internal::Control
55 * @brief Creates a new SceneView.
57 * @return A public handle to the newly allocated SceneView.
59 static Dali::Scene3D::SceneView New();
62 * @copydoc SceneView::AddCamera()
64 void AddCamera(Dali::CameraActor camera);
67 * @copydoc SceneView::RemoveCamera()
69 void RemoveCamera(CameraActor camera);
72 * @copydoc SceneView::GetCameraCount()
74 uint32_t GetCameraCount() const;
77 * @copydoc SceneView::GetSelectedCamera()
79 CameraActor GetSelectedCamera() const;
82 * @copydoc SceneView::GetCamera()
84 CameraActor GetCamera(uint32_t index) const;
87 * @copydoc SceneView::GetCamera()
89 CameraActor GetCamera(const std::string& name) const;
92 * @copydoc SceneView::SelectCamera()
94 void SelectCamera(uint32_t index);
97 * @copydoc SceneView::SelectCamera()
99 void SelectCamera(const std::string& name);
102 * @brief Register an item.
104 * Some works(e.g, lighting) of SceneView should be propagated to the child 3D items.
105 * SceneView can avoid unnecessary tree traversal to find 3D items by storing only 3D items as a list.
107 * @param[in] item scene observer to be registered.
109 void RegisterSceneItem(Scene3D::Internal::LightObserver* item);
112 * @brief Unregister an item
114 * @param[in] item scene observer to be unregistered.
116 void UnregisterSceneItem(Scene3D::Internal::LightObserver* item);
119 * @copydoc SceneView::SetImageBasedLightSource()
121 void SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor);
124 * @copydoc SceneView::SetImageBasedLightScaleFactor()
126 void SetImageBasedLightScaleFactor(float scaleFactor);
129 * @copydoc SceneView::GetImageBasedLightScaleFactor()
131 float GetImageBasedLightScaleFactor() const;
134 * @brief Adds a Light object to this SceneView.
135 * Multiple light object can be added on this SceneView
136 * But the number of lights those actually turned on has limitation.
137 * Scene3D::Light::GetMaximumEnabledLightCount() method can be used to know the maximum namber.
139 * @param[in] light Light object to be added.
141 void AddLight(Scene3D::Light light);
144 * @brief Removes a Light object to this SceneView.
145 * If the light is currently turned on, and SceneView has lights more than maximum number of enabled light.
146 * One of light in queue is turned on after this light is removed.
148 * @param[in] light Light object to be removed.
150 void RemoveLight(Scene3D::Light light);
153 * @brief Set a shadow to this scene by input light.
154 * Currently, SceneView supports only one shadow.
156 * @param[in] light Light object to make shadow.
157 * @note The shadow will be drawn if the input light is turn on in current scene.
159 void SetShadow(Scene3D::Light light);
162 * @brief Removes Shadow from this SceneView.
164 * @param[in] light Light object to be removed.
166 void RemoveShadow(Scene3D::Light light);
169 * @copydoc SceneView::GetActivatedLightCount()
171 uint32_t GetActivatedLightCount() const;
174 * @copydoc SceneView::UseFramebuffer()
176 void UseFramebuffer(bool useFramebuffer);
179 * @copydoc SceneView::IsUsingFramebuffer()
181 bool IsUsingFramebuffer() const;
184 * @copydoc SceneView::SetResolution()
186 void SetResolution(uint32_t width, uint32_t height);
189 * @copydoc SceneView::GetResolutionWidth()
191 uint32_t GetResolutionWidth();
194 * @copydoc SceneView::GetResolutionHeight()
196 uint32_t GetResolutionHeight();
199 * @copydoc SceneView::ResetResolution()
201 void ResetResolution();
204 * @copydoc SceneView::SetFramebufferMultiSamplingLevel()
206 void SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel);
209 * @copydoc SceneView::GetFramebufferMultiSamplingLevel()
211 uint8_t GetFramebufferMultiSamplingLevel() const;
214 * @copydoc SceneView::SetSkybox()
216 void SetSkybox(const std::string& skyboxUrl);
219 * @copydoc SceneView::SetSkyboxEnvironmentMapType()
221 void SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
224 * @copydoc SceneView::SetSkyboxIntensity()
226 void SetSkyboxIntensity(float intensity);
229 * @copydoc SceneView::GetSkyboxIntensity()
231 float GetSkyboxIntensity() const;
234 * @copydoc SceneView::SetSkyboxOrientation()
236 void SetSkyboxOrientation(const Quaternion& orientation);
239 * @copydoc SceneView::GetSkyboxOrientation()
241 Quaternion GetSkyboxOrientation() const;
244 * @brief Retrieves ShaderManager of this SceneView.
245 * @return ShaderManager of this SceneView.
247 Dali::Scene3D::Loader::ShaderManagerPtr GetShaderManager() const;
250 * @brief Updates shader uniforms about shadow.
251 * @param[in] light Light that makes shadow.
253 void UpdateShadowUniform(Scene3D::Light light);
256 * @brief Sets alpha mask url
257 * @param[in] alphaMaskUrl Url for alpha mask.
259 void SetAlphaMaskUrl(std::string& alphaMaskUrl);
262 * @brief Retrieves alpha mask url
263 * @return Alpha mask url.
265 std::string GetAlphaMaskUrl();
268 * @brief Sets mask content scale factor
269 * @param[in] maskContentScaleFactor Scale factor for mask content.
271 void SetMaskContentScaleFactor(float maskContentScaleFactor);
274 * @brief Retrieves mask content scale factor
275 * @return Scale factor for mask content.
277 float GetMaskContentScaleFactor();
280 * @brief Sets whether the rendered result will be crop to mask or not.
281 * @param[in] enableCropToMask True for crop rendered result to mask.
283 void EnableCropToMask(bool enableCropToMask);
286 * @brief Retrieves whether the crop to mask is enabled or not.
287 * @return True when rendered result is cropped to mask.
289 bool IsEnabledCropToMask();
294 * Called when a property of an object of this type is set.
295 * @param[in] object The object whose property is set.
296 * @param[in] index The property index.
297 * @param[in] value The new property value.
299 static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
302 * Called to retrieve a property of an object of this type.
303 * @param[in] object The object whose property is to be retrieved.
304 * @param[in] index The property index.
305 * @return The current value of the property.
307 static Property::Value GetProperty(BaseObject* object, Property::Index index);
311 * @brief Constructs a new SceneView.
316 * A reference counted object may only be deleted by calling Unreference()
318 virtual ~SceneView();
322 * @copydoc CustomActorImpl::OnSceneConnection()
324 void OnSceneConnection(int depth) override;
327 * @copydoc CustomActorImpl::OnSceneDisconnection()
329 void OnSceneDisconnection() override;
332 * @copydoc Toolkit::Control::OnInitialize()
334 void OnInitialize() override;
337 * @copydoc Toolkit::Control::OnChildAdd()
339 void OnChildAdd(Actor& child) override;
342 * @copydoc Toolkit::Control::OnChildRemove()
344 void OnChildRemove(Actor& child) override;
347 * @copydoc Toolkit::Control::GetHeightForWidth()
349 float GetHeightForWidth(float width) override;
352 * @copydoc Toolkit::Control::GetWidthForHeight()
354 float GetWidthForHeight(float height) override;
357 * @copydoc Toolkit::Control::OnRelayout()
359 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
362 * @copydoc Toolkit::Control::IsResourceReady()
364 bool IsResourceReady() const override;
367 * @brief Changes main camera as a input camera
369 * @param camera CameraActor that will be a main camera of the SceneView
371 void UpdateCamera(CameraActor camera);
374 * @brief Updates RenderTask to use selected camera and to make framebuffer
376 void UpdateRenderTask();
379 * @brief Callback that will be called when window is resized.
381 void OnWindowResized(Window window, Window::WindowSize size);
384 * @brief Updates camera's projection orientation according to the screen orientation.
389 * @brief UpdateSkybox with skybox url and skybox environment map type.
391 * @param[in] skyboxUrl image url for skybox.
392 * @param[in] skyboxEnvironmentMapType The environment type of skybox.
394 void UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType);
397 * @brief Asynchronously skybox loading finished.
399 void OnSkyboxLoadComplete();
402 * @brief Asynchronously ibl diffusel image loading finished.
404 void OnIblDiffuseLoadComplete();
407 * @brief Asynchronously ibl specular image loading finished.
409 void OnIblSpecularLoadComplete();
412 * @brief Asynchronously ibl loading finished.
414 void OnIblLoadComplete();
417 * @brief Notify the changes of Ibl textures to the child items.
419 void NotifyImageBasedLightTextureChange();
422 * @brief Update shadowMap framebuffer when the size should be changed.
423 * @param[in] shadowMapSize The size of shadowMap texture. The texture's width and hight is equal.
425 void UpdateShadowMapBuffer(uint32_t shadowMapSize);
428 Toolkit::Visual::Base mVisual;
430 /////////////////////////////////////////////////////////////
431 // FrameBuffer and Rendertask to render child objects as a 3D Scene
432 Dali::WeakHandle<Dali::Window> mWindow;
433 Integration::SceneHolder mSceneHolder;
434 CameraActor mDefaultCamera;
435 CameraActor mSelectedCamera;
436 std::vector<CameraActor> mCameras;
437 std::vector<Scene3D::Internal::LightObserver*> mItems;
438 Dali::FrameBuffer mFrameBuffer;
439 Dali::Texture mTexture;
440 Dali::RenderTask mRenderTask;
442 int32_t mWindowOrientation;
444 Quaternion mSkyboxOrientation;
445 float mSkyboxIntensity{1.0f};
446 uint8_t mFrameBufferMultiSamplingLevel{0u};
448 bool mWindowSizeChanged{false};
449 uint32_t mWindowWidth{0};
450 uint32_t mWindowHeight{0};
453 std::string mAlphaMaskUrl;
454 float mMaskContentScaleFactor{1.0f};
455 bool mCropToMask{true};
456 bool mMaskingPropertyChanged{false};
459 Dali::Scene3D::Loader::ShaderManagerPtr mShaderManager;
462 std::vector<std::pair<Scene3D::Light, bool>> mLights; // Pair of Light object and flag that denotes the light is currently activated or not.
463 Dali::FrameBuffer mShadowFrameBuffer;
464 Dali::RenderTask mShadowMapRenderTask;
465 Scene3D::Light mShadowLight;
466 Dali::Texture mShadowTexture;
468 // Asynchronous Loading.
469 EnvironmentMapLoadTaskPtr mSkyboxLoadTask;
470 EnvironmentMapLoadTaskPtr mIblDiffuseLoadTask;
471 EnvironmentMapLoadTaskPtr mIblSpecularLoadTask;
472 std::string mSkyboxUrl;
473 std::string mDiffuseIblUrl;
474 std::string mSpecularIblUrl;
476 Scene3D::EnvironmentMapType mSkyboxEnvironmentMapType{Scene3D::EnvironmentMapType::AUTO};
477 Dali::Texture mSkyboxTexture;
478 Dali::Texture mDiffuseTexture;
479 Dali::Texture mSpecularTexture;
480 float mIblScaleFactor{1.0f};
481 uint32_t mSpecularMipmapLevels{1u};
482 bool mUseFrameBuffer{false};
483 bool mSkyboxResourceReady{true};
484 bool mIblDiffuseResourceReady{true};
485 bool mIblSpecularResourceReady{true};
486 bool mSkyboxDirty{false};
487 bool mIblDiffuseDirty{false};
488 bool mIblSpecularDirty{false};
491 } // namespace Internal
493 // Helpers for public-api forwarding methods
494 inline Dali::Scene3D::Internal::SceneView& GetImpl(Dali::Scene3D::SceneView& obj)
496 DALI_ASSERT_ALWAYS(obj);
497 Dali::RefObject& handle = obj.GetImplementation();
498 return static_cast<Dali::Scene3D::Internal::SceneView&>(handle);
501 inline const Dali::Scene3D::Internal::SceneView& GetImpl(const Dali::Scene3D::SceneView& obj)
503 DALI_ASSERT_ALWAYS(obj);
504 const Dali::RefObject& handle = obj.GetImplementation();
505 return static_cast<const Dali::Scene3D::Internal::SceneView&>(handle);
508 } // namespace Scene3D
512 #endif // DALI_SCENE3D_INTERNAL_SCENE_VIEW_H