Mercurial > games > semicongine
changeset 1357:b95d19124e90
add: allow manual swapchain recreation, will likely also need another function to pass in a new renderpass
author | sam <sam@basx.dev> |
---|---|
date | Sat, 02 Nov 2024 16:49:09 +0700 |
parents | 043746302874 |
children | fe9a8922333c |
files | semicongine/rendering.nim semicongine/rendering/swapchain.nim |
diffstat | 2 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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()