# HG changeset patch # User sam # Date 1723826517 -25200 # Node ID fa774f3dc15f8417872564a3d87a119932488916 # Parent ac200eaa9d9e24edc4ee97c9ede3fa36b9d21213 add: support manual specifying vertex/instance counts diff -r ac200eaa9d9e -r fa774f3dc15f semicongine/rendering/renderer.nim --- a/semicongine/rendering/renderer.nim Fri Aug 16 21:07:01 2024 +0700 +++ b/semicongine/rendering/renderer.nim Fri Aug 16 23:41:57 2024 +0700 @@ -73,7 +73,7 @@ proc initDescriptorSet*( renderData: RenderData, layout: VkDescriptorSetLayout, - descriptorSet: var DescriptorSetData, + descriptorSet: DescriptorSetData, ) = # santization checks @@ -556,7 +556,7 @@ if hasCustomPragma(attrValue, InstanceAttribute): var foundAttr = false for instAttrName, instAttrValue in default(TInstance).fieldPairs: - if attrName == instAttrName: + when attrName == instAttrName: assert typeof(instAttrValue) is GPUArray, "Instance attribute '" & attrName & "' must be a GPUArray" assert foundAttr == false, "Attribute '" & attrName & "' is defined in Mesh and Instance, can only be one" assert typeof(attrValue) is elementType(instAttrValue.data), "Type of shader attribute and mesh attribute '" & attrName & "' is not the same" @@ -569,6 +569,7 @@ mesh: TMesh, instances: TInstance, fixedVertexCount = -1, + fixedInstanceCount = -1, ) = static: assertCanRenderMesh(TShader, TMesh, TInstance) @@ -631,7 +632,7 @@ vkCmdDrawIndexed( commandBuffer = commandBuffer, indexCount = elementCount, - instanceCount = instanceCount, + instanceCount = if fixedInstanceCount == -1: instanceCount else: fixedInstanceCount.uint32, firstIndex = 0, vertexOffset = 0, firstInstance = 0 @@ -639,8 +640,8 @@ else: vkCmdDraw( commandBuffer = commandBuffer, - vertexCount = if fixedVertexCount < 0: elementCount else: fixedVertexCount, - instanceCount = instanceCount, + vertexCount = if fixedVertexCount < 0: elementCount else: fixedVertexCount.uint32, + instanceCount = if fixedInstanceCount == -1: instanceCount else: fixedInstanceCount.uint32, firstVertex = 0, firstInstance = 0 ) diff -r ac200eaa9d9e -r fa774f3dc15f semicongine/text/font.nim --- a/semicongine/text/font.nim Fri Aug 16 21:07:01 2024 +0700 +++ b/semicongine/text/font.nim Fri Aug 16 23:41:57 2024 +0700 @@ -119,7 +119,8 @@ ): Font = loadResource_intern(path, package = package).readTrueType(path.splitFile().name, charset & additional_codepoints.toSeq, lineHeightPixels) -func textWidth*(text: seq[Rune]|string, font: FontObj): float32 = +func textWidth*(theText: seq[Rune]|string, font: FontObj): float32 = + var text = when theText is string: theText.toRunes else: theText var currentWidth = 0'f32 var lineWidths: seq[float32] for i in 0 ..< text.len: