changeset 1324:ac200eaa9d9e

add: support for specific vertex count when rendering
author sam <sam@basx.dev>
date Fri, 16 Aug 2024 21:07:01 +0700
parents 3ba2c180e52c
children fa774f3dc15f
files semicongine/rendering/renderer.nim semicongine/text/font.nim
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/rendering/renderer.nim	Thu Aug 15 18:37:00 2024 +0700
+++ b/semicongine/rendering/renderer.nim	Fri Aug 16 21:07:01 2024 +0700
@@ -568,8 +568,8 @@
   pipeline: Pipeline[TShader],
   mesh: TMesh,
   instances: TInstance,
+  fixedVertexCount = -1,
 ) =
-
   static: assertCanRenderMesh(TShader, TMesh, TInstance)
 
   var vertexBuffers: seq[VkBuffer]
@@ -639,7 +639,7 @@
   else:
     vkCmdDraw(
       commandBuffer = commandBuffer,
-      vertexCount = elementCount,
+      vertexCount = if fixedVertexCount < 0: elementCount else: fixedVertexCount,
       instanceCount = instanceCount,
       firstVertex = 0,
       firstInstance = 0
@@ -649,8 +649,9 @@
   commandBuffer: VkCommandBuffer,
   pipeline: Pipeline[TShader],
   mesh: TMesh,
+  fixedVertexCount = -1,
 ) =
-  render(commandBuffer, pipeline, mesh, EMPTY())
+  render(commandBuffer, pipeline, mesh, EMPTY(), fixedVertexCount)
 
 proc assertValidPushConstantType(TShader, TPushConstant: typedesc) =
   assert sizeof(TPushConstant) <= PUSH_CONSTANT_SIZE, "Push constant values must be <= 128 bytes"
@@ -668,6 +669,7 @@
   mesh: TMesh,
   instances: TInstance,
   pushConstant: TPushConstant,
+  fixedVertexCount = -1,
 ) =
   static: assertValidPushConstantType(TShader, TPushConstant)
   vkCmdPushConstants(
@@ -678,12 +680,13 @@
     size = PUSH_CONSTANT_SIZE,
     pValues = addr(pushConstant)
   );
-  render(commandBuffer, pipeline, mesh, instances)
+  render(commandBuffer, pipeline, mesh, instances, fixedVertexCount)
 proc renderWithPushConstant*[TShader, TMesh, TPushConstant](
   commandBuffer: VkCommandBuffer,
   pipeline: Pipeline[TShader],
   mesh: TMesh,
   pushConstant: TPushConstant,
+  fixedVertexCount = -1,
 ) =
   static: assertValidPushConstantType(TShader, TPushConstant)
   vkCmdPushConstants(
@@ -694,7 +697,7 @@
     size = PUSH_CONSTANT_SIZE,
     pValues = addr(pushConstant)
   );
-  render(commandBuffer, pipeline, mesh, EMPTY())
+  render(commandBuffer, pipeline, mesh, EMPTY(), fixedVertexCount)
 
 proc asGPUArray*[T](data: sink openArray[T], bufferType: static BufferType): auto =
   GPUArray[T, bufferType](data: @data)
--- a/semicongine/text/font.nim	Thu Aug 15 18:37:00 2024 +0700
+++ b/semicongine/text/font.nim	Fri Aug 16 21:07:01 2024 +0700
@@ -119,7 +119,7 @@
 ): Font =
   loadResource_intern(path, package = package).readTrueType(path.splitFile().name, charset & additional_codepoints.toSeq, lineHeightPixels)
 
-func textWidth*(text: seq[Rune], font: FontObj): float32 =
+func textWidth*(text: seq[Rune]|string, font: FontObj): float32 =
   var currentWidth = 0'f32
   var lineWidths: seq[float32]
   for i in 0 ..< text.len: