#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/debug.h>
#include <dali/public-api/object/type-registry-helper.h>
#include <dali/public-api/object/type-registry.h>
#include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
#include <dali-scene3d/public-api/loader/cube-map-loader.h>
-#include <dali/integration-api/debug.h>
-
using namespace Dali;
namespace Dali
Property::Index RENDERING_BUFFER = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
constexpr int32_t DEFAULT_ORIENTATION = 0;
+constexpr uint8_t DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL = 4u;
+
static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
Dali::Actor CreateSkybox(const std::string& skyboxUrl)
{Vector3(-1.0f, -1.0f, 1.0f)},
{Vector3(1.0f, -1.0f, 1.0f)}};
- Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
- Dali::VertexBuffer vertexBuffer = Dali::VertexBuffer::New(Property::Map().Add("aPosition", Property::VECTOR3));
+ Dali::Shader shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+ 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::Texture skyboxTexture = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
+ Dali::Texture skyboxTexture = Dali::Scene3D::Loader::LoadCubeMap(skyboxUrl);
Dali::TextureSet skyboxTextures = TextureSet::New();
skyboxTextures.SetTexture(0, skyboxTexture);
UpdateCamera(GetCamera(name));
}
-void SceneView::RegisterModel(Scene3D::Model model)
+void SceneView::RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item)
{
- if(model)
+ if(item)
{
- model.SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
- mModels.push_back(model);
+ item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
+ mItems.push_back(item);
}
}
-void SceneView::UnregisterModel(Scene3D::Model model)
+void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* 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);
+ mItems.erase(mItems.begin() + i);
break;
}
}
void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor)
{
- mIBLResourceReady = false;
- Texture diffuseTexture = Dali::Scene3D::Loader::LoadCubeMap(diffuseUrl);
- if(diffuseTexture)
+ mIBLResourceReady = false;
+
+ // If url is empty or invalid, reset IBL.
+ mDiffuseTexture = (!diffuseUrl.empty()) ? Dali::Scene3D::Loader::LoadCubeMap(diffuseUrl) : Texture();
+ mSpecularTexture = (!specularUrl.empty()) ? Dali::Scene3D::Loader::LoadCubeMap(specularUrl) : Texture();
+
+ mIblScaleFactor = scaleFactor;
+
+ for(auto&& item : mItems)
{
- Texture specularTexture = Dali::Scene3D::Loader::LoadCubeMap(specularUrl);
- if(specularTexture)
+ if(item)
{
- mDiffuseTexture = diffuseTexture;
- mSpecularTexture = specularTexture;
- mIblScaleFactor = scaleFactor;
-
- for(auto&& model : mModels)
- {
- if(model)
- {
- model.SetImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
- }
- }
+ item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
}
}
+
mIBLResourceReady = true;
if(IsResourceReady())
{
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);
}
}
}
void SceneView::OnSceneConnection(int depth)
{
- UpdateRenderTask();
-
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);
+ 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.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
mDefaultCamera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
Vector3 size = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
const float aspectRatio = size.width / size.height;
mSelectedCamera.SetAspectRatio(aspectRatio);
- const bool projectionVertical = mSelectedCamera.GetProperty<int>(Dali::DevelCameraActor::Property::PROJECTION_DIRECTION) == Dali::DevelCameraActor::VERTICAL;
-
- // if projectionVertical, Top / Bottom is +-ve to keep consistency with orthographic values
- // else, Left / Right is +-ve to keep consistency with orthographic values
- const float orthographicSize = DALI_LIKELY(projectionVertical) ? mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] : mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE];
- const float halfHeight = DALI_LIKELY(projectionVertical) ? orthographicSize : orthographicSize / aspectRatio;
- const float halfWidth = DALI_LIKELY(projectionVertical) ? orthographicSize * aspectRatio : orthographicSize;
-
- mSelectedCamera[Dali::CameraActor::Property::LEFT_PLANE_DISTANCE] = -halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::RIGHT_PLANE_DISTANCE] = halfWidth;
- mSelectedCamera[Dali::CameraActor::Property::TOP_PLANE_DISTANCE] = halfHeight;
- mSelectedCamera[Dali::CameraActor::Property::BOTTOM_PLANE_DISTANCE] = -halfHeight;
if(mUseFrameBuffer)
{
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, DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL);
+ 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);
}
Toolkit::DevelControl::UnregisterVisual(*this, RENDERING_BUFFER);
mVisual.Reset();
- mRenderTarget.Reset();
+ mFrameBuffer.Reset();
mTexture.Reset();
}
}