Mercurial > games > semicongine
comparison tests/test_rendering.nim @ 1242:e8b3dc80e48e
add: PNG loading and tests for it
author | sam <sam@basx.dev> |
---|---|
date | Mon, 22 Jul 2024 15:53:32 +0700 |
parents | 42eeb59f3a43 |
children | 01e9f41d35b1 |
comparison
equal
deleted
inserted
replaced
1241:a0ed1a918fda | 1242:e8b3dc80e48e |
---|---|
9 | 9 |
10 proc test_01_triangle(time: float32) = | 10 proc test_01_triangle(time: float32) = |
11 var renderdata = InitRenderData() | 11 var renderdata = InitRenderData() |
12 | 12 |
13 type | 13 type |
14 TrianglShader = object | 14 Shader = object |
15 position {.VertexAttribute.}: Vec3f | 15 position {.VertexAttribute.}: Vec3f |
16 color {.VertexAttribute.}: Vec3f | 16 color {.VertexAttribute.}: Vec3f |
17 fragmentColor {.Pass.}: Vec3f | 17 fragmentColor {.Pass.}: Vec3f |
18 outColor {.ShaderOutput.}: Vec4f | 18 outColor {.ShaderOutput.}: Vec4f |
19 # code | 19 # code |
30 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | 30 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), |
31 ) | 31 ) |
32 AssignBuffers(renderdata, mesh) | 32 AssignBuffers(renderdata, mesh) |
33 renderdata.FlushAllMemory() | 33 renderdata.FlushAllMemory() |
34 | 34 |
35 var | 35 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) |
36 pipeline = CreatePipeline[TrianglShader](renderPass = vulkan.swapchain.renderPass) | |
37 | 36 |
38 var start = getMonoTime() | 37 var start = getMonoTime() |
39 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 38 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
39 | |
40 WithNextFrame(framebuffer, commandbuffer): | 40 WithNextFrame(framebuffer, commandbuffer): |
41 | |
41 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 42 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
43 | |
42 WithPipeline(commandbuffer, pipeline): | 44 WithPipeline(commandbuffer, pipeline): |
45 | |
43 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | 46 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
44 | 47 |
45 # cleanup | 48 # cleanup |
46 checkVkResult vkDeviceWaitIdle(vulkan.device) | 49 checkVkResult vkDeviceWaitIdle(vulkan.device) |
47 DestroyPipeline(pipeline) | 50 DestroyPipeline(pipeline) |
102 | 105 |
103 var pipeline = CreatePipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) | 106 var pipeline = CreatePipeline[SomeShader](renderPass = vulkan.swapchain.renderPass) |
104 | 107 |
105 var start = getMonoTime() | 108 var start = getMonoTime() |
106 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 109 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
110 | |
107 WithNextFrame(framebuffer, commandbuffer): | 111 WithNextFrame(framebuffer, commandbuffer): |
112 | |
108 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 113 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
114 | |
109 WithPipeline(commandbuffer, pipeline): | 115 WithPipeline(commandbuffer, pipeline): |
116 | |
110 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) | 117 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesA) |
111 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) | 118 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad, instances = instancesB) |
112 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) | 119 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesA) |
113 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) | 120 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = tri, instances = instancesB) |
114 | 121 |
124 Material = object | 131 Material = object |
125 baseColor: Vec3f | 132 baseColor: Vec3f |
126 | 133 |
127 Uniforms = object | 134 Uniforms = object |
128 material: GPUValue[Material, UniformBuffer] | 135 material: GPUValue[Material, UniformBuffer] |
129 texture1: Image[TVec4[uint8]] | 136 texture1: Image[RGBA] |
130 | 137 |
131 QuadShader = object | 138 QuadShader = object |
132 position {.VertexAttribute.}: Vec3f | 139 position {.VertexAttribute.}: Vec3f |
133 fragmentColor {.Pass.}: Vec3f | 140 fragmentColor {.Pass.}: Vec3f |
134 uv {.Pass.}: Vec2f | 141 uv {.Pass.}: Vec2f |
145 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" | 152 outColor = vec4(fragmentColor, 1) * texture(texture1, uv);}""" |
146 QuadMesh = object | 153 QuadMesh = object |
147 position: GPUArray[Vec3f, VertexBuffer] | 154 position: GPUArray[Vec3f, VertexBuffer] |
148 indices: GPUArray[uint16, IndexBuffer] | 155 indices: GPUArray[uint16, IndexBuffer] |
149 | 156 |
150 let R = TVec4[uint8]([255'u8, 0'u8, 0'u8, 255'u8]) | 157 let R = RGBA([255'u8, 0'u8, 0'u8, 255'u8]) |
151 let G = TVec4[uint8]([0'u8, 255'u8, 0'u8, 255'u8]) | 158 let G = RGBA([0'u8, 255'u8, 0'u8, 255'u8]) |
152 let B = TVec4[uint8]([0'u8, 0'u8, 255'u8, 255'u8]) | 159 let B = RGBA([0'u8, 0'u8, 255'u8, 255'u8]) |
153 let W = TVec4[uint8]([255'u8, 255'u8, 255'u8, 255'u8]) | 160 let W = RGBA([255'u8, 255'u8, 255'u8, 255'u8]) |
154 var | 161 var |
155 quad = QuadMesh( | 162 quad = QuadMesh( |
156 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | 163 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), |
157 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | 164 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
158 ) | 165 ) |
159 uniforms1 = asDescriptorSet( | 166 uniforms1 = asDescriptorSet( |
160 Uniforms( | 167 Uniforms( |
161 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), | 168 material: asGPUValue(Material(baseColor: NewVec3f(1, 1, 1)), UniformBuffer), |
162 texture1: Image[TVec4[uint8]](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST), | 169 texture1: Image[RGBA](width: 3, height: 3, data: @[R, G, B, G, B, R, B, R, G], interpolation: VK_FILTER_NEAREST), |
163 ) | 170 ) |
164 ) | 171 ) |
165 uniforms2 = asDescriptorSet( | 172 uniforms2 = asDescriptorSet( |
166 Uniforms( | 173 Uniforms( |
167 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), | 174 material: asGPUValue(Material(baseColor: NewVec3f(0.5, 0.5, 0.5)), UniformBuffer), |
168 texture1: Image[TVec4[uint8]](width: 2, height: 2, data: @[R, G, B, W]), | 175 texture1: Image[RGBA](width: 2, height: 2, data: @[R, G, B, W]), |
169 ) | 176 ) |
170 ) | 177 ) |
171 | 178 |
172 AssignBuffers(renderdata, quad) | 179 AssignBuffers(renderdata, quad) |
173 AssignBuffers(renderdata, uniforms1) | 180 AssignBuffers(renderdata, uniforms1) |
181 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | 188 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) |
182 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) | 189 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms2) |
183 | 190 |
184 var start = getMonoTime() | 191 var start = getMonoTime() |
185 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 192 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
193 | |
186 WithNextFrame(framebuffer, commandbuffer): | 194 WithNextFrame(framebuffer, commandbuffer): |
195 | |
187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 196 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
197 | |
188 WithPipeline(commandbuffer, pipeline): | 198 WithPipeline(commandbuffer, pipeline): |
199 | |
189 WithBind(commandbuffer, (uniforms1, ), pipeline): | 200 WithBind(commandbuffer, (uniforms1, ), pipeline): |
190 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 201 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
202 | |
191 WithBind(commandbuffer, (uniforms2, ), pipeline): | 203 WithBind(commandbuffer, (uniforms2, ), pipeline): |
192 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 204 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) |
193 | 205 |
194 # cleanup | 206 # cleanup |
195 checkVkResult vkDeviceWaitIdle(vulkan.device) | 207 checkVkResult vkDeviceWaitIdle(vulkan.device) |
213 ConstSet = object | 225 ConstSet = object |
214 constants: GPUValue[Constants, UniformBuffer] | 226 constants: GPUValue[Constants, UniformBuffer] |
215 MainSet = object | 227 MainSet = object |
216 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] | 228 renderSettings: GPUValue[RenderSettings, UniformBufferMapped] |
217 material: array[2, GPUValue[Material, UniformBuffer]] | 229 material: array[2, GPUValue[Material, UniformBuffer]] |
218 texture1: array[2, Image[TVec1[uint8]]] | 230 texture1: array[2, Image[Gray]] |
219 OtherSet = object | 231 OtherSet = object |
220 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] | 232 objectSettings: GPUValue[ObjectSettings, UniformBufferMapped] |
221 | 233 |
222 QuadShader = object | 234 QuadShader = object |
223 position {.VertexAttribute.}: Vec3f | 235 position {.VertexAttribute.}: Vec3f |
247 var constset = asDescriptorSet( | 259 var constset = asDescriptorSet( |
248 ConstSet( | 260 ConstSet( |
249 constants: asGPUValue(Constants(offset: NewVec2f(-0.3, 0.2)), UniformBuffer), | 261 constants: asGPUValue(Constants(offset: NewVec2f(-0.3, 0.2)), UniformBuffer), |
250 ) | 262 ) |
251 ) | 263 ) |
252 let G = TVec1[uint8]([50'u8]) | 264 let G = Gray([50'u8]) |
253 let W = TVec1[uint8]([255'u8]) | 265 let W = Gray([255'u8]) |
254 var mainset = asDescriptorSet( | 266 var mainset = asDescriptorSet( |
255 MainSet( | 267 MainSet( |
256 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), | 268 renderSettings: asGPUValue(RenderSettings(brigthness: 0), UniformBufferMapped), |
257 material: [ | 269 material: [ |
258 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), | 270 asGPUValue(Material(baseColor: NewVec3f(1, 1, 0)), UniformBuffer), |
259 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), | 271 asGPUValue(Material(baseColor: NewVec3f(1, 0, 1)), UniformBuffer), |
260 ], | 272 ], |
261 texture1: [ | 273 texture1: [ |
262 Image[TVec1[uint8]](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST), | 274 Image[Gray](width: 2, height: 2, data: @[W, G, G, W], interpolation: VK_FILTER_NEAREST), |
263 Image[TVec1[uint8]](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST), | 275 Image[Gray](width: 3, height: 3, data: @[W, G, W, G, W, G, W, G, W], interpolation: VK_FILTER_NEAREST), |
264 ], | 276 ], |
265 ), | 277 ), |
266 ) | 278 ) |
267 var otherset1 = asDescriptorSet( | 279 var otherset1 = asDescriptorSet( |
268 OtherSet( | 280 OtherSet( |
290 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) | 302 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset1) |
291 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset2) | 303 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[2], otherset2) |
292 | 304 |
293 var start = getMonoTime() | 305 var start = getMonoTime() |
294 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 306 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
295 TimeAndLog: | 307 |
296 WithNextFrame(framebuffer, commandbuffer): | 308 WithNextFrame(framebuffer, commandbuffer): |
297 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 309 |
298 WithPipeline(commandbuffer, pipeline): | 310 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
299 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline): | 311 |
300 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 312 WithPipeline(commandbuffer, pipeline): |
301 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline): | 313 |
302 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | 314 WithBind(commandbuffer, (constset, mainset, otherset1), pipeline): |
315 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
316 | |
317 WithBind(commandbuffer, (constset, mainset, otherset2), pipeline): | |
318 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = quad) | |
319 | |
303 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time | 320 mainset.data.renderSettings.data.brigthness = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
304 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time | 321 otherset1.data.objectSettings.data.scale = 0.5 + ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
305 UpdateGPUBuffer(mainset.data.renderSettings) | 322 UpdateGPUBuffer(mainset.data.renderSettings) |
306 UpdateGPUBuffer(otherset1.data.objectSettings) | 323 UpdateGPUBuffer(otherset1.data.objectSettings) |
307 renderdata.FlushAllMemory() | 324 renderdata.FlushAllMemory() |
420 Translate(0, 0, 2) * | 437 Translate(0, 0, 2) * |
421 Rotate(PI / 4, X) * | 438 Rotate(PI / 4, X) * |
422 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) | 439 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y) |
423 ) | 440 ) |
424 UpdateGPUBuffer(uniforms1.data.data, flush = true) | 441 UpdateGPUBuffer(uniforms1.data.data, flush = true) |
442 | |
425 WithNextFrame(framebuffer, commandbuffer): | 443 WithNextFrame(framebuffer, commandbuffer): |
444 | |
426 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 445 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
427 WithPipeline(commandbuffer, pipeline): | 446 WithPipeline(commandbuffer, pipeline): |
447 | |
428 WithBind(commandbuffer, (uniforms1, ), pipeline): | 448 WithBind(commandbuffer, (uniforms1, ), pipeline): |
429 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | 449 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) |
430 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) | 450 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) |
431 | 451 |
432 let tEndLoop = getMonoTime() - tStart | 452 let tEndLoop = getMonoTime() - tStart |
495 DestroyPipeline(pipeline2) | 515 DestroyPipeline(pipeline2) |
496 DestroyPipeline(pipeline3) | 516 DestroyPipeline(pipeline3) |
497 DestroyPipeline(pipeline4) | 517 DestroyPipeline(pipeline4) |
498 DestroyRenderData(renderdata) | 518 DestroyRenderData(renderdata) |
499 | 519 |
500 proc test_07_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = | 520 proc test_07_png_texture(time: float32) = |
501 var (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | |
502 | |
503 SetupSwapchain(renderpass = presentRP) | |
504 | |
505 var renderdata = InitRenderData() | 521 var renderdata = InitRenderData() |
506 | 522 |
507 type | 523 type |
508 Uniforms = object | 524 Uniforms = object |
509 frameTexture: Image[TVec4[uint8]] | 525 texture1: Image[RGBA] |
526 Shader = object | |
527 position {.VertexAttribute.}: Vec3f | |
528 uv {.VertexAttribute.}: Vec2f | |
529 fragmentUv {.Pass.}: Vec2f | |
530 outColor {.ShaderOutput.}: Vec4f | |
531 descriptorSets {.DescriptorSets.}: (Uniforms, ) | |
532 # code | |
533 vertexCode: string = """ | |
534 void main() { | |
535 fragmentUv = uv; | |
536 gl_Position = vec4(position, 1); | |
537 }""" | |
538 fragmentCode: string = """ | |
539 void main() { | |
540 outColor = texture(texture1, fragmentUv); | |
541 }""" | |
542 Quad = object | |
543 position: GPUArray[Vec3f, VertexBuffer] | |
544 uv: GPUArray[Vec2f, VertexBuffer] | |
545 var mesh = Quad( | |
546 position: asGPUArray([ | |
547 NewVec3f(-0.8, -0.5), NewVec3f(-0.8, 0.5), NewVec3f(0.8, 0.5), | |
548 NewVec3f(0.8, 0.5), NewVec3f(0.8, -0.5), NewVec3f(-0.8, -0.5), | |
549 ], VertexBuffer), | |
550 uv: asGPUArray([ | |
551 NewVec2f(0, 1), NewVec2f(0, 0), NewVec2f(1, 0), | |
552 NewVec2f(1, 0), NewVec2f(1, 1), NewVec2f(0, 1), | |
553 ], VertexBuffer), | |
554 ) | |
555 AssignBuffers(renderdata, mesh) | |
556 renderdata.FlushAllMemory() | |
557 | |
558 var pipeline = CreatePipeline[Shader](renderPass = vulkan.swapchain.renderPass) | |
559 var uniforms1 = asDescriptorSet( | |
560 Uniforms( | |
561 texture1: LoadImage[RGBA]("art.png"), | |
562 ) | |
563 ) | |
564 UploadImages(renderdata, uniforms1) | |
565 InitDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], uniforms1) | |
566 | |
567 var start = getMonoTime() | |
568 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
569 | |
570 WithNextFrame(framebuffer, commandbuffer): | |
571 | |
572 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | |
573 | |
574 WithPipeline(commandbuffer, pipeline): | |
575 | |
576 WithBind(commandbuffer, (uniforms1, ), pipeline): | |
577 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) | |
578 | |
579 # cleanup | |
580 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
581 DestroyPipeline(pipeline) | |
582 DestroyRenderData(renderdata) | |
583 | |
584 proc test_08_triangle_2pass(time: float32, depthBuffer: bool, samples: VkSampleCountFlagBits) = | |
585 var (offscreenRP, presentRP) = CreateIndirectPresentationRenderPass(depthBuffer = depthBuffer, samples = samples) | |
586 | |
587 SetupSwapchain(renderpass = presentRP) | |
588 | |
589 var renderdata = InitRenderData() | |
590 | |
591 type | |
592 Uniforms = object | |
593 frameTexture: Image[RGBA] | |
510 TriangleShader = object | 594 TriangleShader = object |
511 position {.VertexAttribute.}: Vec3f | 595 position {.VertexAttribute.}: Vec3f |
512 color {.VertexAttribute.}: Vec3f | 596 color {.VertexAttribute.}: Vec3f |
513 fragmentColor {.Pass.}: Vec3f | 597 fragmentColor {.Pass.}: Vec3f |
514 outColor {.ShaderOutput.}: Vec4f | 598 outColor {.ShaderOutput.}: Vec4f |
553 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), | 637 position: asGPUArray([NewVec2f(-1, -1), NewVec2f(-1, 1), NewVec2f(1, 1), NewVec2f(1, -1)], VertexBuffer), |
554 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), | 638 indices: asGPUArray([0'u16, 1'u16, 2'u16, 2'u16, 3'u16, 0'u16], IndexBuffer), |
555 ) | 639 ) |
556 var uniforms1 = asDescriptorSet( | 640 var uniforms1 = asDescriptorSet( |
557 Uniforms( | 641 Uniforms( |
558 frameTexture: Image[TVec4[uint8]](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), | 642 frameTexture: Image[RGBA](width: vulkan.swapchain.width, height: vulkan.swapchain.height, isRenderTarget: true), |
559 ) | 643 ) |
560 ) | 644 ) |
561 AssignBuffers(renderdata, mesh) | 645 AssignBuffers(renderdata, mesh) |
562 AssignBuffers(renderdata, quad) | 646 AssignBuffers(renderdata, quad) |
563 UploadImages(renderdata, uniforms1) | 647 UploadImages(renderdata, uniforms1) |
644 ) | 728 ) |
645 | 729 |
646 var start = getMonoTime() | 730 var start = getMonoTime() |
647 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 731 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
648 | 732 |
649 TimeAndLog: | 733 WithNextFrame(framebuffer, commandbuffer): |
650 WithNextFrame(framebuffer, commandbuffer): | 734 |
651 | 735 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
652 WithRenderPass(offscreenRP, offscreenFB, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 736 WithPipeline(commandbuffer, drawPipeline): |
653 WithPipeline(commandbuffer, drawPipeline): | 737 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) |
654 Render(commandbuffer = commandbuffer, pipeline = drawPipeline, mesh = mesh) | 738 |
655 | 739 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
656 WithRenderPass(presentRP, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): | 740 |
657 WithPipeline(commandbuffer, presentPipeline): | 741 WithPipeline(commandbuffer, presentPipeline): |
658 WithBind(commandbuffer, (uniforms1, ), presentPipeline): | 742 |
659 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) | 743 WithBind(commandbuffer, (uniforms1, ), presentPipeline): |
744 Render(commandbuffer = commandbuffer, pipeline = presentPipeline, mesh = quad) | |
660 | 745 |
661 # cleanup | 746 # cleanup |
662 checkVkResult vkDeviceWaitIdle(vulkan.device) | 747 checkVkResult vkDeviceWaitIdle(vulkan.device) |
663 DestroyPipeline(presentPipeline) | 748 DestroyPipeline(presentPipeline) |
664 DestroyPipeline(drawPipeline) | 749 DestroyPipeline(drawPipeline) |
710 test_05_cube(time) | 795 test_05_cube(time) |
711 | 796 |
712 # different draw modes (lines, points, and topologies) | 797 # different draw modes (lines, points, and topologies) |
713 test_06_different_draw_modes(time) | 798 test_06_different_draw_modes(time) |
714 | 799 |
800 # load PNG texture | |
801 test_07_png_texture(time) | |
802 | |
715 checkVkResult vkDeviceWaitIdle(vulkan.device) | 803 checkVkResult vkDeviceWaitIdle(vulkan.device) |
716 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | 804 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
717 ClearSwapchain() | 805 ClearSwapchain() |
718 | 806 |
719 # test multiple render passes | 807 # test multiple render passes |
720 for i, (depthBuffer, samples) in renderPasses: | 808 for i, (depthBuffer, samples) in renderPasses: |
721 test_07_triangle_2pass(time, depthBuffer, samples) | 809 test_08_triangle_2pass(time, depthBuffer, samples) |
722 | 810 |
723 DestroyVulkan() | 811 DestroyVulkan() |