# HG changeset patch
# User Sam <sam@basx.dev>
# Date 1704716281 -25200
# Node ID a408af667e29ec0086cd4b7cd673b0c11efc063f
# Parent  a430b5febe22bc3272d77c137365d969502e2829
fix: error on bad uniform-attribute ordering

diff -r a430b5febe22 -r a408af667e29 semicongine/core/gpu_types.nim
--- a/semicongine/core/gpu_types.nim	Sun Jan 07 00:56:44 2024 +0700
+++ b/semicongine/core/gpu_types.nim	Mon Jan 08 19:18:01 2024 +0700
@@ -371,11 +371,14 @@
     return @[]
   # currently only a single uniform block supported, therefore binding = 0
   result.add(&"layout(std430, binding = {binding}) uniform T{blockName} {{")
+  var last_size = high(int)
   for attribute in group:
+    assert attribute.size <= last_size, &"The attribute '{attribute.name}' is bigger than the attribute before, which is not allowed" # using smaller uniform-types first will lead to problems (I think due to alignment, there is also some stuff on the internet about this ;)
     var arrayDecl = ""
     if attribute.arrayCount > 0:
       arrayDecl = &"[{attribute.arrayCount}]"
     result.add(&"    {attribute.theType.glslType} {attribute.name}{arrayDecl};")
+    last_size = attribute.size
   result.add(&"}} {blockName};")
 
 func glslSamplers*(group: openArray[ShaderAttribute], basebinding: int): seq[string] =