Recreate swapchain if window is resized

This commit is contained in:
Lander Gallastegi 2024-09-16 01:07:26 +02:00
parent 74498463a3
commit 161e3fb785
3 changed files with 13 additions and 0 deletions

View file

@ -262,6 +262,12 @@ Frame* RendererVulkan::PrepareFrameInternal(VideoCore::Image& image, bool is_eop
}
void RendererVulkan::Present(Frame* frame) {
// Recreate the swapchain if the window was resized.
if (window.getWidth() != swapchain.GetExtent().width ||
window.getHeight() != swapchain.GetExtent().height) {
swapchain.Recreate(window.getWidth(), window.getHeight());
}
ImGui::Core::NewFrame();
swapchain.AcquireNextImage();

View file

@ -81,6 +81,10 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
RefreshSemaphores();
}
void Swapchain::Recreate(u32 width_, u32 height_) {
Create(width_, height_, surface);
}
bool Swapchain::AcquireNextImage() {
vk::Device device = instance.GetDevice();
vk::Result result =

View file

@ -25,6 +25,9 @@ public:
/// Creates (or recreates) the swapchain with a given size.
void Create(u32 width, u32 height, vk::SurfaceKHR surface);
/// Recreates the swapchain with a given size and current surface.
void Recreate(u32 width, u32 height);
/// Acquires the next image in the swapchain.
bool AcquireNextImage();