Mercurial > games > semicongine
changeset 1363:ce92db0b8f50
add: allow configuration of triple buffering
author | sam <sam@basx.dev> |
---|---|
date | Tue, 05 Nov 2024 23:02:32 +0700 |
parents | 3dbf77ca78b9 |
children | 8f774d9c2518 |
files | semicongine/rendering.nim semicongine/rendering/swapchain.nim |
diffstat | 2 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/semicongine/rendering.nim Mon Nov 04 23:27:30 2024 +0700 +++ b/semicongine/rendering.nim Tue Nov 05 23:02:32 2024 +0700 @@ -85,6 +85,7 @@ # parameters to initSwapchain, required for swapchain recreation renderPass*: RenderPass vSync*: bool + tripleBuffering*: bool # populated through initSwapchain proc vk: VkSwapchainKHR width*: uint32
--- a/semicongine/rendering/swapchain.nim Mon Nov 04 23:27:30 2024 +0700 +++ b/semicongine/rendering/swapchain.nim Tue Nov 05 23:02:32 2024 +0700 @@ -1,7 +1,8 @@ -const N_FRAMEBUFFERS = 3'u32 - proc initSwapchain( - renderPass: RenderPass, vSync: bool = false, oldSwapchain: Swapchain = nil + renderPass: RenderPass, + vSync: bool = false, + tripleBuffering: bool = true, + oldSwapchain: Swapchain = nil, ): Swapchain = assert vulkan.instance.Valid, "Vulkan not initialized" @@ -17,7 +18,7 @@ return nil # following "count" is established according to vulkan specs - var minFramebufferCount = N_FRAMEBUFFERS + var minFramebufferCount = if tripleBuffering: 3'u32 else: 2'u32 minFramebufferCount = max(minFramebufferCount, capabilities.minImageCount) if capabilities.maxImageCount != 0: minFramebufferCount = min(minFramebufferCount, capabilities.maxImageCount) @@ -56,6 +57,7 @@ height: height, renderPass: renderPass, vSync: vSync, + tripleBuffering: tripleBuffering, oldSwapchain: oldSwapchain, ) @@ -267,19 +269,23 @@ swapchain.currentFiF = (uint32(swapchain.currentFiF) + 1) mod INFLIGHTFRAMES return true +# for re-creation with same settings, e.g. window resized proc recreateSwapchain*() = let newSwapchain = initSwapchain( renderPass = vulkan.swapchain.renderPass, vSync = vulkan.swapchain.vSync, + tripleBuffering = vulkan.swapchain.tripleBuffering, oldSwapchain = vulkan.swapchain, ) if newSwapchain != nil: vulkan.swapchain = newSwapchain -proc recreateSwapchain*(vSync: bool) = +# for re-creation with different settings +proc recreateSwapchain*(vSync: bool, tripleBuffering: bool) = let newSwapchain = initSwapchain( renderPass = vulkan.swapchain.renderPass, vSync = vSync, + tripleBuffering = tripleBuffering, oldSwapchain = vulkan.swapchain, ) if newSwapchain != nil: