annotate tests/test_vulkan_wrapper.nim @ 584:9e7bcc8e0e52

did: refactor mesh code, prepare for instance-data
author Sam <sam@basx.dev>
date Mon, 10 Apr 2023 00:53:16 +0700
parents 90537a8887ae
children cb9e27a30165
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
1 import std/options
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
2
578
13febe7978e5 did: small changes from refactoring
Sam <sam@basx.dev>
parents: 576
diff changeset
3 import semicongine
560
8de8a2102071 add: vertex and (initial) shader types and methods
Sam <sam@basx.dev>
parents: 559
diff changeset
4
565
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
5 proc diagnostics(instance: Instance) =
555
7c44f714bd03 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 554
diff changeset
6 # diagnostic output
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
7 # print basic driver infos
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
8 echo "Layers"
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
9 for layer in getLayers():
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
10 echo " " & layer
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
11 echo "Instance extensions"
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
12 for extension in getInstanceExtensions():
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
13 echo " " & extension
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
14
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
15 echo "Devices"
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
16 for device in instance.getPhysicalDevices():
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
17 echo " " & $device
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
18 echo " Rating: " & $device.rateGraphics()
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
19 echo " Extensions"
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
20 for extension in device.getExtensions():
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
21 echo " " & $extension
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
22 echo " Properties"
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
23 echo " " & $device.getProperties()
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
24 echo " Features"
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
25 echo " " & $device.getFeatures()
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
26 echo " Queue families"
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
27 for queueFamily in device.getQueueFamilies():
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
28 echo " " & $queueFamily
555
7c44f714bd03 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 554
diff changeset
29 echo " Surface present modes"
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
30 for mode in device.getSurfacePresentModes():
555
7c44f714bd03 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 554
diff changeset
31 echo " " & $mode
7c44f714bd03 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 554
diff changeset
32 echo " Surface formats"
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
33 for format in device.getSurfaceFormats():
555
7c44f714bd03 add: device, surface and refactoring
Sam <sam@basx.dev>
parents: 554
diff changeset
34 echo " " & $format
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
35
565
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
36 when isMainModule:
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
37 # INIT ENGINE:
565
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
38 # create instance
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
39 var thewindow = createWindow("Test")
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
40 var instance = thewindow.createInstance(
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
41 vulkanVersion=VK_MAKE_API_VERSION(0, 1, 3, 0),
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
42 instanceExtensions= @["VK_EXT_debug_utils"],
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
43 layers= @["VK_LAYER_KHRONOS_validation", "VK_LAYER_MESA_overlay"]
565
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
44 )
a0b01e84607d did: some refactoring
Sam <sam@basx.dev>
parents: 564
diff changeset
45 var debugger = instance.createDebugMessenger()
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
46 # create devices
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
47 let selectedPhysicalDevice = instance.getPhysicalDevices().filterBestGraphics()
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
48 var device = instance.createDevice(
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
49 selectedPhysicalDevice,
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
50 @[],
581
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
51 @["VK_EXT_index_type_uint8"],
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
52 selectedPhysicalDevice.filterForGraphicsPresentationQueues()
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
53 )
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
54
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
55 # INIT RENDERER:
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
56 const
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
57 vertexInput = @[
582
8cf5d3f921ae did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents: 581
diff changeset
58 attr[Vec3f]("position"),
8cf5d3f921ae did: refactor GPU data types, more generic, prepare to use for decriptors/uniforms
Sam <sam@basx.dev>
parents: 581
diff changeset
59 attr[Vec3f]("color"),
584
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
60 attr[Vec3f]("translate", perInstance=true)
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
61 ]
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
62 vertexOutput = @[attr[Vec3f]("outcolor")]
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
63 uniforms = @[attr[float32]("time")]
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
64 fragOutput = @[attr[Vec4f]("color")]
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
65 vertexCode = compileGlslShader(
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
66 stage=VK_SHADER_STAGE_VERTEX_BIT,
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
67 inputs=vertexInput,
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
68 uniforms=uniforms,
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
69 outputs=vertexOutput,
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
70 body="""gl_Position = vec4(position, 1.0); outcolor = color * sin(Uniforms.time) * 0.5 + 0.5;"""
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
71 )
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
72 fragmentCode = compileGlslShader(
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
73 stage=VK_SHADER_STAGE_FRAGMENT_BIT,
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
74 inputs=vertexOutput,
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
75 uniforms=uniforms,
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
76 outputs=fragOutput,
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
77 body="color = vec4(outcolor, 1);"
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
78 )
567
05ac2455ff60 add: render main loop structure
Sam <sam@basx.dev>
parents: 566
diff changeset
79 var
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
80 vertexshader = device.createShaderModule(vertexCode)
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
81 fragmentshader = device.createShaderModule(fragmentCode)
569
f4d8f0018670 did: reorganize code
Sam <sam@basx.dev>
parents: 568
diff changeset
82 surfaceFormat = device.physicalDevice.getSurfaceFormats().filterSurfaceFormat()
572
9f1de117aaca did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents: 570
diff changeset
83 renderPass = device.simpleForwardRenderPass(surfaceFormat.format, vertexshader, fragmentshader, 2)
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
84 (swapchain, res) = device.createSwapchain(renderPass, surfaceFormat, device.firstGraphicsQueue().get().family, 2)
569
f4d8f0018670 did: reorganize code
Sam <sam@basx.dev>
parents: 568
diff changeset
85 if res != VK_SUCCESS:
f4d8f0018670 did: reorganize code
Sam <sam@basx.dev>
parents: 568
diff changeset
86 raise newException(Exception, "Unable to create swapchain")
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
87
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
88 # INIT SCENE
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
89 var time = initShaderGlobal("time", 0.0'f32)
584
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
90 #[
574
bbeec60e25ca did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents: 573
diff changeset
91 var thescene = Scene(
bbeec60e25ca did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents: 573
diff changeset
92 name: "main",
bbeec60e25ca did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents: 573
diff changeset
93 root: newEntity("root",
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
94 newEntity("stuff", time),
578
13febe7978e5 did: small changes from refactoring
Sam <sam@basx.dev>
parents: 576
diff changeset
95 newEntity("triangle1", newMesh(
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
96 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)],
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
97 colors=[newVec3f(1.0, 0.0, 0.0), newVec3f(0.0, 1.0, 0.0), newVec3f(0.0, 0.0, 1.0)],
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
98 )),
581
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
99 newEntity("triangle1b", newMesh(
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
100 positions=[newVec3f(0.0, -0.4), newVec3f(0.4, 0.4), newVec3f(-0.4, 0.5)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
101 colors=[newVec3f(1.0, 0.0, 0.0), newVec3f(0.0, 1.0, 0.0), newVec3f(0.0, 0.0, 1.0)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
102 )),
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
103 newEntity("triangle2a", newMesh(
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
104 positions=[newVec3f(0.0, 0.5), newVec3f(0.5, -0.5), newVec3f(-0.5, -0.5)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
105 colors=[newVec3f(1.0, 0.0, 0.0), newVec3f(0.0, 1.0, 0.0), newVec3f(0.0, 0.0, 1.0)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
106 indices=[[0'u16, 2'u16, 1'u16]]
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
107 )),
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
108 newEntity("triangle2b", newMesh(
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
109 positions=[newVec3f(0.0, 0.4), newVec3f(0.4, -0.4), newVec3f(-0.4, -0.4)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
110 colors=[newVec3f(1.0, 0.0, 0.0), newVec3f(0.0, 1.0, 0.0), newVec3f(0.0, 0.0, 1.0)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
111 indices=[[0'u16, 2'u16, 1'u16]]
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
112 )),
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
113 newEntity("triangle3a", newMesh(
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
114 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
115 colors=[newVec3f(1.0, 1.0, 0.0), newVec3f(1.0, 1.0, 0.0), newVec3f(1.0, 1.0, 0.0)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
116 indices=[[0'u32, 2'u32, 1'u32]],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
117 autoResize=false
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
118 )),
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
119 newEntity("triangle3b", newMesh(
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
120 positions=[newVec3f(0.4, 0.5), newVec3f(0.9, -0.3), newVec3f(0.0, -0.3)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
121 colors=[newVec3f(1.0, 1.0, 0.0), newVec3f(1.0, 1.0, 0.0), newVec3f(1.0, 1.0, 0.0)],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
122 indices=[[0'u32, 2'u32, 1'u32]],
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
123 autoResize=false
87e500bd528a add: better mesh support, indexed mesh
Sam <sam@basx.dev>
parents: 578
diff changeset
124 )),
574
bbeec60e25ca did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents: 573
diff changeset
125 )
bbeec60e25ca did: first final implementation of scene-graph <-> pipeline connection, not working yet
Sam <sam@basx.dev>
parents: 573
diff changeset
126 )
584
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
127 ]#
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
128 var mymesh = newMesh(
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
129 positions=[newVec3f(0.0, -0.5), newVec3f(0.5, 0.5), newVec3f(-0.5, 0.5)],
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
130 colors=[newVec3f(1.0, 0.0, 0.0), newVec3f(0.0, 1.0, 0.0), newVec3f(0.0, 0.0, 1.0)],
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
131 )
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
132 setInstanceData[Vec3f](mymesh, "translate", @[newVec3f(0.3, 0.3)])
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
133 var thescene = Scene(
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
134 name: "main",
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
135 root: newEntity("root",
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
136 newEntity("stuff", time),
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
137 newEntity("triangle", mymesh),
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
138 )
9e7bcc8e0e52 did: refactor mesh code, prepare for instance-data
Sam <sam@basx.dev>
parents: 583
diff changeset
139 )
572
9f1de117aaca did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents: 570
diff changeset
140 thescene.setupDrawables(renderPass)
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
141 swapchain.setupUniforms(thescene)
570
1cf928eb0a10 did: refactor rendering/scene concept
Sam <sam@basx.dev>
parents: 569
diff changeset
142
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
143 # MAINLOOP
572
9f1de117aaca did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents: 570
diff changeset
144 echo "Setup successfull, start rendering"
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
145 for i in 0 ..< 1:
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
146 setValue[float32](time.value, get[float32](time.value) + 0.0005)
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
147 echo get[float32](time.value)
572
9f1de117aaca did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents: 570
diff changeset
148 discard swapchain.drawScene(thescene)
569
f4d8f0018670 did: reorganize code
Sam <sam@basx.dev>
parents: 568
diff changeset
149 echo "Rendered ", swapchain.framesRendered, " frames"
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
150 checkVkResult device.vk.vkDeviceWaitIdle()
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
151
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
152 # cleanup
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
153 echo "Start cleanup"
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
154
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
155 # destroy scene
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
156 thescene.destroy()
569
f4d8f0018670 did: reorganize code
Sam <sam@basx.dev>
parents: 568
diff changeset
157
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
158 # destroy renderer
564
20837928dc63 add: finally working initial approach for shader definitions
Sam <sam@basx.dev>
parents: 563
diff changeset
159 vertexshader.destroy()
20837928dc63 add: finally working initial approach for shader definitions
Sam <sam@basx.dev>
parents: 563
diff changeset
160 fragmentshader.destroy()
572
9f1de117aaca did: allow runtime shader-input definitions
Sam <sam@basx.dev>
parents: 570
diff changeset
161 renderPass.destroy()
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
162 swapchain.destroy()
575
eaedc0369c38 yay: first triangle rendering with new engine implmentation
Sam <sam@basx.dev>
parents: 574
diff changeset
163
576
677e4f7fb567 add: comments for further refactoring
Sam <sam@basx.dev>
parents: 575
diff changeset
164 # destroy engine
557
e2d8c02f1548 add: swapchain API, more refactoring
Sam <sam@basx.dev>
parents: 555
diff changeset
165 device.destroy()
554
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
166 debugger.destroy()
f9a5ada2df1e add: testing for vulkan API wrapper
Sam <sam@basx.dev>
parents:
diff changeset
167 instance.destroy()
583
90537a8887ae did: implement uniforms, some refactoring
Sam <sam@basx.dev>
parents: 582
diff changeset
168 thewindow.destroy()