Mercurial > games > semicongine
comparison tests/test_vulkan_wrapper.nim @ 1139:114f395b9144
did: finish refactoring and updated all tests accordingly
author | sam <sam@basx.dev> |
---|---|
date | Sat, 08 Jun 2024 14:58:25 +0700 |
parents | 02e1d2658ff5 |
children |
comparison
equal
deleted
inserted
replaced
1138:02e1d2658ff5 | 1139:114f395b9144 |
---|---|
18 "position": Vec3F32, | 18 "position": Vec3F32, |
19 "uv": Vec2F32, | 19 "uv": Vec2F32, |
20 }.toTable, | 20 }.toTable, |
21 attributes: {"baseTexture": TextureType}.toTable | 21 attributes: {"baseTexture": TextureType}.toTable |
22 ) | 22 ) |
23 mat = Mat1Type.initMaterialData( | 23 mat = Mat1Type.InitMaterialData( |
24 name = "mat", | 24 name = "mat", |
25 attributes = { | 25 attributes = { |
26 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | 26 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ |
27 R, R, R, R, R, | 27 R, R, R, R, R, |
28 R, R, W, R, R, | 28 R, R, W, R, R, |
39 "position": Vec3F32, | 39 "position": Vec3F32, |
40 "uv": Vec2F32, | 40 "uv": Vec2F32, |
41 }.toTable, | 41 }.toTable, |
42 attributes: {"baseTexture": TextureType}.toTable | 42 attributes: {"baseTexture": TextureType}.toTable |
43 ) | 43 ) |
44 mat2 = Mat2Type.initMaterialData( | 44 mat2 = Mat2Type.InitMaterialData( |
45 name = "mat2", | 45 name = "mat2", |
46 attributes = { | 46 attributes = { |
47 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ | 47 "baseTexture": InitDataList(@[Texture(isGrayscale: false, colorImage: Image[RGBAPixel](width: 5, height: 5, imagedata: @[ |
48 R, W, R, W, R, | 48 R, W, R, W, R, |
49 W, R, W, R, W, | 49 W, R, W, R, W, |
51 W, R, W, R, W, | 51 W, R, W, R, W, |
52 R, W, R, W, R, | 52 R, W, R, W, R, |
53 ]), sampler: sampler)]) | 53 ]), sampler: sampler)]) |
54 }.toTable | 54 }.toTable |
55 ) | 55 ) |
56 mat3 = SINGLE_COLOR_MATERIAL.initMaterialData( | 56 mat3 = SINGLE_COLOR_MATERIAL.InitMaterialData( |
57 name = "mat3", | 57 name = "mat3", |
58 attributes = { | 58 attributes = { |
59 "color": InitDataList(@[NewVec4f(0, 1, 0, 1)]) | 59 "color": InitDataList(@[NewVec4f(0, 1, 0, 1)]) |
60 }.toTable | 60 }.toTable |
61 ) | 61 ) |
62 | 62 |
63 proc scene_different_mesh_types(): seq[Mesh] = | 63 proc scene_different_mesh_types(): seq[Mesh] = |
64 @[ | 64 @[ |
65 newMesh( | 65 NewMesh( |
66 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], | 66 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], |
67 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], | 67 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], |
68 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 68 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
69 material = mat, | 69 material = mat, |
70 transform = Translate(-0.7, -0.5), | 70 transform = Translate(-0.7, -0.5), |
71 ), | 71 ), |
72 newMesh( | 72 NewMesh( |
73 positions = [NewVec3f(0.0, -0.4), NewVec3f(0.4, 0.4), NewVec3f(-0.4, 0.5)], | 73 positions = [NewVec3f(0.0, -0.4), NewVec3f(0.4, 0.4), NewVec3f(-0.4, 0.5)], |
74 uvs = [NewVec2f(0.0, -0.4), NewVec2f(0.4, 0.4), NewVec2f(-0.4, 0.5)], | 74 uvs = [NewVec2f(0.0, -0.4), NewVec2f(0.4, 0.4), NewVec2f(-0.4, 0.5)], |
75 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 75 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
76 material = mat, | 76 material = mat, |
77 transform = Translate(0, -0.5), | 77 transform = Translate(0, -0.5), |
78 ), | 78 ), |
79 newMesh( | 79 NewMesh( |
80 positions = [NewVec3f(0.0, 0.5), NewVec3f(0.5, -0.5), NewVec3f(-0.5, -0.5)], | 80 positions = [NewVec3f(0.0, 0.5), NewVec3f(0.5, -0.5), NewVec3f(-0.5, -0.5)], |
81 uvs = [NewVec2f(0.0, 0.5), NewVec2f(0.5, -0.5), NewVec2f(-0.5, -0.5)], | 81 uvs = [NewVec2f(0.0, 0.5), NewVec2f(0.5, -0.5), NewVec2f(-0.5, -0.5)], |
82 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 82 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
83 indices = [[0'u16, 2'u16, 1'u16]], | 83 indices = [[0'u16, 2'u16, 1'u16]], |
84 material = mat2, | 84 material = mat2, |
85 transform = Translate(0.7, -0.5), | 85 transform = Translate(0.7, -0.5), |
86 ), | 86 ), |
87 newMesh( | 87 NewMesh( |
88 positions = [NewVec3f(0.0, 0.4), NewVec3f(0.4, -0.4), NewVec3f(-0.4, -0.4)], | 88 positions = [NewVec3f(0.0, 0.4), NewVec3f(0.4, -0.4), NewVec3f(-0.4, -0.4)], |
89 uvs = [NewVec2f(0.0, 0.4), NewVec2f(0.4, -0.4), NewVec2f(-0.4, -0.4)], | 89 uvs = [NewVec2f(0.0, 0.4), NewVec2f(0.4, -0.4), NewVec2f(-0.4, -0.4)], |
90 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 90 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
91 indices = [[0'u16, 2'u16, 1'u16]], | 91 indices = [[0'u16, 2'u16, 1'u16]], |
92 material = mat2, | 92 material = mat2, |
93 transform = Translate(-0.7, 0.5), | 93 transform = Translate(-0.7, 0.5), |
94 ), | 94 ), |
95 newMesh( | 95 NewMesh( |
96 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], | 96 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], |
97 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], | 97 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], |
98 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], | 98 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], |
99 indices = [[0'u32, 2'u32, 1'u32]], | 99 indices = [[0'u32, 2'u32, 1'u32]], |
100 autoResize = false, | 100 autoResize = false, |
101 material = mat2, | 101 material = mat2, |
102 transform = Translate(0, 0.5), | 102 transform = Translate(0, 0.5), |
103 ), | 103 ), |
104 newMesh( | 104 NewMesh( |
105 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], | 105 positions = [NewVec3f(0.4, 0.5), NewVec3f(0.9, -0.3), NewVec3f(0.0, -0.3)], |
106 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], | 106 uvs = [NewVec2f(0.4, 0.5), NewVec2f(0.9, -0.3), NewVec2f(0.0, -0.3)], |
107 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], | 107 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], |
108 indices = [[0'u32, 2'u32, 1'u32]], | 108 indices = [[0'u32, 2'u32, 1'u32]], |
109 autoResize = false, | 109 autoResize = false, |
112 ), | 112 ), |
113 ] | 113 ] |
114 | 114 |
115 proc scene_simple(): seq[Mesh] = | 115 proc scene_simple(): seq[Mesh] = |
116 @[ | 116 @[ |
117 newMesh( | 117 NewMesh( |
118 positions = [NewVec3f(0.0, -0.3), NewVec3f(0.3, 0.3), NewVec3f(-0.3, 0.3)], | 118 positions = [NewVec3f(0.0, -0.3), NewVec3f(0.3, 0.3), NewVec3f(-0.3, 0.3)], |
119 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 119 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
120 uvs = [NewVec2f(0.0, -0.3), NewVec2f(0.3, 0.3), NewVec2f(-0.3, 0.3)], | 120 uvs = [NewVec2f(0.0, -0.3), NewVec2f(0.3, 0.3), NewVec2f(-0.3, 0.3)], |
121 material = mat, | 121 material = mat, |
122 transform = Translate(0.4, 0.4), | 122 transform = Translate(0.4, 0.4), |
123 ), | 123 ), |
124 newMesh( | 124 NewMesh( |
125 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], | 125 positions = [NewVec3f(0.0, -0.5), NewVec3f(0.5, 0.5), NewVec3f(-0.5, 0.5)], |
126 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 126 colors = [NewVec4f(1.0, 0.0, 0.0, 1), NewVec4f(0.0, 1.0, 0.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
127 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], | 127 uvs = [NewVec2f(0.0, -0.5), NewVec2f(0.5, 0.5), NewVec2f(-0.5, 0.5)], |
128 material = mat, | 128 material = mat, |
129 transform = Translate(0.4, -0.4), | 129 transform = Translate(0.4, -0.4), |
130 ), | 130 ), |
131 newMesh( | 131 NewMesh( |
132 positions = [NewVec3f(0.0, -0.6), NewVec3f(0.6, 0.6), NewVec3f(-0.6, 0.6)], | 132 positions = [NewVec3f(0.0, -0.6), NewVec3f(0.6, 0.6), NewVec3f(-0.6, 0.6)], |
133 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], | 133 colors = [NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1), NewVec4f(1.0, 1.0, 0.0, 1)], |
134 uvs = [NewVec2f(0.0, -0.6), NewVec2f(0.6, 0.6), NewVec2f(-0.6, 0.6)], | 134 uvs = [NewVec2f(0.0, -0.6), NewVec2f(0.6, 0.6), NewVec2f(-0.6, 0.6)], |
135 indices = [[0'u32, 1'u32, 2'u32]], | 135 indices = [[0'u32, 1'u32, 2'u32]], |
136 autoResize = false, | 136 autoResize = false, |
137 material = mat, | 137 material = mat, |
138 transform = Translate(-0.4, 0.4), | 138 transform = Translate(-0.4, 0.4), |
139 ), | 139 ), |
140 newMesh( | 140 NewMesh( |
141 positions = [NewVec3f(0.0, -0.8), NewVec3f(0.8, 0.8), NewVec3f(-0.8, 0.8)], | 141 positions = [NewVec3f(0.0, -0.8), NewVec3f(0.8, 0.8), NewVec3f(-0.8, 0.8)], |
142 colors = [NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], | 142 colors = [NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1), NewVec4f(0.0, 0.0, 1.0, 1)], |
143 uvs = [NewVec2f(0.0, -0.8), NewVec2f(0.8, 0.8), NewVec2f(-0.8, 0.8)], | 143 uvs = [NewVec2f(0.0, -0.8), NewVec2f(0.8, 0.8), NewVec2f(-0.8, 0.8)], |
144 indices = [[0'u16, 1'u16, 2'u16]], | 144 indices = [[0'u16, 1'u16, 2'u16]], |
145 instanceTransforms = [Unit4F32, Unit4F32], | 145 instanceTransforms = [Unit4F32, Unit4F32], |
147 transform = Translate(-0.4, -0.4), | 147 transform = Translate(-0.4, -0.4), |
148 ) | 148 ) |
149 ] | 149 ] |
150 | 150 |
151 proc scene_primitives(): seq[Mesh] = | 151 proc scene_primitives(): seq[Mesh] = |
152 var r = rect(color = "ff0000") | 152 var r = Rect(color = "ff0000") |
153 var t = tri(color = "0000ff") | 153 var t = Tri(color = "0000ff") |
154 var c = circle(color = "00ff00") | 154 var c = Circle(color = "00ff00") |
155 r.material = mat | 155 r.material = mat |
156 t.material = mat | 156 t.material = mat |
157 c.material = mat | 157 c.material = mat |
158 r.transform = Translate(NewVec3f(0.5, -0.3)) | 158 r.transform = Translate(NewVec3f(0.5, -0.3)) |
159 t.transform = Translate(NewVec3f(0.3, 0.3)) | 159 t.transform = Translate(NewVec3f(0.3, 0.3)) |
160 c.transform = Translate(NewVec3f(-0.3, 0.1)) | 160 c.transform = Translate(NewVec3f(-0.3, 0.1)) |
161 result = @[r, c, t] | 161 result = @[r, c, t] |
162 | 162 |
163 proc scene_flag(): seq[Mesh] = | 163 proc scene_flag(): seq[Mesh] = |
164 @[ | 164 @[ |
165 newMesh( | 165 NewMesh( |
166 positions = [NewVec3f(-1.0, -1.0), NewVec3f(1.0, -1.0), NewVec3f(1.0, 1.0), NewVec3f(-1.0, 1.0)], | 166 positions = [NewVec3f(-1.0, -1.0), NewVec3f(1.0, -1.0), NewVec3f(1.0, 1.0), NewVec3f(-1.0, 1.0)], |
167 uvs = [NewVec2f(-1.0, -1.0), NewVec2f(1.0, -1.0), NewVec2f(1.0, 1.0), NewVec2f(-1.0, 1.0)], | 167 uvs = [NewVec2f(-1.0, -1.0), NewVec2f(1.0, -1.0), NewVec2f(1.0, 1.0), NewVec2f(-1.0, 1.0)], |
168 colors = [NewVec4f(-1, -1, 1, 1), NewVec4f(1, -1, 1, 1), NewVec4f(1, 1, 1, 1), NewVec4f(-1, 1, 1, 1)], | 168 colors = [NewVec4f(-1, -1, 1, 1), NewVec4f(1, -1, 1, 1), NewVec4f(1, 1, 1, 1), NewVec4f(-1, 1, 1, 1)], |
169 indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], | 169 indices = [[0'u16, 1'u16, 2'u16], [2'u16, 3'u16, 0'u16]], |
170 material = mat, | 170 material = mat, |
172 ) | 172 ) |
173 ] | 173 ] |
174 | 174 |
175 proc scene_multi_material(): seq[Mesh] = | 175 proc scene_multi_material(): seq[Mesh] = |
176 var | 176 var |
177 r1 = rect(color = "ffffff") | 177 r1 = Rect(color = "ffffff") |
178 r2 = rect(color = "000000") | 178 r2 = Rect(color = "000000") |
179 r1.material = mat | 179 r1.material = mat |
180 r2.material = mat3 | 180 r2.material = mat3 |
181 r1.transform = Translate(NewVec3f(-0.5)) | 181 r1.transform = Translate(NewVec3f(-0.5)) |
182 r2.transform = Translate(NewVec3f(+0.5)) | 182 r2.transform = Translate(NewVec3f(+0.5)) |
183 result = @[r1, r2] | 183 result = @[r1, r2] |
185 proc main() = | 185 proc main() = |
186 var engine = InitEngine("Test") | 186 var engine = InitEngine("Test") |
187 | 187 |
188 # INIT RENDERER: | 188 # INIT RENDERER: |
189 const | 189 const |
190 shaderConfiguration1 = createShaderConfiguration( | 190 shaderConfiguration1 = CreateShaderConfiguration( |
191 name = "shader1", | 191 name = "shader1", |
192 inputs = [ | 192 inputs = [ |
193 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 193 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
194 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), | 194 Attr[Vec4f]("color", memoryPerformanceHint = PreferFastWrite), |
195 Attr[Mat4]("transform", perInstance = true), | 195 Attr[Mat4]("transform", perInstance = true), |
200 outputs = [Attr[Vec4f]("color")], | 200 outputs = [Attr[Vec4f]("color")], |
201 samplers = [Attr[Texture]("baseTexture")], | 201 samplers = [Attr[Texture]("baseTexture")], |
202 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", | 202 vertexCode = """gl_Position = vec4(position, 1.0) * transform; outcolor = color;""", |
203 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", | 203 fragmentCode = "color = texture(baseTexture, outcolor.xy) * 0.5 + outcolor * 0.5;", |
204 ) | 204 ) |
205 shaderConfiguration2 = createShaderConfiguration( | 205 shaderConfiguration2 = CreateShaderConfiguration( |
206 name = "shader2", | 206 name = "shader2", |
207 inputs = [ | 207 inputs = [ |
208 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), | 208 Attr[Vec3f]("position", memoryPerformanceHint = PreferFastRead), |
209 Attr[Mat4]("transform", perInstance = true), | 209 Attr[Mat4]("transform", perInstance = true), |
210 ], | 210 ], |