From 4309dae5a06d0ca8c95c81bfe020592cb4e6853b Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Thu, 26 Sep 2024 19:59:41 +0200 Subject: [PATCH] handle resizes --- include/vulkan/instance.hpp | 2 ++ src/vulkan/application.cpp | 4 ++-- src/vulkan/instance.cpp | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/vulkan/instance.hpp b/include/vulkan/instance.hpp index cdd0c53..2965fbe 100644 --- a/include/vulkan/instance.hpp +++ b/include/vulkan/instance.hpp @@ -22,6 +22,8 @@ public: VkQueue presentQueue = VK_NULL_HANDLE; VkQueue computeQueue = VK_NULL_HANDLE; + bool windowResized = false; + CommandPool* commandPool = nullptr; struct QueueFamilyIndices { diff --git a/src/vulkan/application.cpp b/src/vulkan/application.cpp index f03e898..48d7973 100644 --- a/src/vulkan/application.cpp +++ b/src/vulkan/application.cpp @@ -154,9 +154,9 @@ void Application::drawFrame() { presentInfo.pImageIndices = &imageIndex; result = vkQueuePresentKHR(Instance::instance->presentQueue, &presentInfo); - if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR){ + if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || Instance::instance->windowResized){ + Instance::instance->windowResized = false; swapchain->recreateSwapchain(); - return; } } diff --git a/src/vulkan/instance.cpp b/src/vulkan/instance.cpp index 988f4fd..f798682 100644 --- a/src/vulkan/instance.cpp +++ b/src/vulkan/instance.cpp @@ -67,6 +67,9 @@ void Instance::initWindow() { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(800, 600, "Vulkan Simulation", nullptr, nullptr); + glfwSetFramebufferSizeCallback(window, [](GLFWwindow* window, int width, int height) { + instance->windowResized = true; + }); } void Instance::createInstance() {