Graphics/RenderSystem: Add support for external swapchains
This commit is contained in:
parent
6323cb5372
commit
2a3da7384d
|
|
@ -41,8 +41,13 @@ namespace Nz
|
||||||
RenderSystem(RenderSystem&&) = delete;
|
RenderSystem(RenderSystem&&) = delete;
|
||||||
~RenderSystem();
|
~RenderSystem();
|
||||||
|
|
||||||
|
inline void AttachExternalSwapchain(WindowSwapchain& swapchain);
|
||||||
|
|
||||||
WindowSwapchain& CreateSwapchain(Window& window, const SwapchainParameters& parameters = SwapchainParameters{});
|
WindowSwapchain& CreateSwapchain(Window& window, const SwapchainParameters& parameters = SwapchainParameters{});
|
||||||
|
|
||||||
|
void DestroySwapchain(WindowSwapchain& swapchain);
|
||||||
|
inline void DetachExternalSwapchain(WindowSwapchain& swapchain);
|
||||||
|
|
||||||
inline FramePipeline& GetFramePipeline();
|
inline FramePipeline& GetFramePipeline();
|
||||||
inline const FramePipeline& GetFramePipeline() const;
|
inline const FramePipeline& GetFramePipeline() const;
|
||||||
|
|
||||||
|
|
@ -136,6 +141,7 @@ namespace Nz
|
||||||
std::unordered_map<entt::entity, GraphicsEntity*> m_graphicsEntities;
|
std::unordered_map<entt::entity, GraphicsEntity*> m_graphicsEntities;
|
||||||
std::unordered_map<entt::entity, LightEntity*> m_lightEntities;
|
std::unordered_map<entt::entity, LightEntity*> m_lightEntities;
|
||||||
std::unordered_map<Skeleton*, SharedSkeleton> m_sharedSkeletonInstances;
|
std::unordered_map<Skeleton*, SharedSkeleton> m_sharedSkeletonInstances;
|
||||||
|
std::vector<std::reference_wrapper<WindowSwapchain>> m_externalSwapchains;
|
||||||
std::vector<std::unique_ptr<WindowSwapchain>> m_windowSwapchains;
|
std::vector<std::unique_ptr<WindowSwapchain>> m_windowSwapchains;
|
||||||
ElementRendererRegistry m_elementRegistry;
|
ElementRendererRegistry m_elementRegistry;
|
||||||
MemoryPool<CameraEntity> m_cameraEntityPool;
|
MemoryPool<CameraEntity> m_cameraEntityPool;
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,23 @@
|
||||||
// This file is part of the "Nazara Engine - Graphics module"
|
// This file is part of the "Nazara Engine - Graphics module"
|
||||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||||
|
|
||||||
#include <type_traits>
|
#include <Nazara/Core/Error.hpp>
|
||||||
#include <Nazara/Graphics/Debug.hpp>
|
#include <Nazara/Graphics/Debug.hpp>
|
||||||
|
|
||||||
namespace Nz
|
namespace Nz
|
||||||
{
|
{
|
||||||
|
inline void RenderSystem::AttachExternalSwapchain(WindowSwapchain& swapchain)
|
||||||
|
{
|
||||||
|
m_windowSwapchains.emplace_back(&swapchain);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void RenderSystem::DetachExternalSwapchain(WindowSwapchain& swapchain)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(m_externalSwapchains.begin(), m_externalSwapchains.end(), [&](WindowSwapchain& externalSwapchain) { return &externalSwapchain == &swapchain; });
|
||||||
|
NazaraAssert(it != m_externalSwapchains.end(), "external swapchain is not part of this render system");
|
||||||
|
m_externalSwapchains.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
inline FramePipeline& RenderSystem::GetFramePipeline()
|
inline FramePipeline& RenderSystem::GetFramePipeline()
|
||||||
{
|
{
|
||||||
return *m_pipeline;
|
return *m_pipeline;
|
||||||
|
|
@ -19,3 +31,4 @@ namespace Nz
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Nazara/Graphics/DebugOff.hpp>
|
#include <Nazara/Graphics/DebugOff.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,22 +55,36 @@ namespace Nz
|
||||||
return *m_windowSwapchains.emplace_back(std::make_unique<WindowSwapchain>(Graphics::Instance()->GetRenderDevice(), window, parameters));
|
return *m_windowSwapchains.emplace_back(std::make_unique<WindowSwapchain>(Graphics::Instance()->GetRenderDevice(), window, parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderSystem::DestroySwapchain(WindowSwapchain& swapchain)
|
||||||
|
{
|
||||||
|
auto it = std::find_if(m_windowSwapchains.begin(), m_windowSwapchains.end(), [&](const auto& ptr) { return ptr.get() == &swapchain; });
|
||||||
|
NazaraAssert(it != m_windowSwapchains.end(), "invalid swapchain");
|
||||||
|
|
||||||
|
m_windowSwapchains.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
void RenderSystem::Update(Time /*elapsedTime*/)
|
void RenderSystem::Update(Time /*elapsedTime*/)
|
||||||
{
|
{
|
||||||
UpdateObservers();
|
UpdateObservers();
|
||||||
UpdateInstances();
|
UpdateInstances();
|
||||||
|
|
||||||
for (auto& swapchainPtr : m_windowSwapchains)
|
auto HandleSwapchain = [&](WindowSwapchain& swapchain)
|
||||||
{
|
{
|
||||||
RenderFrame frame = swapchainPtr->AcquireFrame();
|
RenderFrame frame = swapchain.AcquireFrame();
|
||||||
if (!frame)
|
if (!frame)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
if (!m_cameraEntities.empty())
|
if (!m_cameraEntities.empty())
|
||||||
m_pipeline->Render(frame);
|
m_pipeline->Render(frame);
|
||||||
|
|
||||||
frame.Present();
|
frame.Present();
|
||||||
}
|
};
|
||||||
|
|
||||||
|
for (auto& swapchainPtr : m_windowSwapchains)
|
||||||
|
HandleSwapchain(*swapchainPtr);
|
||||||
|
|
||||||
|
for (WindowSwapchain& swapchain : m_externalSwapchains)
|
||||||
|
HandleSwapchain(swapchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::OnCameraDestroy([[maybe_unused]] entt::registry& registry, entt::entity entity)
|
void RenderSystem::OnCameraDestroy([[maybe_unused]] entt::registry& registry, entt::entity entity)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue