changeset 1058:7a0d5fc00f4f

add: a few more exposed parameters to the render API
author sam <sam@basx.dev>
date Sun, 31 Mar 2024 18:13:46 +0700
parents 70d4d53ee9d2
children 9c364af8d3f0
files semicongine/engine.nim semicongine/renderer.nim semicongine/vulkan/swapchain.nim
diffstat 3 files changed, 32 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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")
--- 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
   )