changeset 205:24d18cd8be8a

did: try to simplfy swapchain recreation, not sure if it is a good idea
author Sam <sam@basx.dev>
date Mon, 08 May 2023 21:45:47 +0700
parents 6e2017cb8b8b
children 7f921d7d0a2b
files src/semicongine/renderer.nim
diffstat 1 files changed, 7 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/semicongine/renderer.nim	Mon May 08 21:23:29 2023 +0700
+++ b/src/semicongine/renderer.nim	Mon May 08 21:45:47 2023 +0700
@@ -230,17 +230,15 @@
   var
     commandBufferResult = renderer.swapchain.nextFrame()
     commandBuffer: VkCommandBuffer
-    oldSwapchain: Swapchain
 
   if not commandBufferResult.isSome:
-    oldSwapchain = renderer.swapchain
     let res = renderer.swapchain.recreate()
     if res.isSome:
+      var oldSwapchain = renderer.swapchain
       renderer.swapchain = res.get()
-      commandBufferResult = renderer.swapchain.nextFrame()
-      assert commandBufferResult.isSome
-    else:
-      raise newException(Exception, "Unable to recreate swapchain")
+      checkVkResult renderer.device.vk.vkDeviceWaitIdle()
+      oldSwapchain.destroy()
+    return
   commandBuffer = commandBufferResult.get()
 
   commandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer())
@@ -268,16 +266,12 @@
   commandBuffer.endRenderCommands()
 
   if not renderer.swapchain.swap():
-    oldSwapchain = renderer.swapchain
     let res = renderer.swapchain.recreate()
     if res.isSome:
+      var oldSwapchain = renderer.swapchain
       renderer.swapchain = res.get()
-    else:
-      raise newException(Exception, "Unable to recreate swapchain")
-
-  if oldSwapchain.vk.valid:
-    checkVkResult renderer.device.vk.vkDeviceWaitIdle()
-    oldSwapchain.destroy()
+      checkVkResult renderer.device.vk.vkDeviceWaitIdle()
+      oldSwapchain.destroy()
 
 func framesRendered*(renderer: Renderer): uint64 =
   renderer.swapchain.framesRendered