# HG changeset patch # User sam # Date 1723817221 -25200 # Node ID ac200eaa9d9e24edc4ee97c9ede3fa36b9d21213 # Parent 3ba2c180e52c3751b3f359773da47f8929c592ea add: support for specific vertex count when rendering diff -r 3ba2c180e52c -r ac200eaa9d9e semicongine/rendering/renderer.nim --- 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) diff -r 3ba2c180e52c -r ac200eaa9d9e semicongine/text/font.nim --- 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: