From df58bf246e83783f2a6fcea83ef19a8560665ce6 Mon Sep 17 00:00:00 2001 From: Sebastian Gaida <gaida@ca-digit.com> Date: Tue, 1 Jun 2021 13:30:56 +0200 Subject: [PATCH] [#34] add initial for recreation of swapchain --- include/vkcv/Core.hpp | 4 +++- projects/first_mesh/src/main.cpp | 2 +- src/vkcv/Core.cpp | 11 ++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/vkcv/Core.hpp b/include/vkcv/Core.hpp index cf75b8e7..7d20685f 100644 --- a/include/vkcv/Core.hpp +++ b/include/vkcv/Core.hpp @@ -81,12 +81,14 @@ namespace vkcv uint32_t m_currentSwapchainImageIndex; std::vector<vk::Framebuffer> m_TemporaryFramebuffers; + std::function<void(int, int)> m_resizeHandle; + /** * recreates the swapchain * @param[in] width new window width * @param[in] height new window hight */ - static void recreateSwapchain(int width, int height); + static void recreateSwapchain( const vk::Device& device ,int width, int height); public: /** diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp index 107cd432..6a4b1d01 100644 --- a/projects/first_mesh/src/main.cpp +++ b/projects/first_mesh/src/main.cpp @@ -14,7 +14,7 @@ int main(int argc, const char** argv) { applicationName, windowWidth, windowHeight, - false + true ); vkcv::CameraManager cameraManager(window, windowWidth, windowHeight); diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 0b0d3a24..486c4d5b 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -74,10 +74,6 @@ namespace vkcv const auto commandResources = createCommandResources(context.getDevice(), queueFamilySet); const auto defaultSyncResources = createSyncResources(context.getDevice()); - window.e_resize.add([&](int width, int height){ - recreateSwapchain(width,height); - }); - return Core(std::move(context) , window, swapChain, imageViews, commandResources, defaultSyncResources); } @@ -105,6 +101,8 @@ namespace vkcv m_BufferManager->init(); m_ImageManager->m_core = this; + + m_resizeHandle = window.e_resize.add( [&](int width, int height) { recreateSwapchain( this->getContext().getDevice(),width ,height ); }); } Core::~Core() noexcept { @@ -308,9 +306,8 @@ namespace vkcv return m_swapchain.getSurfaceFormat().format; } - void Core::recreateSwapchain(int width, int height) { - /* boilerplate for #34 */ - std::cout << "Resized to : " << width << " , " << height << std::endl; + void Core::recreateSwapchain( const vk::Device& device, int width, int height) { + device.waitIdle(); } void Core::submitCommands(const SubmitInfo &submitInfo, const RecordCommandFunction& record, const FinishCommandFunction& finish) -- GitLab