2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-scene3d/internal/controls/scene-view/scene-view-impl.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/public-api/image-loader/image-url.h>
27 #include <dali-toolkit/public-api/image-loader/image.h>
28 #include <dali/devel-api/actors/camera-actor-devel.h>
29 #include <dali/devel-api/adaptor-framework/window-devel.h>
30 #include <dali/devel-api/common/stage.h>
31 #include <dali/devel-api/rendering/frame-buffer-devel.h>
32 #include <dali/integration-api/adaptor-framework/adaptor.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/public-api/math/math-utils.h>
35 #include <dali/public-api/object/type-registry-helper.h>
36 #include <dali/public-api/object/type-registry.h>
37 #include <string_view>
40 #include <dali-scene3d/internal/controls/model/model-impl.h>
41 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
42 #include <dali-scene3d/internal/light/light-impl.h>
56 return Scene3D::SceneView::New();
59 // Setup properties, signals and actions using the type-registry.
60 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::SceneView, Toolkit::Control, Create);
61 DALI_TYPE_REGISTRATION_END()
63 Property::Index RENDERING_BUFFER = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
64 constexpr int32_t DEFAULT_ORIENTATION = 0;
65 constexpr int32_t INVALID_INDEX = -1;
67 static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
69 Dali::Actor CreateSkybox()
76 Vertex skyboxVertices[] = {
78 {Vector3(-1.0f, 1.0f, -1.0f)},
79 {Vector3(-1.0f, -1.0f, -1.0f)},
80 {Vector3(1.0f, -1.0f, -1.0f)},
81 {Vector3(1.0f, -1.0f, -1.0f)},
82 {Vector3(1.0f, 1.0f, -1.0f)},
83 {Vector3(-1.0f, 1.0f, -1.0f)},
86 {Vector3(-1.0f, -1.0f, 1.0f)},
87 {Vector3(-1.0f, -1.0f, -1.0f)},
88 {Vector3(-1.0f, 1.0f, -1.0f)},
89 {Vector3(-1.0f, 1.0f, -1.0f)},
90 {Vector3(-1.0f, 1.0f, 1.0f)},
91 {Vector3(-1.0f, -1.0f, 1.0f)},
94 {Vector3(1.0f, -1.0f, -1.0f)},
95 {Vector3(1.0f, -1.0f, 1.0f)},
96 {Vector3(1.0f, 1.0f, 1.0f)},
97 {Vector3(1.0f, 1.0f, 1.0f)},
98 {Vector3(1.0f, 1.0f, -1.0f)},
99 {Vector3(1.0f, -1.0f, -1.0f)},
102 {Vector3(-1.0f, -1.0f, 1.0f)},
103 {Vector3(-1.0f, 1.0f, 1.0f)},
104 {Vector3(1.0f, 1.0f, 1.0f)},
105 {Vector3(1.0f, 1.0f, 1.0f)},
106 {Vector3(1.0f, -1.0f, 1.0f)},
107 {Vector3(-1.0f, -1.0f, 1.0f)},
110 {Vector3(-1.0f, 1.0f, -1.0f)},
111 {Vector3(1.0f, 1.0f, -1.0f)},
112 {Vector3(1.0f, 1.0f, 1.0f)},
113 {Vector3(1.0f, 1.0f, 1.0f)},
114 {Vector3(-1.0f, 1.0f, 1.0f)},
115 {Vector3(-1.0f, 1.0f, -1.0f)},
118 {Vector3(-1.0f, -1.0f, -1.0f)},
119 {Vector3(-1.0f, -1.0f, 1.0f)},
120 {Vector3(1.0f, -1.0f, -1.0f)},
121 {Vector3(1.0f, -1.0f, -1.0f)},
122 {Vector3(-1.0f, -1.0f, 1.0f)},
123 {Vector3(1.0f, -1.0f, 1.0f)}};
125 Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
126 vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));
128 Dali::Geometry skyboxGeometry = Geometry::New();
129 skyboxGeometry.AddVertexBuffer(vertexBuffer);
130 skyboxGeometry.SetType(Geometry::TRIANGLES);
132 Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
133 Dali::Renderer skyboxRenderer;
134 skyboxRenderer = Renderer::New(skyboxGeometry, shaderSkybox);
135 skyboxRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2.0f);
136 // Enables the depth test.
137 skyboxRenderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON);
138 // The fragment shader will run only is those pixels that have the max depth value.
139 skyboxRenderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
141 Dali::Actor skyboxActor = Actor::New();
142 skyboxActor.SetProperty(Dali::Actor::Property::NAME, "SkyBox");
143 skyboxActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
144 skyboxActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
145 skyboxActor.AddRenderer(skyboxRenderer);
149 } // anonymous namespace
151 SceneView::SceneView()
152 : Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
153 mWindowOrientation(DEFAULT_ORIENTATION),
155 mSkyboxOrientation(Quaternion()),
156 mSkyboxIntensity(1.0f),
157 mShaderManager(new Scene3D::Loader::ShaderManager())
161 SceneView::~SceneView()
163 if(Dali::Adaptor::IsAvailable())
165 if(mIblDiffuseLoadTask)
167 Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
168 mIblDiffuseLoadTask.Reset();
170 if(mIblSpecularLoadTask)
172 Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
173 mIblSpecularLoadTask.Reset();
177 Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
178 mSkyboxLoadTask.Reset();
183 Dali::Scene3D::SceneView SceneView::New()
185 SceneView* impl = new SceneView();
187 Dali::Scene3D::SceneView handle = Dali::Scene3D::SceneView(*impl);
189 // Second-phase init of the implementation
190 // This can only be done after the CustomActor connection has been made...
196 void SceneView::AddCamera(CameraActor camera)
202 UpdateCamera(camera);
204 mCameras.push_back(camera);
208 void SceneView::RemoveCamera(CameraActor camera)
210 if(camera == mDefaultCamera)
212 DALI_LOG_ERROR("Default Camera cannot removed.\n");
218 for(uint32_t i = 0; i < mCameras.size(); ++i)
220 if(mCameras[i] == camera)
222 mCameras.erase(mCameras.begin() + i);
227 if(mSelectedCamera == camera)
229 CameraActor newCurrentCamera = *mCameras.begin();
230 UpdateCamera(newCurrentCamera);
235 uint32_t SceneView::GetCameraCount() const
237 return mCameras.size();
240 CameraActor SceneView::GetSelectedCamera() const
242 return mSelectedCamera;
245 CameraActor SceneView::GetCamera(uint32_t index) const
247 if(index < mCameras.size())
249 return mCameras[index];
251 DALI_LOG_ERROR("Input index is out of bounds\n");
252 return CameraActor();
255 CameraActor SceneView::GetCamera(const std::string& name) const
257 CameraActor returnCamera;
258 for(auto&& camera : mCameras)
260 if(camera.GetProperty<std::string>(Actor::Property::NAME) == name)
262 returnCamera = camera;
269 void SceneView::SelectCamera(uint32_t index)
271 UpdateCamera(GetCamera(index));
274 void SceneView::SelectCamera(const std::string& name)
276 UpdateCamera(GetCamera(name));
279 void SceneView::RegisterSceneItem(Scene3D::Internal::LightObserver* item)
283 item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
285 if(mActivatedLightCount > 0)
287 uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
288 for(uint32_t i = 0; i < maxLightCount; ++i)
290 if(mActivatedLights[i])
292 item->NotifyLightAdded(i, mActivatedLights[i]);
296 mItems.push_back(item);
300 void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
304 for(uint32_t i = 0; i < mItems.size(); ++i)
306 if(mItems[i] == item)
308 if(mActivatedLightCount > 0)
310 uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
311 for(uint32_t i = 0; i < maxLightCount; ++i)
313 if(mActivatedLights[i])
315 item->NotifyLightRemoved(i);
319 mItems.erase(mItems.begin() + i);
326 void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor)
328 bool needIblReset = false;
329 bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
330 if(mDiffuseIblUrl != diffuseUrl)
332 mDiffuseIblUrl = diffuseUrl;
333 if(mDiffuseIblUrl.empty())
339 mIblDiffuseDirty = true;
340 mIblDiffuseResourceReady = false;
344 if(mSpecularIblUrl != specularUrl)
346 mSpecularIblUrl = specularUrl;
347 if(mSpecularIblUrl.empty())
353 mIblSpecularDirty = true;
354 mIblSpecularResourceReady = false;
358 // If one or both of diffuse url and specular url are empty,
359 // we don't need to request to load texture.
362 if(mIblDiffuseLoadTask)
364 Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
365 mIblDiffuseLoadTask.Reset();
368 if(mIblSpecularLoadTask)
370 Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
371 mIblSpecularLoadTask.Reset();
374 mIblDiffuseDirty = false;
375 mIblSpecularDirty = false;
376 mIblDiffuseResourceReady = true;
377 mIblSpecularResourceReady = true;
379 mDiffuseTexture.Reset();
380 mSpecularTexture.Reset();
382 mSpecularMipmapLevels = 1u;
383 NotifyImageBasedLightTextureChange();
387 if(isOnScene && mIblDiffuseDirty)
389 if(mIblDiffuseLoadTask)
391 Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
392 mIblDiffuseLoadTask.Reset();
394 mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
395 Dali::AsyncTaskManager::Get().AddTask(mIblDiffuseLoadTask);
396 mIblDiffuseDirty = false;
399 if(isOnScene && mIblSpecularDirty)
401 if(mIblSpecularLoadTask)
403 Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
404 mIblSpecularLoadTask.Reset();
406 mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
407 Dali::AsyncTaskManager::Get().AddTask(mIblSpecularLoadTask);
408 mIblSpecularDirty = false;
412 if(!Dali::Equals(mIblScaleFactor, scaleFactor))
414 SetImageBasedLightScaleFactor(scaleFactor);
417 // If diffuse and specular textures are already loaded, emits resource ready signal here.
418 if(IsResourceReady())
420 Control::SetResourceReady();
424 void SceneView::SetImageBasedLightScaleFactor(float scaleFactor)
426 mIblScaleFactor = scaleFactor;
427 for(auto&& item : mItems)
431 item->NotifyImageBasedLightScaleFactor(scaleFactor);
436 float SceneView::GetImageBasedLightScaleFactor() const
438 return mIblScaleFactor;
441 void SceneView::AddLight(Scene3D::Light light)
443 bool enabled = AddLightInternal(light);
444 mLights.push_back(std::make_pair(light, enabled));
447 void SceneView::RemoveLight(Scene3D::Light light)
449 if(mActivatedLights.empty())
454 bool needToDisable = false;
455 for(uint32_t i = 0; i < mLights.size(); ++i)
457 if(mLights[i].first == light)
459 // If mLights[i].second is true, it means the light is currently activated in Scene.
460 // Then it should be removed from mActivatedLights list too.
461 needToDisable = mLights[i].second;
462 mLights.erase(mLights.begin() + i);
467 uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
470 uint32_t removedIndex = RemoveLightInternal(light);
471 if(mActivatedLightCount < maxNumberOfLight && mLights.size() >= maxNumberOfLight)
473 for(auto&& lightItem : mLights)
475 if(lightItem.second == false)
477 lightItem.second = AddLightInternal(lightItem.first);
483 // To remove empty entity of mActivatedLights, moves last object to empty position.
484 // Because one Light is removed, mActivatedLights[mActivatedLightCount] is current last object of the list.
485 if(!mActivatedLights[removedIndex] && mActivatedLightCount > 0 && removedIndex < mActivatedLightCount)
487 Scene3D::Light reorderingLight = mActivatedLights[mActivatedLightCount];
488 RemoveLightInternal(reorderingLight);
489 AddLightInternal(reorderingLight);
494 uint32_t SceneView::GetActivatedLightCount() const
496 return mActivatedLightCount;
499 void SceneView::UseFramebuffer(bool useFramebuffer)
501 if(mUseFrameBuffer != useFramebuffer)
503 mUseFrameBuffer = useFramebuffer;
508 bool SceneView::IsUsingFramebuffer() const
510 return mUseFrameBuffer;
513 void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
515 if(mFrameBufferMultiSamplingLevel != multiSamplingLevel)
517 mFrameBufferMultiSamplingLevel = multiSamplingLevel;
519 // Create new framebuffer with changed multiSamplingLevel.
520 if(mRenderTask && mFrameBuffer && mTexture)
522 Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
524 mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
525 mFrameBuffer.AttachColorTexture(mTexture);
526 DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
527 mRenderTask.SetFrameBuffer(mFrameBuffer);
529 // Note : we don't need to create new visual since visual's url is depend on mTexture.
534 uint8_t SceneView::GetFramebufferMultiSamplingLevel() const
536 return mFrameBufferMultiSamplingLevel;
539 void SceneView::SetSkybox(const std::string& skyboxUrl)
541 if(mSkyboxUrl != skyboxUrl)
543 UpdateSkybox(skyboxUrl, mSkyboxEnvironmentMapType);
547 void SceneView::SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
549 if(mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
551 UpdateSkybox(mSkyboxUrl, skyboxEnvironmentMapType);
555 void SceneView::SetSkyboxIntensity(float intensity)
557 mSkyboxIntensity = intensity;
560 DALI_LOG_ERROR("Intensity should be greater than or equal to 0.\n");
561 mSkyboxIntensity = 0.0f;
566 mSkybox.RegisterProperty(SKYBOX_INTENSITY_STRING.data(), mSkyboxIntensity);
570 float SceneView::GetSkyboxIntensity() const
572 return mSkyboxIntensity;
575 void SceneView::SetSkyboxOrientation(const Quaternion& orientation)
577 mSkyboxOrientation = orientation;
580 mSkybox.SetProperty(Dali::Actor::Property::ORIENTATION, orientation);
584 Quaternion SceneView::GetSkyboxOrientation() const
586 return mSkyboxOrientation;
589 Dali::Scene3D::Loader::ShaderManagerPtr SceneView::GetShaderManager() const
591 return mShaderManager;
594 ///////////////////////////////////////////////////////////
599 void SceneView::OnSceneConnection(int depth)
601 // If diffuse and specular url is not valid, IBL does not need to be loaded.
602 if(!mDiffuseIblUrl.empty() && !mSpecularIblUrl.empty())
604 SetImageBasedLightSource(mDiffuseIblUrl, mSpecularIblUrl, mIblScaleFactor);
607 if(!mSkyboxUrl.empty())
609 UpdateSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
612 Window window = DevelWindow::Get(Self());
615 // Only for on-screen window
616 window.ResizeSignal().Connect(this, &SceneView::OnWindowResized);
619 mWindowOrientation = DevelWindow::GetPhysicalOrientation(window);
622 // On-screen / Off-screen window
623 mSceneHolder = Integration::SceneHolder::Get(Self());
626 RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
627 mRenderTask = taskList.CreateTask();
628 mRenderTask.SetSourceActor(mRootLayer);
629 mRenderTask.SetExclusive(true);
630 mRenderTask.SetInputEnabled(true);
631 mRenderTask.SetCullMode(false);
632 mRenderTask.SetScreenToFrameBufferMappingActor(Self());
637 Control::OnSceneConnection(depth);
640 void SceneView::OnSceneDisconnection()
644 Window window = mWindow.GetHandle();
647 window.ResizeSignal().Disconnect(this, &SceneView::OnWindowResized);
655 RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
656 taskList.RemoveTask(mRenderTask);
659 mSceneHolder.Reset();
661 mFrameBuffer.Reset();
663 Control::OnSceneDisconnection();
666 void SceneView::OnInitialize()
669 mRootLayer = Layer::New();
670 mRootLayer.SetProperty(Layer::Property::BEHAVIOR, Layer::LAYER_3D);
671 mRootLayer.SetProperty(Layer::Property::DEPTH_TEST, true);
672 // The models in the SceneView should be have independent coordinate with DALi default coordinate.
673 mRootLayer.SetProperty(Dali::Actor::Property::INHERIT_POSITION, false);
674 mRootLayer.SetProperty(Dali::Actor::Property::INHERIT_ORIENTATION, false);
675 mRootLayer.SetProperty(Dali::Actor::Property::INHERIT_SCALE, false);
676 self.Add(mRootLayer);
678 mDefaultCamera = Dali::CameraActor::New3DCamera();
679 mDefaultCamera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
680 mDefaultCamera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
681 AddCamera(mDefaultCamera);
682 UpdateCamera(mDefaultCamera);
685 void SceneView::OnChildAdd(Actor& child)
687 if(child != mRootLayer)
689 mRootLayer.Add(child);
691 Control::OnChildAdd(child);
694 void SceneView::OnChildRemove(Actor& child)
696 mRootLayer.Remove(child);
697 Control::OnChildRemove(child);
700 float SceneView::GetHeightForWidth(float width)
703 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
704 return Control::GetHeightForWidth(width) + padding.top + padding.bottom;
707 float SceneView::GetWidthForHeight(float height)
710 padding = Self().GetProperty<Extents>(Toolkit::Control::Property::PADDING);
711 return Control::GetWidthForHeight(height) + padding.start + padding.end;
714 void SceneView::OnRelayout(const Vector2& size, RelayoutContainer& container)
716 Control::OnRelayout(size, container);
717 // Change canvas size of camera actor.
721 bool SceneView::IsResourceReady() const
723 return mIblDiffuseResourceReady && mIblSpecularResourceReady && mSkyboxResourceReady;
726 void SceneView::UpdateCamera(CameraActor camera)
730 if(mSelectedCamera && mSelectedCamera.GetParent())
732 mSelectedCamera.Unparent();
734 mRootLayer.Add(camera);
737 mSelectedCamera = camera;
741 void SceneView::UpdateRenderTask()
745 if(mSelectedCamera != mRenderTask.GetCameraActor())
747 mRenderTask.SetCameraActor(mSelectedCamera);
750 Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
751 const float aspectRatio = size.width / size.height;
752 mSelectedCamera.SetAspectRatio(aspectRatio);
756 Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
757 if(!currentFrameBuffer ||
758 !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), size.width) ||
759 !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height))
761 mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_COLOR);
762 mRenderTask.ResetViewportGuideActor();
763 mRenderTask.SetViewport(Dali::Viewport(Vector4::ZERO));
765 // create offscreen buffer of new size to render our child actors to
766 mTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(size.width), unsigned(size.height));
767 mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
768 mFrameBuffer.AttachColorTexture(mTexture);
769 DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
770 Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(mFrameBuffer, 0u);
772 Property::Map imagePropertyMap;
773 imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
774 imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, imageUrl.GetUrl());
775 // To flip rendered scene without CameraActor::SetInvertYAxis() to avoid backface culling.
776 imagePropertyMap.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, Vector4(0.0f, 1.0f, 1.0f, -1.0f));
777 mVisual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap);
779 Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
781 mRenderTask.SetFrameBuffer(mFrameBuffer);
782 mRenderTask.SetClearEnabled(true);
783 mRenderTask.SetClearColor(Color::TRANSPARENT);
788 mRenderTask.SetViewportGuideActor(Self());
789 if(mRenderTask.GetFrameBuffer())
791 mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA);
792 FrameBuffer framebuffer;
793 mRenderTask.SetFrameBuffer(framebuffer);
794 mRenderTask.SetClearEnabled(false);
796 Toolkit::DevelControl::UnregisterVisual(*this, RENDERING_BUFFER);
799 mFrameBuffer.Reset();
808 void SceneView::OnWindowResized(Window window, Window::WindowSize size)
810 mWindowOrientation = DevelWindow::GetPhysicalOrientation(window);
814 void SceneView::RotateCamera()
818 DevelCameraActor::RotateProjection(mSelectedCamera, DEFAULT_ORIENTATION);
822 DevelCameraActor::RotateProjection(mSelectedCamera, mWindowOrientation);
826 void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
828 bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
829 if(mSkyboxUrl != skyboxUrl || mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
832 mSkyboxResourceReady = false;
833 mSkyboxUrl = skyboxUrl;
834 mSkyboxEnvironmentMapType = skyboxEnvironmentMapType;
837 if(mSkyboxUrl.empty())
841 Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
842 mSkyboxLoadTask.Reset();
849 mSkyboxTexture.Reset();
852 mSkyboxDirty = false;
853 mSkyboxResourceReady = true;
857 if(isOnScene && mSkyboxDirty)
861 Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
862 mSkyboxLoadTask.Reset();
865 mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, mSkyboxEnvironmentMapType, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
866 Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
867 mSkyboxDirty = false;
871 if(IsResourceReady())
873 Control::SetResourceReady();
877 void SceneView::OnSkyboxLoadComplete()
881 mSkybox = CreateSkybox();
882 SetSkyboxIntensity(mSkyboxIntensity);
883 SetSkyboxOrientation(mSkyboxOrientation);
886 mRootLayer.Add(mSkybox);
890 mSkyboxResourceReady = true;
891 if(IsResourceReady())
893 Control::SetResourceReady();
896 mSkyboxTexture = mSkyboxLoadTask->GetLoadedTexture();
898 if(mSkyboxLoadTask->GetEnvironmentMapType() == Scene3D::EnvironmentMapType::CUBEMAP)
900 skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
904 skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_EQUIRECTANGULAR_SHADER_FRAG.data());
907 Renderer skyboxRenderer = (mSkybox.GetRendererCount() > 0u) ? mSkybox.GetRendererAt(0u) : Renderer();
910 Dali::TextureSet skyboxTextures = TextureSet::New();
911 skyboxTextures.SetTexture(0, mSkyboxTexture);
912 skyboxRenderer.SetTextures(skyboxTextures);
913 skyboxRenderer.SetShader(skyboxShader);
916 mSkyboxLoadTask.Reset();
919 void SceneView::OnIblDiffuseLoadComplete()
921 mDiffuseTexture = mIblDiffuseLoadTask->GetLoadedTexture();
922 mIblDiffuseResourceReady = true;
923 if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
927 mIblDiffuseLoadTask.Reset();
930 void SceneView::OnIblSpecularLoadComplete()
932 mSpecularTexture = mIblSpecularLoadTask->GetLoadedTexture();
933 mSpecularMipmapLevels = mIblSpecularLoadTask->GetMipmapLevels();
934 mIblSpecularResourceReady = true;
935 if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
939 mIblSpecularLoadTask.Reset();
942 void SceneView::OnIblLoadComplete()
944 NotifyImageBasedLightTextureChange();
945 if(IsResourceReady())
947 Control::SetResourceReady();
951 void SceneView::NotifyImageBasedLightTextureChange()
953 for(auto&& item : mItems)
957 item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
962 bool SceneView::AddLightInternal(Scene3D::Light light)
964 uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
965 if(mActivatedLightCount == 0)
967 mActivatedLights.resize(maxNumberOfLight);
970 bool enabled = false;
971 if(mActivatedLightCount < maxNumberOfLight)
973 uint32_t newLightIndex = 0u;
974 for(; newLightIndex < maxNumberOfLight; ++newLightIndex)
976 if(!mActivatedLights[newLightIndex])
978 mActivatedLights[newLightIndex] = light;
983 for(auto&& item : mItems)
987 item->NotifyLightAdded(newLightIndex, light);
991 mActivatedLightCount++;
997 int32_t SceneView::RemoveLightInternal(Scene3D::Light light)
999 int32_t removedIndex = INVALID_INDEX;
1000 uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
1001 for(uint32_t i = 0; i < maxNumberOfLight; ++i)
1003 if(mActivatedLights[i] == light)
1005 for(auto&& item : mItems)
1009 item->NotifyLightRemoved(i);
1012 mActivatedLights[i].Reset();
1013 mActivatedLightCount--;
1019 return removedIndex;
1022 } // namespace Internal
1023 } // namespace Scene3D