Mercurial > games > semicongine
annotate tests/test_text.nim @ 1329:ad09d41abd1e
add: 2d-scaling for text
author | sam <sam@basx.dev> |
---|---|
date | Sat, 17 Aug 2024 16:09:15 +0700 |
parents | 373a4888f6ac |
children | df3c075e5dea |
rev | line source |
---|---|
1236 | 1 import std/os |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
2 import std/algorithm |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
3 import std/strutils |
1236 | 4 import std/sequtils |
5 import std/monotimes | |
6 import std/times | |
7 import std/options | |
8 import std/random | |
9 | |
1267 | 10 import ../semicongine |
1236 | 11 |
1327 | 12 type |
13 FontDS = object | |
14 fontAtlas: Image[Gray] | |
15 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
16 proc test_01_static_label(time: float32) = |
1327 | 17 var font = loadFont("Overhaul.ttf", lineHeightPixels = 160) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
18 var renderdata = initRenderData() |
1327 | 19 var pipeline = createPipeline[DefaultFontShader[FontDS]](renderPass = vulkan.swapchain.renderPass) |
1236 | 20 |
1327 | 21 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas)) |
22 uploadImages(renderdata, ds) | |
23 initDescriptorSet( | |
24 renderdata, | |
25 pipeline.layout(0), | |
26 ds, | |
27 ) | |
1236 | 28 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
29 var label1 = initTextbox( |
1236 | 30 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
31 pipeline.layout(0), |
1236 | 32 font, |
1327 | 33 0.0005, |
1236 | 34 "Hello semicongine!", |
35 ) | |
36 | |
37 var start = getMonoTime() | |
38 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
39 label1.refresh() |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
40 withNextFrame(framebuffer, commandbuffer): |
1327 | 41 bindDescriptorSet(commandbuffer, ds, 0, pipeline) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
42 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
43 withPipeline(commandbuffer, pipeline): |
1327 | 44 render(commandbuffer, pipeline, label1, vec3(), vec4(1, 1, 1, 1)) |
1236 | 45 |
46 # cleanup | |
47 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
48 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
49 destroyRenderData(renderdata) |
1236 | 50 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
51 proc test_02_multiple_animated(time: float32) = |
1282
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
52 var font1 = loadFont("Overhaul.ttf", lineHeightPixels = 40) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
53 var font2 = loadFont("Overhaul.ttf", lineHeightPixels = 160) |
3308b88e53a6
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1281
diff
changeset
|
54 var font3 = loadFont("DejaVuSans.ttf", lineHeightPixels = 160) |
1327 | 55 var renderdata = initRenderData() |
56 | |
57 var pipeline = createPipeline[DefaultFontShader[FontDS]](renderPass = vulkan.swapchain.renderPass) | |
58 | |
59 var ds1 = asDescriptorSetData(FontDS(fontAtlas: font1.fontAtlas)) | |
60 uploadImages(renderdata, ds1) | |
61 initDescriptorSet(renderdata, pipeline.layout(0), ds1) | |
62 | |
63 var ds2 = asDescriptorSetData(FontDS(fontAtlas: font2.fontAtlas)) | |
64 uploadImages(renderdata, ds2) | |
65 initDescriptorSet(renderdata, pipeline.layout(0), ds2) | |
66 | |
67 var ds3 = asDescriptorSetData(FontDS(fontAtlas: font3.fontAtlas)) | |
68 uploadImages(renderdata, ds3) | |
69 initDescriptorSet(renderdata, pipeline.layout(0), ds3) | |
70 | |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
71 var labels = [ |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
72 initTextbox( |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
73 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
74 pipeline.layout(0), |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
75 font1, |
1327 | 76 0.004, |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
77 " 0", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
78 ), |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
79 initTextbox( |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
80 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
81 pipeline.layout(0), |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
82 font2, |
1327 | 83 0.001, |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
84 " 1", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
85 ), |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
86 initTextbox( |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
87 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
88 pipeline.layout(0), |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
89 font3, |
1327 | 90 0.001, |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
91 " 2", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
92 ) |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
93 ] |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
94 |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
95 var start = getMonoTime() |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
96 var p = 0 |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
97 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
98 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
99 for i in 0 ..< labels.len: |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
100 labels[i].text = $(p + i) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
101 labels[i].refresh() |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
102 inc p |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
103 withNextFrame(framebuffer, commandbuffer): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
104 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
105 withPipeline(commandbuffer, pipeline): |
1327 | 106 bindDescriptorSet(commandbuffer, ds1, 0, pipeline) |
107 render( | |
108 commandbuffer, | |
109 pipeline, | |
110 labels[0], | |
111 position=vec3(0 / labels.len, 0.1 + progress * 0.5), | |
112 color=vec4(1, 1, 1, 1), | |
113 ) | |
114 bindDescriptorSet(commandbuffer, ds2, 0, pipeline) | |
115 render( | |
116 commandbuffer, | |
117 pipeline, | |
118 labels[1], | |
119 position=vec3(1 / labels.len, 0.1 + progress * 0.5), | |
120 color=vec4(1, 1, 1, 1), | |
121 ) | |
122 bindDescriptorSet(commandbuffer, ds3, 0, pipeline) | |
123 render( | |
124 commandbuffer, | |
125 pipeline, | |
126 labels[2], | |
127 position=vec3(2 / labels.len, 0.1 + progress * 0.5), | |
128 color=vec4(1, 1, 1, 1), | |
129 ) | |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
130 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
131 # cleanup |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
132 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
133 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
134 destroyRenderData(renderdata) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
135 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
136 proc test_03_layouting(time: float32) = |
1327 | 137 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 40) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
138 var renderdata = initRenderData() |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
139 |
1327 | 140 var pipeline = createPipeline[DefaultFontShader[FontDS]](renderPass = vulkan.swapchain.renderPass) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
141 |
1327 | 142 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas)) |
143 uploadImages(renderdata, ds) | |
144 initDescriptorSet( | |
145 renderdata, | |
146 pipeline.layout(0), | |
147 ds, | |
148 ) | |
149 | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
150 var labels: seq[Textbox] |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
151 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
152 for horizontal in HorizontalAlignment: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
153 labels.add initTextbox( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
154 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
155 pipeline.layout(0), |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
156 font, |
1327 | 157 0.001, |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
158 $horizontal & " aligned", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
159 horizontalAlignment = horizontal, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
160 ) |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
161 for vertical in VerticalAlignment: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
162 labels.add initTextbox( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
163 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
164 pipeline.layout(0), |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
165 font, |
1327 | 166 0.001, |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
167 $vertical & " aligned", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
168 verticalAlignment = vertical, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
169 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
170 labels.add initTextbox( |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
171 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
172 pipeline.layout(0), |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
173 font, |
1327 | 174 0.001, |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
175 """Paragraph |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
176 This is a somewhat longer paragraph with a few newlines and a maximum width of 0.2. |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
177 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
178 It should display with some space above and have a pleasing appearance overall! :)""", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
179 maxWidth = 0.6, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
180 verticalAlignment = Top, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
181 horizontalAlignment = Left, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
182 ) |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
183 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
184 var start = getMonoTime() |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
185 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
186 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
187 withNextFrame(framebuffer, commandbuffer): |
1327 | 188 bindDescriptorSet(commandbuffer, ds, 0, pipeline) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
189 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
190 withPipeline(commandbuffer, pipeline): |
1327 | 191 for i in 0 ..< labels.len: |
192 render(commandbuffer, pipeline, labels[i], vec3(0.5 - i.float32 * 0.1, 0.5 - i.float32 * 0.1), vec4(1, 1, 1, 1)) | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
193 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
194 # cleanup |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
195 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
196 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
197 destroyRenderData(renderdata) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
198 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
199 proc test_04_lots_of_texts(time: float32) = |
1327 | 200 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 160) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
201 var renderdata = initRenderData() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
202 |
1327 | 203 var pipeline = createPipeline[DefaultFontShader[FontDS]](renderPass = vulkan.swapchain.renderPass) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
204 |
1327 | 205 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas)) |
206 uploadImages(renderdata, ds) | |
207 initDescriptorSet( | |
208 renderdata, | |
209 pipeline.layout(0), | |
210 ds, | |
211 ) | |
212 | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
213 var labels: seq[Textbox] |
1327 | 214 var positions = newSeq[Vec3f](100) |
215 var colors = newSeq[Vec4f](100) | |
1329 | 216 var scales = newSeq[Vec2f](100) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
217 for i in 0 ..< 100: |
1327 | 218 positions[i] = vec3(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1)) |
219 colors[i] = vec4(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)) | |
1329 | 220 scales[i] = vec2(rand(0.5'f32 .. 1.5'f32), rand(0.5'f32 .. 1.5'f32)) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
221 labels.add initTextbox( |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
222 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
223 pipeline.layout(0), |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
224 font, |
1327 | 225 0.001, |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
226 $i, |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
227 ) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
228 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
229 var start = getMonoTime() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
230 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
231 for l in labels.mitems: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
232 l.refresh() |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
233 withNextFrame(framebuffer, commandbuffer): |
1327 | 234 bindDescriptorSet(commandbuffer, ds, 0, pipeline) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
235 withRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)): |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
236 withPipeline(commandbuffer, pipeline): |
1327 | 237 for i in 0 ..< labels.len: |
238 render(commandbuffer, pipeline, labels[i], positions[i], colors[i], scales[i]) | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
239 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
240 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
241 checkVkResult vkDeviceWaitIdle(vulkan.device) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
242 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
243 destroyRenderData(renderdata) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
244 |
1236 | 245 when isMainModule: |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
246 var time = 1'f32 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
247 initVulkan() |
1236 | 248 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
249 for depthBuffer in [true, false]: |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
250 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
251 setupSwapchain(renderpass = renderpass) |
1236 | 252 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
253 # tests a simple triangle with minimalistic shader and vertex format |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
254 test_01_static_label(time) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
255 test_02_multiple_animated(time) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
256 test_03_layouting(time) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
257 test_04_lots_of_texts(time) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
258 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
259 checkVkResult vkDeviceWaitIdle(vulkan.device) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
260 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
261 clearSwapchain() |
1236 | 262 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
263 destroyVulkan() |