annotate src/vertex.nim @ 17:b40466fa446a

add: vertex basics, some refactoring
author Sam <sam@basx.dev>
date Sun, 01 Jan 2023 01:00:50 +0700
parents a571db114152
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
1 import std/macros
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
2 import std/strutils
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
3 import std/strformat
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
4 import std/typetraits
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
5
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
6 import ./math/vector
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
7 import ./vulkan
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
8
13
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
9 type
17
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
10 VertexAttributeType = SomeNumber|Vec
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
11 VertexAttribute*[T:VertexAttributeType] = object
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
12
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
13
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
14 # from https://registry.khronos.org/vulkan/specs/1.3-extensions/html/chap15.html
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
15 func nLocationSlots[T: VertexAttributeType](): int =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
16 when (T is Vec3[float64] or T is Vec3[uint64] or T is Vec4[float64] or T is Vec4[float64]):
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
17 2
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
18 else:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
19 1
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
20
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
21 # numbers
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
22 func getVkFormat[T: VertexAttributeType](): VkFormat =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
23 when T is uint8: VK_FORMAT_R8_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
24 elif T is int8: VK_FORMAT_R8_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
25 elif T is uint16: VK_FORMAT_R16_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
26 elif T is int16: VK_FORMAT_R16_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
27 elif T is uint32: VK_FORMAT_R32_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
28 elif T is int32: VK_FORMAT_R32_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
29 elif T is uint64: VK_FORMAT_R64_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
30 elif T is int64: VK_FORMAT_R64_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
31 elif T is float32: VK_FORMAT_R32_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
32 elif T is float64: VK_FORMAT_R64_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
33 elif T is Vec2[uint8]: VK_FORMAT_R8G8_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
34 elif T is Vec2[int8]: VK_FORMAT_R8G8_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
35 elif T is Vec2[uint16]: VK_FORMAT_R16G16_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
36 elif T is Vec2[int16]: VK_FORMAT_R16G16_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
37 elif T is Vec2[uint32]: VK_FORMAT_R32G32_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
38 elif T is Vec2[int32]: VK_FORMAT_R32G32_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
39 elif T is Vec2[uint64]: VK_FORMAT_R64G64_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
40 elif T is Vec2[int64]: VK_FORMAT_R64G64_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
41 elif T is Vec2[float32]: VK_FORMAT_R32G32_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
42 elif T is Vec2[float64]: VK_FORMAT_R64G64_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
43 elif T is Vec3[uint8]: VK_FORMAT_R8G8B8_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
44 elif T is Vec3[int8]: VK_FORMAT_R8G8B8_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
45 elif T is Vec3[uint16]: VK_FORMAT_R16G16B16_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
46 elif T is Vec3[int16]: VK_FORMAT_R16G16B16_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
47 elif T is Vec3[uint32]: VK_FORMAT_R32G32B32_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
48 elif T is Vec3[int32]: VK_FORMAT_R32G32B32_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
49 elif T is Vec3[uint64]: VK_FORMAT_R64G64B64_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
50 elif T is Vec3[int64]: VK_FORMAT_R64G64B64_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
51 elif T is Vec3[float32]: VK_FORMAT_R32G32B32_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
52 elif T is Vec3[float64]: VK_FORMAT_R64G64B64_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
53 elif T is Vec4[uint8]: VK_FORMAT_R8G8B8A8_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
54 elif T is Vec4[int8]: VK_FORMAT_R8G8B8A8_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
55 elif T is Vec4[uint16]: VK_FORMAT_R16G16B16A16_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
56 elif T is Vec4[int16]: VK_FORMAT_R16G16B16A16_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
57 elif T is Vec4[uint32]: VK_FORMAT_R32G32B32A32_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
58 elif T is Vec4[int32]: VK_FORMAT_R32G32B32A32_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
59 elif T is Vec4[uint64]: VK_FORMAT_R64G64B64A64_UINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
60 elif T is Vec4[int64]: VK_FORMAT_R64G64B64A64_SINT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
61 elif T is Vec4[float32]: VK_FORMAT_R32G32B32A32_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
62 elif T is Vec4[float64]: VK_FORMAT_R64G64B64A64_SFLOAT
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
63
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
64 func getGLSLType[T: VertexAttributeType](): string =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
65 # todo: likely not correct as we would need to enable some
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
66 # extensions somewhere (Vulkan/GLSL compiler?) to have
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
67 # everything work as intended. Or maybe the GPU driver does
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
68 # some automagic conversion stuf..
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
69 when T is uint8: "uint"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
70 elif T is int8: "int"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
71 elif T is uint16: "uint"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
72 elif T is int16: "int"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
73 elif T is uint32: "uint"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
74 elif T is int32: "int"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
75 elif T is uint64: "uint"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
76 elif T is int64: "int"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
77 elif T is float32: "float"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
78 elif T is float64: "double"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
79
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
80 elif T is Vec2[uint8]: "uvec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
81 elif T is Vec2[int8]: "ivec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
82 elif T is Vec2[uint16]: "uvec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
83 elif T is Vec2[int16]: "ivec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
84 elif T is Vec2[uint32]: "uvec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
85 elif T is Vec2[int32]: "ivec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
86 elif T is Vec2[uint64]: "uvec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
87 elif T is Vec2[int64]: "ivec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
88 elif T is Vec2[float32]: "vec2"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
89 elif T is Vec2[float64]: "dvec2"
13
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
90
17
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
91 elif T is Vec3[uint8]: "uvec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
92 elif T is Vec3[int8]: "ivec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
93 elif T is Vec3[uint16]: "uvec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
94 elif T is Vec3[int16]: "ivec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
95 elif T is Vec3[uint32]: "uvec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
96 elif T is Vec3[int32]: "ivec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
97 elif T is Vec3[uint64]: "uvec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
98 elif T is Vec3[int64]: "ivec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
99 elif T is Vec3[float32]: "vec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
100 elif T is Vec3[float64]: "dvec3"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
101
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
102 elif T is Vec4[uint8]: "uvec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
103 elif T is Vec4[int8]: "ivec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
104 elif T is Vec4[uint16]: "uvec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
105 elif T is Vec4[int16]: "ivec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
106 elif T is Vec4[uint32]: "uvec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
107 elif T is Vec4[int32]: "ivec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
108 elif T is Vec4[uint64]: "uvec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
109 elif T is Vec4[int64]: "ivec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
110 elif T is Vec4[float32]: "vec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
111 elif T is Vec4[float64]: "dvec4"
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
112
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
113 template rawAttributeType(v: VertexAttribute): auto = get(genericParams(typeof(v)), 0)
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
114
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
115 func generateGLSL[T](): string =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
116 var stmtList: seq[string]
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
117 var i = 0
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
118 for name, value in T().fieldPairs:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
119 when typeof(value) is VertexAttribute:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
120 let glsltype = getGLSLType[rawAttributeType(value)]()
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
121 let n = name
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
122 stmtList.add(&"layout(location = {i}) in {glsltype} {n};")
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
123 i += nLocationSlots[rawAttributeType(value)]()
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
124
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
125 return stmtList.join("\n")
13
a571db114152 add: vector/matrix modules, tests, nim config script
Sam <sam@basx.dev>
parents:
diff changeset
126
17
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
127 func generateInputVertexBinding*[T](bindingoffset: int = 0, locationoffset: int = 0): seq[VkVertexInputBindingDescription] =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
128 # packed attribute data, not interleaved (aks "struct of arrays")
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
129 var binding = bindingoffset
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
130 for name, value in T().fieldPairs:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
131 when typeof(value) is VertexAttribute:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
132 result.add(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
133 VkVertexInputBindingDescription(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
134 binding: uint32(binding),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
135 stride: uint32(sizeof(rawAttributeType(value))),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
136 inputRate: VK_VERTEX_INPUT_RATE_VERTEX, # VK_VERTEX_INPUT_RATE_INSTANCE for instances
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
137 )
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
138 )
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
139 binding += 1
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
140
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
141 func generateInputAttributeBinding*[T](bindingoffset: int = 0, locationoffset: int = 0): seq[VkVertexInputAttributeDescription] =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
142 # packed attribute data, not interleaved (aks "struct of arrays")
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
143 var location = 0
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
144 var binding = bindingoffset
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
145 for name, value in T().fieldPairs:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
146 when typeof(value) is VertexAttribute:
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
147 result.add(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
148 VkVertexInputAttributeDescription(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
149 binding: uint32(binding),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
150 location: uint32(location),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
151 format: getVkFormat[rawAttributeType(value)](),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
152 offset: 0,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
153 )
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
154 )
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
155 location += nLocationSlots[rawAttributeType(value)]()
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
156 binding += 1
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
157
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
158 func getBindingDescription(binding: int): auto =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
159 VkVertexInputBindingDescription(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
160 binding: uint32(binding),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
161 stride: 0, # either sizeof of vertex (array of structs) or of attribute (struct of arrays)
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
162 inputRate: VK_VERTEX_INPUT_RATE_VERTEX, # VK_VERTEX_INPUT_RATE_INSTANCE for instances
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
163 )
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
164
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
165 func getAttributeDescriptions(binding: int): auto =
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
166 [
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
167 VkVertexInputAttributeDescription(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
168 binding: 0'u32,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
169 location: 0,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
170 format: VK_FORMAT_R32G32_SFLOAT,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
171 offset: 0,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
172 ),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
173 VkVertexInputAttributeDescription(
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
174 binding: 0'u32,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
175 location: 1,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
176 format: VK_FORMAT_R32G32B32_SFLOAT,
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
177 offset: uint32(sizeof(Vec2)), # use offsetOf?
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
178 ),
b40466fa446a add: vertex basics, some refactoring
Sam <sam@basx.dev>
parents: 13
diff changeset
179 ]