diff src/zamikongine/descriptor.nim @ 33:94c38e4b5782

did: refactoring, move more from make to nimscript
author Sam <sam@basx.dev>
date Sun, 15 Jan 2023 23:23:54 +0700
parents 9edca5dc4e93
children
line wrap: on
line diff
--- a/src/zamikongine/descriptor.nim	Sat Jan 14 23:34:50 2023 +0700
+++ b/src/zamikongine/descriptor.nim	Sun Jan 15 23:23:54 2023 +0700
@@ -33,8 +33,8 @@
     )
   checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result))
 
-proc createUniformBuffers*[nBuffers: static int, T](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] =
-  let size = sizeof(T)
+proc createUniformBuffers*[nBuffers: static int, Uniforms](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] =
+  let size = sizeof(Uniforms)
   for i in 0 ..< nBuffers:
     var buffer = InitBuffer(
       device,
@@ -51,14 +51,15 @@
 func generateGLSLUniformDeclarations*[Uniforms](binding: int = 0): string {.compileTime.} =
   var stmtList: seq[string]
 
-  let uniformTypeName = name(Uniforms).toUpper()
-  let uniformInstanceName = name(Uniforms).toLower()
-  stmtList.add(&"layout(binding = {binding}) uniform {uniformTypeName} {{")
-  for fieldname, value in Uniforms().fieldPairs:
-    when typeof(value) is Descriptor:
-      let glsltype = getGLSLType[getDescriptorType(value)]()
-      let n = fieldname
-      stmtList.add(&"    {glsltype} {n};")
-  stmtList.add(&"}} {uniformInstanceName};")
+  when not (Uniforms is void):
+    let uniformTypeName = name(Uniforms).toUpper()
+    let uniformInstanceName = name(Uniforms).toLower()
+    stmtList.add(&"layout(binding = {binding}) uniform {uniformTypeName} {{")
+    for fieldname, value in Uniforms().fieldPairs:
+      when typeof(value) is Descriptor:
+        let glsltype = getGLSLType[getDescriptorType(value)]()
+        let n = fieldname
+        stmtList.add(&"    {glsltype} {n};")
+    stmtList.add(&"}} {uniformInstanceName};")
 
   return stmtList.join("\n")