/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/devel-api/actors/camera-actor-devel.h>
#include <dali/devel-api/adaptor-framework/window-devel.h>
#include <dali/devel-api/common/stage.h>
+#include <dali/devel-api/rendering/frame-buffer-devel.h>
#include <dali/integration-api/adaptor-framework/adaptor.h>
#include <dali/integration-api/debug.h>
+#include <dali/public-api/math/math-utils.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/public-api/object/type-registry.h>
+#include <string_view>
// INTERNAL INCLUDES
#include <dali-scene3d/internal/controls/model/model-impl.h>
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
-
-#include <dali/integration-api/debug.h>
+#include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-scene3d/internal/light/light-impl.h>
using namespace Dali;
Property::Index RENDERING_BUFFER = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
constexpr int32_t DEFAULT_ORIENTATION = 0;
+constexpr int32_t INVALID_INDEX = -1;
+
+static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
+
+Dali::Actor CreateSkybox()
+{
+ struct Vertex
+ {
+ Vector3 aPosition;
+ };
+
+ Vertex skyboxVertices[] = {
+ // back
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+ {Vector3(-1.0f, -1.0f, -1.0f)},
+ {Vector3(1.0f, -1.0f, -1.0f)},
+ {Vector3(1.0f, -1.0f, -1.0f)},
+ {Vector3(1.0f, 1.0f, -1.0f)},
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+
+ // left
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+ {Vector3(-1.0f, -1.0f, -1.0f)},
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+ {Vector3(-1.0f, 1.0f, 1.0f)},
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+
+ // right
+ {Vector3(1.0f, -1.0f, -1.0f)},
+ {Vector3(1.0f, -1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, -1.0f)},
+ {Vector3(1.0f, -1.0f, -1.0f)},
+
+ // front
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+ {Vector3(-1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, -1.0f, 1.0f)},
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+
+ // botton
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+ {Vector3(1.0f, 1.0f, -1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(1.0f, 1.0f, 1.0f)},
+ {Vector3(-1.0f, 1.0f, 1.0f)},
+ {Vector3(-1.0f, 1.0f, -1.0f)},
+
+ // top
+ {Vector3(-1.0f, -1.0f, -1.0f)},
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+ {Vector3(1.0f, -1.0f, -1.0f)},
+ {Vector3(1.0f, -1.0f, -1.0f)},
+ {Vector3(-1.0f, -1.0f, 1.0f)},
+ {Vector3(1.0f, -1.0f, 1.0f)}};
+
+ Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
+ vertexBuffer.SetData(skyboxVertices, sizeof(skyboxVertices) / sizeof(Vertex));
+
+ Dali::Geometry skyboxGeometry = Geometry::New();
+ skyboxGeometry.AddVertexBuffer(vertexBuffer);
+ skyboxGeometry.SetType(Geometry::TRIANGLES);
+
+ Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+ Dali::Renderer skyboxRenderer;
+ skyboxRenderer = Renderer::New(skyboxGeometry, shaderSkybox);
+ skyboxRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2.0f);
+ // Enables the depth test.
+ skyboxRenderer.SetProperty(Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::ON);
+ // The fragment shader will run only is those pixels that have the max depth value.
+ skyboxRenderer.SetProperty(Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
+
+ Dali::Actor skyboxActor = Actor::New();
+ skyboxActor.SetProperty(Dali::Actor::Property::NAME, "SkyBox");
+ skyboxActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ skyboxActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ skyboxActor.AddRenderer(skyboxRenderer);
+ return skyboxActor;
+}
} // anonymous namespace
SceneView::SceneView()
: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
- mIblLoadedCallback(nullptr),
- mScreenOrientation(DEFAULT_ORIENTATION)
+ mWindowOrientation(DEFAULT_ORIENTATION),
+ mSkybox(),
+ mSkyboxOrientation(Quaternion()),
+ mSkyboxIntensity(1.0f)
{
}
SceneView::~SceneView()
{
- if(mIblLoadedCallback && Adaptor::IsAvailable())
+ if(Dali::Adaptor::IsAvailable())
{
- // Removes the callback from the callback manager in case the control is destroyed before the callback is executed.
- Adaptor::Get().RemoveIdle(mIblLoadedCallback);
+ if(mIblDiffuseLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
+ mIblDiffuseLoadTask.Reset();
+ }
+ if(mIblSpecularLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
+ mIblSpecularLoadTask.Reset();
+ }
+ if(mSkyboxLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+ mSkyboxLoadTask.Reset();
+ }
}
}
UpdateCamera(GetCamera(name));
}
-void SceneView::RegisterModel(Scene3D::Model model)
+void SceneView::RegisterSceneItem(Scene3D::Internal::LightObserver* item)
{
- if(model)
+ if(item)
{
- model.SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
- mModels.push_back(model);
+ item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+
+ if(mActivatedLightCount > 0)
+ {
+ uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxLightCount; ++i)
+ {
+ if(mActivatedLights[i])
+ {
+ item->NotifyLightAdded(i, mActivatedLights[i]);
+ }
+ }
+ }
+ mItems.push_back(item);
}
}
-void SceneView::UnregisterModel(Scene3D::Model model)
+void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
{
- if(model)
+ if(item)
{
- for(uint32_t i = 0; i < mModels.size(); ++i)
+ for(uint32_t i = 0; i < mItems.size(); ++i)
{
- if(mModels[i] == model)
+ if(mItems[i] == item)
{
- mModels.erase(mModels.begin() + i);
+ if(mActivatedLightCount > 0)
+ {
+ uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxLightCount; ++i)
+ {
+ if(mActivatedLights[i])
+ {
+ item->NotifyLightRemoved(i);
+ }
+ }
+ }
+ mItems.erase(mItems.begin() + i);
break;
}
}
void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor)
{
- // Request asynchronous model loading
- if(!mIblLoadedCallback)
+ bool needIblReset = false;
+ bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+ if(mDiffuseIblUrl != diffuseUrl)
{
- mIBLResourceReady = false;
- mDiffuseIblUrl = diffuseUrl;
- mSpecularIblUrl = specularUrl;
- mIblScaleFactor = scaleFactor;
- // The callback manager takes the ownership of the callback object.
- mIblLoadedCallback = MakeCallback(this, &SceneView::OnLoadComplete);
- Adaptor::Get().AddIdle(mIblLoadedCallback, false);
+ mDiffuseIblUrl = diffuseUrl;
+ if(mDiffuseIblUrl.empty())
+ {
+ needIblReset = true;
+ }
+ else
+ {
+ mIblDiffuseDirty = true;
+ mIblDiffuseResourceReady = false;
+ }
+ }
+
+ if(mSpecularIblUrl != specularUrl)
+ {
+ mSpecularIblUrl = specularUrl;
+ if(mSpecularIblUrl.empty())
+ {
+ needIblReset = true;
+ }
+ else
+ {
+ mIblSpecularDirty = true;
+ mIblSpecularResourceReady = false;
+ }
+ }
+
+ // If one or both of diffuse url and specular url are empty,
+ // we don't need to request to load texture.
+ if(needIblReset)
+ {
+ if(mIblDiffuseLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
+ mIblDiffuseLoadTask.Reset();
+ }
+
+ if(mIblSpecularLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
+ mIblSpecularLoadTask.Reset();
+ }
+
+ mIblDiffuseDirty = false;
+ mIblSpecularDirty = false;
+ mIblDiffuseResourceReady = true;
+ mIblSpecularResourceReady = true;
+
+ mDiffuseTexture.Reset();
+ mSpecularTexture.Reset();
+
+ mSpecularMipmapLevels = 1u;
+ NotifyImageBasedLightTextureChange();
+ }
+ else
+ {
+ if(isOnScene && mIblDiffuseDirty)
+ {
+ if(mIblDiffuseLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
+ mIblDiffuseLoadTask.Reset();
+ }
+ mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
+ Dali::AsyncTaskManager::Get().AddTask(mIblDiffuseLoadTask);
+ mIblDiffuseDirty = false;
+ }
+
+ if(isOnScene && mIblSpecularDirty)
+ {
+ if(mIblSpecularLoadTask)
+ {
+ Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
+ mIblSpecularLoadTask.Reset();
+ }
+ mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
+ Dali::AsyncTaskManager::Get().AddTask(mIblSpecularLoadTask);
+ mIblSpecularDirty = false;
+ }
+ }
+
+ if(!Dali::Equals(mIblScaleFactor, scaleFactor))
+ {
+ SetImageBasedLightScaleFactor(scaleFactor);
+ }
+
+ // If diffuse and specular textures are already loaded, emits resource ready signal here.
+ if(IsResourceReady())
+ {
+ Control::SetResourceReady(false);
}
}
void SceneView::SetImageBasedLightScaleFactor(float scaleFactor)
{
mIblScaleFactor = scaleFactor;
- for(auto&& model : mModels)
+ for(auto&& item : mItems)
{
- if(model)
+ if(item)
{
- model.SetImageBasedLightScaleFactor(scaleFactor);
+ item->NotifyImageBasedLightScaleFactor(scaleFactor);
}
}
}
return mIblScaleFactor;
}
+void SceneView::AddLight(Scene3D::Light light)
+{
+ bool enabled = AddLightInternal(light);
+ mLights.push_back(std::make_pair(light, enabled));
+}
+
+void SceneView::RemoveLight(Scene3D::Light light)
+{
+ if(mActivatedLights.empty())
+ {
+ return;
+ }
+
+ bool needToDisable = false;
+ for(uint32_t i = 0; i < mLights.size(); ++i)
+ {
+ if(mLights[i].first == light)
+ {
+ // If mLights[i].second is true, it means the light is currently activated in Scene.
+ // Then it should be removed from mActivatedLights list too.
+ needToDisable = mLights[i].second;
+ mLights.erase(mLights.begin() + i);
+ break;
+ }
+ }
+
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ if(needToDisable)
+ {
+ uint32_t removedIndex = RemoveLightInternal(light);
+ if(mActivatedLightCount < maxNumberOfLight && mLights.size() >= maxNumberOfLight)
+ {
+ for(auto && lightItem : mLights)
+ {
+ if(lightItem.second == false)
+ {
+ lightItem.second = AddLightInternal(lightItem.first);
+ break;
+ }
+ }
+ }
+
+ // To remove empty entity of mActivatedLights, moves last object to empty position.
+ // Because one Light is removed, mActivatedLights[mActivatedLightCount] is current last object of the list.
+ if(!mActivatedLights[removedIndex] && mActivatedLightCount > 0 && removedIndex < mActivatedLightCount)
+ {
+ Scene3D::Light reorderingLight = mActivatedLights[mActivatedLightCount];
+ RemoveLightInternal(reorderingLight);
+ AddLightInternal(reorderingLight);
+ }
+ }
+}
+
+uint32_t SceneView::GetActivatedLightCount() const
+{
+ return mActivatedLightCount;
+}
+
void SceneView::UseFramebuffer(bool useFramebuffer)
{
if(mUseFrameBuffer != useFramebuffer)
return mUseFrameBuffer;
}
+void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
+{
+ if(mFrameBufferMultiSamplingLevel != multiSamplingLevel)
+ {
+ mFrameBufferMultiSamplingLevel = multiSamplingLevel;
+
+ // Create new framebuffer with changed multiSamplingLevel.
+ if(mRenderTask && mFrameBuffer && mTexture)
+ {
+ Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+
+ mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
+ mFrameBuffer.AttachColorTexture(mTexture);
+ DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
+ mRenderTask.SetFrameBuffer(mFrameBuffer);
+
+ // Note : we don't need to create new visual since visual's url is depend on mTexture.
+ }
+ }
+}
+
+uint8_t SceneView::GetFramebufferMultiSamplingLevel() const
+{
+ return mFrameBufferMultiSamplingLevel;
+}
+
+void SceneView::SetSkybox(const std::string& skyboxUrl)
+{
+ if(mSkyboxUrl != skyboxUrl)
+ {
+ UpdateSkybox(skyboxUrl, mSkyboxEnvironmentMapType);
+ }
+}
+
+void SceneView::SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
+{
+ if(mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
+ {
+ UpdateSkybox(mSkyboxUrl, skyboxEnvironmentMapType);
+ }
+}
+
+void SceneView::SetSkyboxIntensity(float intensity)
+{
+ mSkyboxIntensity = intensity;
+ if(intensity < 0)
+ {
+ DALI_LOG_ERROR("Intensity should be greater than or equal to 0.\n");
+ mSkyboxIntensity = 0.0f;
+ }
+
+ if(mSkybox)
+ {
+ mSkybox.RegisterProperty(SKYBOX_INTENSITY_STRING.data(), mSkyboxIntensity);
+ }
+}
+
+float SceneView::GetSkyboxIntensity() const
+{
+ return mSkyboxIntensity;
+}
+
+void SceneView::SetSkyboxOrientation(const Quaternion& orientation)
+{
+ mSkyboxOrientation = orientation;
+ if(mSkybox)
+ {
+ mSkybox.SetProperty(Dali::Actor::Property::ORIENTATION, orientation);
+ }
+}
+
+Quaternion SceneView::GetSkyboxOrientation() const
+{
+ return mSkyboxOrientation;
+}
+
///////////////////////////////////////////////////////////
//
// Private methods
void SceneView::OnSceneConnection(int depth)
{
- UpdateRenderTask();
+ // If diffuse and specular url is not valid, IBL does not need to be loaded.
+ if(!mDiffuseIblUrl.empty() && !mSpecularIblUrl.empty())
+ {
+ SetImageBasedLightSource(mDiffuseIblUrl, mSpecularIblUrl, mIblScaleFactor);
+ }
+
+ if(!mSkyboxUrl.empty())
+ {
+ UpdateSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
+ }
Window window = DevelWindow::Get(Self());
if(window)
{
window.ResizeSignal().Connect(this, &SceneView::OnWindowResized);
+ RenderTaskList taskList = window.GetRenderTaskList();
+ mRenderTask = taskList.CreateTask();
+ mRenderTask.SetSourceActor(mRootLayer);
+ mRenderTask.SetExclusive(true);
+ mRenderTask.SetInputEnabled(true);
+ mRenderTask.SetCullMode(false);
+ mRenderTask.SetScreenToFrameBufferMappingActor(Self());
+
+ UpdateRenderTask();
+ mWindow = window;
}
Control::OnSceneConnection(depth);
void SceneView::OnSceneDisconnection()
{
- mModels.clear();
+ mItems.clear();
- Window window = DevelWindow::Get(Self());
+ Window window = mWindow.GetHandle();
if(window)
{
window.ResizeSignal().Disconnect(this, &SceneView::OnWindowResized);
+ RenderTaskList taskList = window.GetRenderTaskList();
+ if(mRenderTask)
+ {
+ taskList.RemoveTask(mRenderTask);
+ mRenderTask.Reset();
+ mFrameBuffer.Reset();
+ }
}
+ mWindow.Reset();
Control::OnSceneDisconnection();
}
mRootLayer.SetProperty(Dali::Actor::Property::INHERIT_SCALE, false);
self.Add(mRootLayer);
- RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
- mRenderTask = taskList.CreateTask();
- mRenderTask.SetSourceActor(mRootLayer);
- mRenderTask.SetExclusive(true);
- mRenderTask.SetInputEnabled(true);
- mRenderTask.SetCullMode(false);
- mRenderTask.SetScreenToFrameBufferMappingActor(Self());
-
- mDefaultCamera = Dali::CameraActor::New();
+ mDefaultCamera = Dali::CameraActor::New3DCamera();
mDefaultCamera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
mDefaultCamera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
- mDefaultCamera.SetNearClippingPlane(1.0f);
AddCamera(mDefaultCamera);
UpdateCamera(mDefaultCamera);
}
bool SceneView::IsResourceReady() const
{
- return mIBLResourceReady;
+ return mIblDiffuseResourceReady && mIblSpecularResourceReady && mSkyboxResourceReady;
}
void SceneView::UpdateCamera(CameraActor camera)
Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
const float aspectRatio = size.width / size.height;
mSelectedCamera.SetAspectRatio(aspectRatio);
- const float halfHeight = mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE];
- const float halfWidth = aspectRatio * halfHeight;
- mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE] = -halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE] = halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] = halfHeight; // Top is +ve to keep consistency with orthographic values
- mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight; // Bottom is -ve to keep consistency with orthographic values
+
if(mUseFrameBuffer)
{
Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
if(!currentFrameBuffer ||
- currentFrameBuffer.GetColorTexture().GetWidth() != size.width ||
- currentFrameBuffer.GetColorTexture().GetHeight() != size.height)
+ !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), size.width) ||
+ !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height))
{
+ mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_COLOR);
mRenderTask.ResetViewportGuideActor();
mRenderTask.SetViewport(Dali::Viewport(Vector4::ZERO));
// create offscreen buffer of new size to render our child actors to
- mTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(size.width), unsigned(size.height));
- mRenderTarget = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
- mRenderTarget.AttachColorTexture(mTexture);
- Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(mRenderTarget, 0u);
+ mTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(size.width), unsigned(size.height));
+ mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
+ mFrameBuffer.AttachColorTexture(mTexture);
+ DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
+ Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(mFrameBuffer, 0u);
Property::Map imagePropertyMap;
imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
- mRenderTask.SetFrameBuffer(mRenderTarget);
+ mRenderTask.SetFrameBuffer(mFrameBuffer);
mRenderTask.SetClearEnabled(true);
mRenderTask.SetClearColor(Color::TRANSPARENT);
}
mRenderTask.SetViewportGuideActor(Self());
if(mRenderTask.GetFrameBuffer())
{
+ mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_MULTIPLY_PARENT_ALPHA);
FrameBuffer framebuffer;
mRenderTask.SetFrameBuffer(framebuffer);
mRenderTask.SetClearEnabled(false);
Toolkit::DevelControl::UnregisterVisual(*this, RENDERING_BUFFER);
mVisual.Reset();
- mRenderTarget.Reset();
+ mFrameBuffer.Reset();
mTexture.Reset();
}
}
void SceneView::OnWindowResized(Window window, Window::WindowSize size)
{
- mScreenOrientation = DevelWindow::GetPhysicalOrientation(window);
+ mWindowOrientation = DevelWindow::GetPhysicalOrientation(window);
RotateCamera();
}
}
else
{
- DevelCameraActor::RotateProjection(mSelectedCamera, mScreenOrientation);
+ DevelCameraActor::RotateProjection(mSelectedCamera, mWindowOrientation);
}
}
-void SceneView::LoadImageBasedLight()
+void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
{
- Texture diffuseTexture = Dali::Scene3D::Loader::LoadCubeMap(mDiffuseIblUrl);
- Texture specularTexture = Dali::Scene3D::Loader::LoadCubeMap(mSpecularIblUrl);
+ bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+ if(mSkyboxUrl != skyboxUrl || mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
+ {
+ mSkyboxDirty = true;
+ mSkyboxResourceReady = false;
+ mSkyboxUrl = skyboxUrl;
+ mSkyboxEnvironmentMapType = skyboxEnvironmentMapType;
+ }
- if(diffuseTexture)
+ if(mSkyboxUrl.empty())
{
- if(specularTexture)
+ if(mSkyboxLoadTask)
{
- mDiffuseTexture = diffuseTexture;
- mSpecularTexture = specularTexture;
+ Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+ mSkyboxLoadTask.Reset();
+ }
- for(auto&& model : mModels)
+ if(mSkybox)
+ {
+ mSkybox.Unparent();
+ mSkybox.Reset();
+ mSkyboxTexture.Reset();
+ }
+
+ mSkyboxDirty = false;
+ mSkyboxResourceReady = true;
+ }
+ else
+ {
+ if(isOnScene && mSkyboxDirty)
+ {
+ if(mSkyboxLoadTask)
{
- if(model)
- {
- model.SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
- }
+ Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+ mSkyboxLoadTask.Reset();
}
+
+ mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, mSkyboxEnvironmentMapType, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
+ Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
+ mSkyboxDirty = false;
}
}
+
+ if(IsResourceReady())
+ {
+ Control::SetResourceReady(false);
+ }
}
-void SceneView::OnLoadComplete()
+void SceneView::OnSkyboxLoadComplete()
{
- // TODO: In this implementation, we cannot know which request occurs this OnLoadComplete Callback.
- // Currently it is no problem because the all loading is processed in this method.
+ if(!mSkybox)
+ {
+ mSkybox = CreateSkybox();
+ SetSkyboxIntensity(mSkyboxIntensity);
+ SetSkyboxOrientation(mSkyboxOrientation);
+ if(mRootLayer)
+ {
+ mRootLayer.Add(mSkybox);
+ }
+ }
- // Prevent to emit unnecessary resource ready signal.
+ mSkyboxResourceReady = true;
if(IsResourceReady())
{
- return;
+ Control::SetResourceReady(false);
}
- if(!mIBLResourceReady)
+ mSkyboxTexture = mSkyboxLoadTask->GetLoadedTexture();
+ Shader skyboxShader;
+ if(mSkyboxLoadTask->GetEnvironmentMapType() == Scene3D::EnvironmentMapType::CUBEMAP)
{
- LoadImageBasedLight();
- mIBLResourceReady = true;
- mIblLoadedCallback = nullptr;
+ skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
}
+ else
+ {
+ skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_EQUIRECTANGULAR_SHADER_FRAG.data());
+ }
+
+ Renderer skyboxRenderer = (mSkybox.GetRendererCount() > 0u) ? mSkybox.GetRendererAt(0u) : Renderer();
+ if(skyboxRenderer)
+ {
+ Dali::TextureSet skyboxTextures = TextureSet::New();
+ skyboxTextures.SetTexture(0, mSkyboxTexture);
+ skyboxRenderer.SetTextures(skyboxTextures);
+ skyboxRenderer.SetShader(skyboxShader);
+ }
+
+ mSkyboxLoadTask.Reset();
+}
+void SceneView::OnIblDiffuseLoadComplete()
+{
+ mDiffuseTexture = mIblDiffuseLoadTask->GetLoadedTexture();
+ mIblDiffuseResourceReady = true;
+ if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
+ {
+ OnIblLoadComplete();
+ }
+ mIblDiffuseLoadTask.Reset();
+}
+
+void SceneView::OnIblSpecularLoadComplete()
+{
+ mSpecularTexture = mIblSpecularLoadTask->GetLoadedTexture();
+ mSpecularMipmapLevels = mIblSpecularLoadTask->GetMipmapLevels();
+ mIblSpecularResourceReady = true;
+ if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
+ {
+ OnIblLoadComplete();
+ }
+ mIblSpecularLoadTask.Reset();
+}
+
+void SceneView::OnIblLoadComplete()
+{
+ NotifyImageBasedLightTextureChange();
if(IsResourceReady())
{
Control::SetResourceReady(false);
}
}
+void SceneView::NotifyImageBasedLightTextureChange()
+{
+ for(auto&& item : mItems)
+ {
+ if(item)
+ {
+ item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+ }
+ }
+}
+
+bool SceneView::AddLightInternal(Scene3D::Light light)
+{
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ if(mActivatedLightCount == 0)
+ {
+ mActivatedLights.resize(maxNumberOfLight);
+ }
+
+ bool enabled = false;
+ if(mActivatedLightCount < maxNumberOfLight)
+ {
+ uint32_t newLightIndex = 0u;
+ for(; newLightIndex < maxNumberOfLight; ++newLightIndex)
+ {
+ if(!mActivatedLights[newLightIndex])
+ {
+ mActivatedLights[newLightIndex] = light;
+ break;
+ }
+ }
+
+ for(auto&& item : mItems)
+ {
+ if(item)
+ {
+ item->NotifyLightAdded(newLightIndex, light);
+ }
+ }
+
+ mActivatedLightCount++;
+ enabled = true;
+ }
+ return enabled;
+}
+
+int32_t SceneView::RemoveLightInternal(Scene3D::Light light)
+{
+ int32_t removedIndex = INVALID_INDEX;
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxNumberOfLight; ++i)
+ {
+ if(mActivatedLights[i] == light)
+ {
+ for(auto&& item : mItems)
+ {
+ if(item)
+ {
+ item->NotifyLightRemoved(i);
+ }
+ }
+ mActivatedLights[i].Reset();
+ mActivatedLightCount--;
+ removedIndex = i;
+ break;
+ }
+ }
+
+ return removedIndex;
+}
+
} // namespace Internal
} // namespace Scene3D
} // namespace Dali