# HG changeset patch # User sam # Date 1711815050 -25200 # Node ID 125f808f8fea91c0e8026ccea9b1e7e7a71ec144 # Parent 17943f768402b83577820be9397fc0ebc9e6ad24 did: some renaming diff -r 17943f768402 -r 125f808f8fea semicongine/renderer.nim --- a/semicongine/renderer.nim Sat Mar 30 22:21:47 2024 +0700 +++ b/semicongine/renderer.nim Sat Mar 30 23:10:50 2024 +0700 @@ -45,7 +45,7 @@ queue: Queue commandBufferPool: CommandBufferPool -proc currentCommandBuffer(renderer: Renderer): VkCommandBuffer = +proc currentFrameCommandBuffer(renderer: Renderer): VkCommandBuffer = renderer.commandBufferPool.buffers[renderer.swapchain.currentInFlight] proc initRenderer*(device: Device, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor = Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32]), backFaceCulling = true): Renderer = @@ -405,9 +405,7 @@ proc render*(renderer: var Renderer, scene: Scene) = assert scene in renderer.scenedata - var currentInFlightFrameIndex = renderer.swapchain.nextFrame() - - if not currentInFlightFrameIndex.isSome: + if not renderer.swapchain.nextFrame(): let res = renderer.swapchain.recreate() if res.isSome: var oldSwapchain = renderer.swapchain @@ -416,7 +414,7 @@ oldSwapchain.destroy() return - renderer.currentCommandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer(), oneTimeSubmit = true) + renderer.currentFrameCommandBuffer.beginRenderCommands(renderer.renderPass, renderer.swapchain.currentFramebuffer(), oneTimeSubmit = true) debug "Scene buffers:" for (location, buffer) in renderer.scenedata[scene].vertexBuffers.pairs: @@ -426,14 +424,14 @@ for (materialType, shaderPipeline) in renderer.renderPass.shaderPipelines: if scene.usesMaterial(materialType): debug &"Start shaderPipeline for '{materialType}'" - renderer.currentCommandBuffer.vkCmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, shaderPipeline.vk) - renderer.currentCommandBuffer.vkCmdBindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, shaderPipeline.layout, 0, 1, addr(renderer.scenedata[scene].descriptorSets[shaderPipeline.vk][renderer.swapchain.currentInFlight].vk), 0, nil) + renderer.currentFrameCommandBuffer.vkCmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, shaderPipeline.vk) + renderer.currentFrameCommandBuffer.vkCmdBindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, shaderPipeline.layout, 0, 1, addr(renderer.scenedata[scene].descriptorSets[shaderPipeline.vk][renderer.swapchain.currentInFlight].vk), 0, nil) for (drawable, mesh) in renderer.scenedata[scene].drawables.filterIt(it[1].visible and it[1].material.theType == materialType): - drawable.draw(renderer.currentCommandBuffer, vertexBuffers = renderer.scenedata[scene].vertexBuffers, indexBuffer = renderer.scenedata[scene].indexBuffer, shaderPipeline.vk) + drawable.draw(renderer.currentFrameCommandBuffer, vertexBuffers = renderer.scenedata[scene].vertexBuffers, indexBuffer = renderer.scenedata[scene].indexBuffer, shaderPipeline.vk) - renderer.currentCommandBuffer.endRenderCommands() + renderer.currentFrameCommandBuffer.endRenderCommands() - if not renderer.swapchain.swap(renderer.queue, renderer.currentCommandBuffer): + if not renderer.swapchain.swap(renderer.queue, renderer.currentFrameCommandBuffer): let res = renderer.swapchain.recreate() if res.isSome: var oldSwapchain = renderer.swapchain diff -r 17943f768402 -r 125f808f8fea semicongine/vulkan/swapchain.nim --- a/semicongine/vulkan/swapchain.nim Sat Mar 30 22:21:47 2024 +0700 +++ b/semicongine/vulkan/swapchain.nim Sat Mar 30 23:10:50 2024 +0700 @@ -108,7 +108,7 @@ assert swapchain.vk.valid swapchain.framebuffers[swapchain.currentFramebufferIndex] -proc nextFrame*(swapchain: var Swapchain): Option[int] = +proc nextFrame*(swapchain: var Swapchain): bool = assert swapchain.device.vk.valid assert swapchain.vk.valid @@ -125,9 +125,9 @@ if nextImageResult == VK_SUCCESS: swapchain.queueFinishedFence[swapchain.currentInFlight].reset() - result = some(swapchain.currentInFlight) + return true else: - result = none(int) + return false proc swap*(swapchain: var Swapchain, queue: Queue, commandBuffer: VkCommandBuffer): bool = assert swapchain.device.vk.valid