Mercurial > games > semicongine
changeset 227:297bffdf3d94
add: better support for array members
author | Sam <sam@basx.dev> |
---|---|
date | Mon, 15 May 2023 23:51:06 +0700 |
parents | 3cbbf50e9e4c |
children | 6b02e108ba54 |
files | src/semicongine/core/gpu_data.nim |
diffstat | 1 files changed, 15 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/core/gpu_data.nim Mon May 15 18:25:24 2023 +0700 +++ b/src/semicongine/core/gpu_data.nim Mon May 15 23:51:06 2023 +0700 @@ -149,7 +149,7 @@ ShaderAttribute* = object name*: string thetype*: DataType - arrayCount*: int + arrayCount*: uint32 perInstance*: bool memoryPerformanceHint*: MemoryPerformanceHint @@ -217,8 +217,13 @@ of Sampler2D: 0 func size*(attribute: ShaderAttribute, perDescriptor=false): uint32 = - if perDescriptor: attribute.thetype.size div attribute.thetype.numberOfVertexInputAttributeDescriptors - else: attribute.thetype.size + if perDescriptor: + attribute.thetype.size div attribute.thetype.numberOfVertexInputAttributeDescriptors + else: + if attribute.arrayCount == 0: + attribute.thetype.size + else: + attribute.thetype.size * attribute.arrayCount func size*(thetype: seq[ShaderAttribute]): uint32 = for attribute in thetype: @@ -287,7 +292,7 @@ func attr*[T: GPUType]( name: string, perInstance=false, - arrayCount=0, + arrayCount=0'u32, memoryPerformanceHint=PreferFastRead, ): auto = ShaderAttribute( @@ -1006,7 +1011,7 @@ return @[] var i = 0'u32 for attribute in group: - assert attribute.arrayCount == 0, "arrays not yet supported for shader vertex attributes" + assert attribute.arrayCount == 0, "arrays not supported for shader vertex attributes" result.add &"layout(location = {i}) in {attribute.thetype.glslType} {attribute.name};" for j in 0 ..< attribute.thetype.numberOfVertexInputAttributeDescriptors: i += attribute.thetype.nLocationSlots @@ -1017,8 +1022,10 @@ # currently only a single uniform block supported, therefore binding = 0 result.add(&"layout(binding = {binding}) uniform T{blockName} {{") for attribute in group: - assert attribute.arrayCount == 0, "arrays not yet supported for uniforms" - result.add(&" {attribute.thetype.glslType} {attribute.name};") + var arrayDecl = "" + if attribute.arrayCount > 0: + arrayDecl = &"[{attribute.arrayCount}]" + result.add(&" {attribute.thetype.glslType} {attribute.name}{arrayDecl};") result.add(&"}} {blockName};") func glslSamplers*(group: seq[ShaderAttribute], basebinding: int): seq[string] = @@ -1037,6 +1044,6 @@ return @[] var i = 0'u32 for attribute in group: - assert attribute.arrayCount == 0, "arrays not yet supported for outputs" + assert attribute.arrayCount == 0, "arrays not supported for outputs" result.add &"layout(location = {i}) out {attribute.thetype.glslType} {attribute.name};" i += 1