# HG changeset patch # User sam # Date 1711883626 -25200 # Node ID 7a0d5fc00f4fd028badbd01a7932c5f00e1473c7 # Parent 70d4d53ee9d2569b04af9cc49a992768475e0b59 add: a few more exposed parameters to the render API diff -r 70d4d53ee9d2 -r 7a0d5fc00f4f semicongine/engine.nim --- a/semicongine/engine.nim Sat Mar 30 23:10:50 2024 +0700 +++ b/semicongine/engine.nim Sun Mar 31 18:13:46 2024 +0700 @@ -112,7 +112,14 @@ ) startMixerThread() -proc initRenderer*(engine: var Engine, shaders: openArray[(MaterialType, ShaderConfiguration)], clearColor = Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32]), backFaceCulling = true) = +proc initRenderer*( + engine: var Engine, + shaders: openArray[(MaterialType, ShaderConfiguration)], + clearColor = newVec4f(0, 0, 0, 0), + backFaceCulling = true, + vSync = false, + inFlightFrames = 2, +) = assert not engine.renderer.isSome var allShaders = @shaders @@ -122,10 +129,16 @@ allShaders.add (PANEL_MATERIAL_TYPE, PANEL_SHADER) if not shaders.mapIt(it[0]).contains(TEXT_MATERIAL_TYPE): allShaders.add (TEXT_MATERIAL_TYPE, TEXT_SHADER) - engine.renderer = some(engine.device.initRenderer(shaders = allShaders, clearColor = clearColor, backFaceCulling = backFaceCulling)) + engine.renderer = some(engine.device.initRenderer( + shaders = allShaders, + clearColor = clearColor, + backFaceCulling = backFaceCulling, + vSync = vSync, + inFlightFrames = inFlightFrames, + )) -proc initRenderer*(engine: var Engine, clearColor = Vec4f([0.8'f32, 0.8'f32, 0.8'f32, 1'f32])) = - engine.initRenderer(@[], clearColor) +proc initRenderer*(engine: var Engine, clearColor = newVec4f(0, 0, 0, 0), vSync = false) = + engine.initRenderer(@[], clearColor, vSync = vSync) proc loadScene*(engine: var Engine, scene: var Scene) = assert engine.renderer.isSome diff -r 70d4d53ee9d2 -r 7a0d5fc00f4f semicongine/renderer.nim --- a/semicongine/renderer.nim Sat Mar 30 23:10:50 2024 +0700 +++ b/semicongine/renderer.nim Sun Mar 31 18:13:46 2024 +0700 @@ -48,7 +48,14 @@ 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 = +proc initRenderer*( + device: Device, + shaders: openArray[(MaterialType, ShaderConfiguration)], + clearColor = newVec4f(0, 0, 0, 0), + backFaceCulling = true, + vSync = false, + inFlightFrames = 2, +): Renderer = assert device.vk.valid result.device = device @@ -56,6 +63,8 @@ let swapchain = device.createSwapchain( result.renderPass.vk, device.physicalDevice.getSurfaceFormats().filterSurfaceFormat(), + vSync = vSync, + inFlightFrames = inFlightFrames, ) if not swapchain.isSome: raise newException(Exception, "Unable to create swapchain") diff -r 70d4d53ee9d2 -r 7a0d5fc00f4f semicongine/vulkan/swapchain.nim --- a/semicongine/vulkan/swapchain.nim Sat Mar 30 23:10:50 2024 +0700 +++ b/semicongine/vulkan/swapchain.nim Sun Mar 31 18:13:46 2024 +0700 @@ -28,14 +28,15 @@ imageCount: uint32 inFlightFrames*: int presentQueue: Queue + vSync: bool proc createSwapchain*( device: Device, renderPass: VkRenderPass, surfaceFormat: VkSurfaceFormatKHR, + inFlightFrames: int, desiredNumberOfImages = 3'u32, - inFlightFrames = 2, oldSwapchain = VkSwapchainKHR(0), vSync = false ): Option[Swapchain] = @@ -78,7 +79,8 @@ surfaceFormat: surfaceFormat, dimension: TVec2[uint32]([capabilities.currentExtent.width, capabilities.currentExtent.height]), inFlightFrames: inFlightFrames, - renderPass: renderPass + renderPass: renderPass, + vSync: vSync ) if device.vk.vkCreateSwapchainKHR(addr(createInfo), nil, addr(swapchain.vk)) == VK_SUCCESS: @@ -199,4 +201,5 @@ desiredNumberOfImages = swapchain.imageCount, inFlightFrames = swapchain.inFlightFrames, oldSwapchain = swapchain.vk, + vSync = swapchain.vSync )