# HG changeset patch # User Sam # Date 1684581441 -25200 # Node ID 2fca78b0c0d664f6140aa1f853b2d53b86803787 # Parent 4a7b8cd88e0e5a8b76f5a1130b0caaccd71e764e fix: incorrect vertex data alignment diff -r 4a7b8cd88e0e -r 2fca78b0c0d6 src/semicongine/renderer.nim --- a/src/semicongine/renderer.nim Sat May 20 17:45:12 2023 +0700 +++ b/src/semicongine/renderer.nim Sat May 20 18:17:21 2023 +0700 @@ -52,9 +52,9 @@ proc setupDrawableBuffers*(renderer: var Renderer, scene: Scene, inputs: seq[ShaderAttribute], transformAttribute="") = assert not (scene in renderer.scenedata) + const VERTEX_ATTRIB_ALIGNMENT = 4 # used for buffer alignment var data = SceneData() - # when mesh transformation are handled through the scenegraph-transformation, set it up here if transformattribute != "": var hasTransformAttribute = false @@ -111,6 +111,10 @@ inc bindingNumber # setup one buffer per attribute-location-type for mesh in allMeshes: + # align size to VERTEX_ATTRIB_ALIGNMENT bytes (the important thing is the correct alignment of the offsets, bu + # we need to expand the buffer size as well, therefore considering alignment already here as well + if perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: + perLocationSizes[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationSizes[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) perLocationSizes[attribute.memoryPerformanceHint] += mesh.dataSize(attribute.name) for memoryPerformanceHint, bufferSize in perLocationSizes.pairs: if bufferSize > 0: @@ -131,6 +135,8 @@ if pdata != nil: # no data data.vertexBuffers[attribute.memoryPerformanceHint].setData(pdata, size, perLocationOffsets[attribute.memoryPerformanceHint]) perLocationOffsets[attribute.memoryPerformanceHint] += size + if perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT != 0: + perLocationOffsets[attribute.memoryPerformanceHint] += VERTEX_ATTRIB_ALIGNMENT - (perLocationOffsets[attribute.memoryPerformanceHint] mod VERTEX_ATTRIB_ALIGNMENT) let indexed = mesh.indexType != None var drawable = Drawable(