Renderer: Make WindowSwapchain a RenderTarget
To make it easier to handle window re-creation
This commit is contained in:
parent
97fa4d98be
commit
4a91f3d470
|
|
@ -1523,7 +1523,7 @@ int main()
|
|||
|
||||
bakedGraph.Execute(frame);
|
||||
|
||||
const Nz::RenderTarget* windowRT = &windowSwapchain.GetSwapchain();
|
||||
const Nz::RenderTarget* windowRT = &windowSwapchain;
|
||||
frame.Execute([&](Nz::CommandBufferBuilder& builder)
|
||||
{
|
||||
Nz::Recti windowRenderRect(0, 0, window.GetSize().x, window.GetSize().y);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ int main()
|
|||
|
||||
Nz::Vector2ui windowSize = window.GetSize();
|
||||
|
||||
Nz::Camera camera(&windowSwapchain.GetSwapchain());
|
||||
Nz::Camera camera(&windowSwapchain);
|
||||
//camera.UpdateClearColor(Nz::Color::Gray);
|
||||
|
||||
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ int main()
|
|||
entt::handle viewer = world.CreateEntity();
|
||||
{
|
||||
viewer.emplace<Nz::NodeComponent>();
|
||||
auto& cameraComponent = viewer.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain(), Nz::ProjectionType::Orthographic);
|
||||
auto& cameraComponent = viewer.emplace<Nz::CameraComponent>(&windowSwapchain, Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateRenderMask(1);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ int main()
|
|||
entt::handle viewer = world.CreateEntity();
|
||||
{
|
||||
viewer.emplace<Nz::NodeComponent>();
|
||||
auto& cameraComponent = viewer.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain());
|
||||
auto& cameraComponent = viewer.emplace<Nz::CameraComponent>(&windowSwapchain);
|
||||
cameraComponent.UpdateRenderMask(1);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.5f, 0.5f, 0.5f));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ int main()
|
|||
cameraNode.SetPosition(Nz::Vector3f::Up() * 2.f + Nz::Vector3f::Backward());
|
||||
//cameraNode.SetParent(playerRotNode);
|
||||
|
||||
auto& cameraComponent = playerCamera.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain());
|
||||
auto& cameraComponent = playerCamera.emplace<Nz::CameraComponent>(&windowSwapchain);
|
||||
cameraComponent.UpdateZNear(0.2f);
|
||||
cameraComponent.UpdateZFar(10000.f);
|
||||
cameraComponent.UpdateRenderMask(1);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ int main()
|
|||
{
|
||||
cameraEntity.emplace<Nz::NodeComponent>();
|
||||
|
||||
auto& cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain(), Nz::ProjectionType::Orthographic);
|
||||
auto& cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(&windowSwapchain, Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ int main()
|
|||
{
|
||||
cameraEntity.emplace<Nz::NodeComponent>();
|
||||
|
||||
auto& cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain(), Nz::ProjectionType::Orthographic);
|
||||
auto& cameraComponent = cameraEntity.emplace<Nz::CameraComponent>(&windowSwapchain, Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ int main()
|
|||
{
|
||||
viewer2D.emplace<Nz::NodeComponent>();
|
||||
|
||||
auto& cameraComponent = viewer2D.emplace<Nz::CameraComponent>(&windowSwapchain.GetSwapchain(), Nz::ProjectionType::Orthographic);
|
||||
auto& cameraComponent = viewer2D.emplace<Nz::CameraComponent>(&windowSwapchain, Nz::ProjectionType::Orthographic);
|
||||
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Platform/WindowEventHandler.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Swapchain.hpp>
|
||||
#include <Nazara/Renderer/SwapchainParameters.hpp>
|
||||
#include <memory>
|
||||
|
|
@ -18,13 +19,13 @@ namespace Nz
|
|||
class RenderDevice;
|
||||
class Window;
|
||||
|
||||
class NAZARA_RENDERER_API WindowSwapchain
|
||||
class NAZARA_RENDERER_API WindowSwapchain : public RenderTarget
|
||||
{
|
||||
public:
|
||||
WindowSwapchain(std::shared_ptr<RenderDevice> renderDevice, Window& window, SwapchainParameters parameters = SwapchainParameters());
|
||||
WindowSwapchain(const WindowSwapchain&) = delete;
|
||||
inline WindowSwapchain(WindowSwapchain&& windowSwapchain) noexcept;
|
||||
~WindowSwapchain() = default;
|
||||
WindowSwapchain(WindowSwapchain&&) = delete;
|
||||
inline ~WindowSwapchain();
|
||||
|
||||
inline RenderFrame AcquireFrame();
|
||||
|
||||
|
|
@ -32,11 +33,15 @@ namespace Nz
|
|||
|
||||
inline void EnableRenderOnlyIfFocused(bool enable = true);
|
||||
|
||||
const Framebuffer& GetFramebuffer(std::size_t i) const override;
|
||||
std::size_t GetFramebufferCount() const override;
|
||||
const RenderPass& GetRenderPass() const override;
|
||||
const Vector2ui& GetSize() const override;
|
||||
inline Swapchain& GetSwapchain();
|
||||
inline const Swapchain& GetSwapchain() const;
|
||||
|
||||
WindowSwapchain& operator=(const WindowSwapchain&) = default;
|
||||
inline WindowSwapchain& operator=(WindowSwapchain&& windowSwapchain) noexcept;
|
||||
WindowSwapchain& operator=(const WindowSwapchain&) = delete;
|
||||
WindowSwapchain& operator=(WindowSwapchain&& windowSwapchain) = delete;
|
||||
|
||||
private:
|
||||
void ConnectSignals();
|
||||
|
|
|
|||
|
|
@ -8,15 +8,9 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
inline WindowSwapchain::WindowSwapchain(WindowSwapchain&& windowSwapchain) noexcept :
|
||||
m_renderDevice(std::move(windowSwapchain.m_renderDevice)),
|
||||
m_swapchain(std::move(windowSwapchain.m_swapchain)),
|
||||
m_window(std::move(windowSwapchain.m_window)),
|
||||
m_renderOnlyIfFocused(windowSwapchain.m_renderOnlyIfFocused),
|
||||
m_hasFocus(windowSwapchain.m_hasFocus),
|
||||
m_isMinimized(windowSwapchain.m_isMinimized)
|
||||
inline WindowSwapchain::~WindowSwapchain()
|
||||
{
|
||||
ConnectSignals();
|
||||
OnRenderTargetRelease(this);
|
||||
}
|
||||
|
||||
inline RenderFrame WindowSwapchain::AcquireFrame()
|
||||
|
|
@ -47,22 +41,6 @@ namespace Nz
|
|||
return *m_swapchain;
|
||||
}
|
||||
|
||||
inline WindowSwapchain& WindowSwapchain::operator=(WindowSwapchain&& windowSwapchain) noexcept
|
||||
{
|
||||
windowSwapchain.DisconnectSignals();
|
||||
|
||||
m_renderDevice = std::move(windowSwapchain.m_renderDevice);
|
||||
m_swapchain = std::move(windowSwapchain.m_swapchain);
|
||||
m_window = std::move(windowSwapchain.m_window);
|
||||
m_renderOnlyIfFocused = windowSwapchain.m_renderOnlyIfFocused;
|
||||
m_hasFocus = windowSwapchain.m_hasFocus;
|
||||
m_isMinimized = windowSwapchain.m_isMinimized;
|
||||
|
||||
ConnectSignals();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void WindowSwapchain::DisconnectSignals()
|
||||
{
|
||||
m_onGainedFocus.Disconnect();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
void AppWindowingComponent::Update(Time elapsedTime)
|
||||
void AppWindowingComponent::Update(Time /*elapsedTime*/)
|
||||
{
|
||||
Window::ProcessEvents();
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,26 @@ namespace Nz
|
|||
ConnectSignals();
|
||||
}
|
||||
|
||||
const Framebuffer& WindowSwapchain::GetFramebuffer(std::size_t i) const
|
||||
{
|
||||
return m_swapchain->GetFramebuffer(i);
|
||||
}
|
||||
|
||||
std::size_t WindowSwapchain::GetFramebufferCount() const
|
||||
{
|
||||
return m_swapchain->GetFramebufferCount();
|
||||
}
|
||||
|
||||
const RenderPass& WindowSwapchain::GetRenderPass() const
|
||||
{
|
||||
return m_swapchain->GetRenderPass();
|
||||
}
|
||||
|
||||
const Vector2ui& WindowSwapchain::GetSize() const
|
||||
{
|
||||
return m_swapchain->GetSize();
|
||||
}
|
||||
|
||||
void WindowSwapchain::ConnectSignals()
|
||||
{
|
||||
WindowEventHandler& windowEvents = m_window->GetEventHandler();
|
||||
|
|
@ -62,6 +82,7 @@ namespace Nz
|
|||
m_onResized.Connect(windowEvents.OnResized, [this](const WindowEventHandler* /*eventHandler*/, const WindowEvent::SizeEvent& event)
|
||||
{
|
||||
m_swapchain->NotifyResize({ event.width, event.height });
|
||||
OnRenderTargetSizeChange(this, m_swapchain->GetSize());
|
||||
});
|
||||
|
||||
m_onRestored.Connect(windowEvents.OnRestored, [this](const WindowEventHandler* /*eventHandler*/)
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ int main()
|
|||
}
|
||||
}
|
||||
|
||||
const Nz::RenderTarget* windowRT = &windowSwapchain.GetSwapchain();
|
||||
const Nz::RenderTarget* windowRT = &windowSwapchain;
|
||||
frame.Execute([&](Nz::CommandBufferBuilder& builder)
|
||||
{
|
||||
builder.BeginDebugRegion("Compute part", Nz::Color::Blue());
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ int main()
|
|||
|
||||
Nz::Vector2ui windowSize = window.GetSize();
|
||||
|
||||
Nz::Camera camera(&windowSwapchain.GetSwapchain());
|
||||
Nz::Camera camera(&windowSwapchain);
|
||||
camera.UpdateClearColor(Nz::Color::Gray());
|
||||
|
||||
Nz::ViewerInstance& viewerInstance = camera.GetViewerInstance();
|
||||
|
|
|
|||
Loading…
Reference in New Issue