Mercurial > games > semicongine
changeset 1325:fa774f3dc15f
add: support manual specifying vertex/instance counts
author | sam <sam@basx.dev> |
---|---|
date | Fri, 16 Aug 2024 23:41:57 +0700 |
parents | ac200eaa9d9e |
children | 41f3612ef38d |
files | semicongine/rendering/renderer.nim semicongine/text/font.nim |
diffstat | 2 files changed, 8 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 )
--- 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: