comparison src/zamikongine/vertex.nim @ 494:0c18638c7217

did: refactoring, move more from make to nimscript
author Sam <sam@basx.dev>
date Sun, 15 Jan 2023 23:23:54 +0700
parents 680c4b8ca28a
children b41733878bc6
comparison
equal deleted inserted replaced
493:680c4b8ca28a 494:0c18638c7217
12 VertexAttributeType = SomeNumber|Vec 12 VertexAttributeType = SomeNumber|Vec
13 AttributePurpose* = enum 13 AttributePurpose* = enum
14 Unknown, Position Color 14 Unknown, Position Color
15 GenericAttribute*[T:VertexAttributeType] = object 15 GenericAttribute*[T:VertexAttributeType] = object
16 data*: seq[T] 16 data*: seq[T]
17 PositionAttribute*[T:VertexAttributeType] = object 17 PositionAttribute*[T:Vec] = object
18 data*: seq[T] 18 data*: seq[T]
19 ColorAttribute*[T:VertexAttributeType] = object 19 ColorAttribute*[T:Vec] = object
20 data*: seq[T] 20 data*: seq[T]
21 VertexAttribute* = GenericAttribute|PositionAttribute|ColorAttribute 21 VertexAttribute* = GenericAttribute|PositionAttribute|ColorAttribute
22 22
23 template getAttributeType*(v: VertexAttribute): auto = get(genericParams(typeof(v)), 0) 23 template getAttributeType*(v: VertexAttribute): auto = get(genericParams(typeof(v)), 0)
24 24
83 if result == 0: 83 if result == 0:
84 result = uint32(value.data.len) 84 result = uint32(value.data.len)
85 else: 85 else:
86 assert result == uint32(value.data.len) 86 assert result == uint32(value.data.len)
87 87
88 func VertexAttributesCount*[T](): uint32 =
89 for name, value in T().fieldPairs:
90 when typeof(value) is VertexAttribute:
91 result += 1
92
88 func generateGLSLVertexDeclarations*[T](): string = 93 func generateGLSLVertexDeclarations*[T](): string =
89 var stmtList: seq[string] 94 var stmtList: seq[string]
90 var i = 0 95 var i = 0
91 for name, value in T().fieldPairs: 96 for name, value in T().fieldPairs:
92 when typeof(value) is VertexAttribute: 97 when typeof(value) is VertexAttribute: