# HG changeset patch # User sam # Date 1730540949 -25200 # Node ID b95d19124e90beffcefaeb580ecaec597542d5ab # Parent 04374630287485ee7ca27000e9e84873d8bab878 add: allow manual swapchain recreation, will likely also need another function to pass in a new renderpass diff -r 043746302874 -r b95d19124e90 semicongine/rendering.nim --- a/semicongine/rendering.nim Wed Oct 30 21:19:42 2024 +0700 +++ b/semicongine/rendering.nim Sat Nov 02 16:49:09 2024 +0700 @@ -84,7 +84,7 @@ Swapchain* = ref object # parameters to initSwapchain, required for swapchain recreation renderPass*: RenderPass - vSync: bool + vSync*: bool # populated through initSwapchain proc vk: VkSwapchainKHR width*: uint32 diff -r 043746302874 -r b95d19124e90 semicongine/rendering/swapchain.nim --- a/semicongine/rendering/swapchain.nim Wed Oct 30 21:19:42 2024 +0700 +++ b/semicongine/rendering/swapchain.nim Sat Nov 02 16:49:09 2024 +0700 @@ -267,10 +267,23 @@ swapchain.currentFiF = (uint32(swapchain.currentFiF) + 1) mod INFLIGHTFRAMES return true -proc recreate(swapchain: Swapchain): Swapchain = - initSwapchain( - renderPass = swapchain.renderPass, vSync = swapchain.vSync, oldSwapchain = swapchain +proc recreateSwapchain*() = + let newSwapchain = initSwapchain( + renderPass = vulkan.swapchain.renderPass, + vSync = vulkan.swapchain.vSync, + oldSwapchain = vulkan.swapchain, ) + if newSwapchain != nil: + vulkan.swapchain = newSwapchain + +proc recreateSwapchain*(vSync: bool) = + let newSwapchain = initSwapchain( + renderPass = vulkan.swapchain.renderPass, + vSync = vSync, + oldSwapchain = vulkan.swapchain, + ) + if newSwapchain != nil: + vulkan.swapchain = newSwapchain template withNextFrame*(framebufferName, commandBufferName, body: untyped): untyped = assert vulkan.swapchain != nil, "Swapchain has not been initialized yet" @@ -294,6 +307,4 @@ checkVkResult vkEndCommandBuffer(`commandBufferName`) discard swap(swapchain = vulkan.swapchain, commandBuffer = `commandBufferName`) else: - let newSwapchain = recreate(vulkan.swapchain) - if newSwapchain != nil: - vulkan.swapchain = newSwapchain + recreateSwapchain()