comparison 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
comparison
equal deleted inserted replaced
32:9edca5dc4e93 33:94c38e4b5782
31 bindingCount: 1, 31 bindingCount: 1,
32 pBindings: addr(layoutbinding) 32 pBindings: addr(layoutbinding)
33 ) 33 )
34 checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result)) 34 checkVkResult device.vkCreateDescriptorSetLayout(addr(layoutInfo), nil, addr(result))
35 35
36 proc createUniformBuffers*[nBuffers: static int, T](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] = 36 proc createUniformBuffers*[nBuffers: static int, Uniforms](device: VkDevice, physicalDevice: VkPhysicalDevice): array[nBuffers, Buffer] =
37 let size = sizeof(T) 37 let size = sizeof(Uniforms)
38 for i in 0 ..< nBuffers: 38 for i in 0 ..< nBuffers:
39 var buffer = InitBuffer( 39 var buffer = InitBuffer(
40 device, 40 device,
41 physicalDevice, 41 physicalDevice,
42 uint64(size), 42 uint64(size),
49 template getDescriptorType*(v: Descriptor): auto = get(genericParams(typeof(v)), 0) 49 template getDescriptorType*(v: Descriptor): auto = get(genericParams(typeof(v)), 0)
50 50
51 func generateGLSLUniformDeclarations*[Uniforms](binding: int = 0): string {.compileTime.} = 51 func generateGLSLUniformDeclarations*[Uniforms](binding: int = 0): string {.compileTime.} =
52 var stmtList: seq[string] 52 var stmtList: seq[string]
53 53
54 let uniformTypeName = name(Uniforms).toUpper() 54 when not (Uniforms is void):
55 let uniformInstanceName = name(Uniforms).toLower() 55 let uniformTypeName = name(Uniforms).toUpper()
56 stmtList.add(&"layout(binding = {binding}) uniform {uniformTypeName} {{") 56 let uniformInstanceName = name(Uniforms).toLower()
57 for fieldname, value in Uniforms().fieldPairs: 57 stmtList.add(&"layout(binding = {binding}) uniform {uniformTypeName} {{")
58 when typeof(value) is Descriptor: 58 for fieldname, value in Uniforms().fieldPairs:
59 let glsltype = getGLSLType[getDescriptorType(value)]() 59 when typeof(value) is Descriptor:
60 let n = fieldname 60 let glsltype = getGLSLType[getDescriptorType(value)]()
61 stmtList.add(&" {glsltype} {n};") 61 let n = fieldname
62 stmtList.add(&"}} {uniformInstanceName};") 62 stmtList.add(&" {glsltype} {n};")
63 stmtList.add(&"}} {uniformInstanceName};")
63 64
64 return stmtList.join("\n") 65 return stmtList.join("\n")