diff --git a/include/vkcv/Core.hpp b/include/vkcv/Core.hpp index 45e555151584e60f4edd29058e5a59e076f9fafc..065c21d225810f465f0909cb8c1479c1031aba8f 100644 --- a/include/vkcv/Core.hpp +++ b/include/vkcv/Core.hpp @@ -33,7 +33,7 @@ namespace vkcv * * @param context encapsulates various Vulkan objects */ - Core(Context &&context, const Window &window, SwapChain swapChain, std::vector<vk::ImageView> imageViews, + Core(Context &&context, Window &window, SwapChain swapChain, std::vector<vk::ImageView> imageViews, const CommandResources& commandResources, const SyncResources& syncResources) noexcept; // explicit destruction of default constructor Core() = delete; @@ -53,6 +53,14 @@ namespace vkcv SyncResources m_SyncResources; uint32_t m_currentSwapchainImageIndex; std::vector<vk::Framebuffer> m_TemporaryFramebuffers; + + /** + * recreates the swapchain + * @param[in] width new window width + * @param[in] height new window hight + */ + static void recreateSwapchain(int width, int height); + public: /** * Destructor of #Core destroys the Vulkan objects contained in the core's context. @@ -107,7 +115,7 @@ namespace vkcv * @param[in] deviceExtensions (optional) Requested device extensions * @return New instance of #Context */ - static Core create(const Window &window, + static Core create(Window &window, const char *applicationName, uint32_t applicationVersion, std::vector<vk::QueueFlagBits> queueFlags = {}, diff --git a/src/vkcv/Core.cpp b/src/vkcv/Core.cpp index 5b01914796bebd9ac996648113db11e75fdfd557..488715116cbb3b978dfab79e1e0e3d8e05c0f4dc 100644 --- a/src/vkcv/Core.cpp +++ b/src/vkcv/Core.cpp @@ -16,7 +16,7 @@ namespace vkcv { - Core Core::create(const Window &window, + Core Core::create(Window &window, const char *applicationName, uint32_t applicationVersion, std::vector<vk::QueueFlagBits> queueFlags, @@ -70,6 +70,10 @@ namespace vkcv const auto defaultCommandResources = createDefaultCommandResources(context.getDevice(), graphicQueueFamilyIndex); const auto defaultSyncResources = createDefaultSyncResources(context.getDevice()); + window.e_resize.add([&](int width, int height){ + recreateSwapchain(width,height); + }); + return Core(std::move(context) , window, swapChain, imageViews, defaultCommandResources, defaultSyncResources); } @@ -78,7 +82,7 @@ namespace vkcv return m_Context; } - Core::Core(Context &&context, const Window &window , SwapChain swapChain, std::vector<vk::ImageView> imageViews, + Core::Core(Context &&context, Window &window , SwapChain swapChain, std::vector<vk::ImageView> imageViews, const CommandResources& commandResources, const SyncResources& syncResources) noexcept : m_Context(std::move(context)), m_window(window), @@ -213,4 +217,9 @@ namespace vkcv vk::Format Core::getSwapchainImageFormat() { return m_swapchain.getSurfaceFormat().format; } + + void Core::recreateSwapchain(int width, int height) { + /* boilerplate for #34 */ + std::cout << "Resized to : " << width << " , " << height << std::endl; + } }