Mercurial > games > semicongine
annotate tests/test_text.nim @ 1404:80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
author | sam <sam@basx.dev> |
---|---|
date | Thu, 19 Dec 2024 23:32:45 +0700 |
parents | 02d302c868d5 |
children | 46bac138ad6c |
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 | |
1381
c8d1b87cf6c8
did: make progress on new glyph-rendering system
sam <sam@basx.dev>
parents:
1380
diff
changeset
|
7 import std/tables |
1236 | 8 import std/options |
9 import std/random | |
1381
c8d1b87cf6c8
did: make progress on new glyph-rendering system
sam <sam@basx.dev>
parents:
1380
diff
changeset
|
10 import std/unicode |
1236 | 11 |
1267 | 12 import ../semicongine |
1236 | 13 |
1332 | 14 type FontDS = object |
15 fontAtlas: Image[Gray] | |
1327 | 16 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
17 const MAX_CODEPOINTS = 200 |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
18 const FONTNAME = "Overhaul.ttf" |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
19 # const FONTNAME = "DejaVuSans.ttf" |
1379
9ca552dad5fc
did: continue working on new glyph-renderer
sam <sam@basx.dev>
parents:
1374
diff
changeset
|
20 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
21 proc test_01_static_label(time: float32) = |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
22 var font = loadFont[MAX_CODEPOINTS](FONTNAME, lineHeightPixels = 200) |
1374 | 23 var renderdata = initRenderData() |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
24 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
25 renderPass = vulkan.swapchain.renderPass |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
26 ) |
1401
4ecb004ee7f8
did: add horizontal advancment for glyph rendering
sam <sam@basx.dev>
parents:
1400
diff
changeset
|
27 var glyphs = font.initGlyphs(1000, baseScale = 0.1) |
1374 | 28 |
1379
9ca552dad5fc
did: continue working on new glyph-renderer
sam <sam@basx.dev>
parents:
1374
diff
changeset
|
29 assignBuffers(renderdata, glyphs) |
1399 | 30 assignBuffers(renderdata, font.descriptorSet) |
31 uploadImages(renderdata, font.descriptorSet) | |
32 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet) | |
33 | |
1374 | 34 var start = getMonoTime() |
35 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | |
1400
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
36 let t = getMonoTime() |
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
37 glyphs.reset() |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
38 glyphs.add("Hello semicongine!", vec3(0.5, 0.5), anchor = vec2(0.5, 0.5)) |
1400
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
39 glyphs.updateAllGPUBuffers(flush = true) |
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
40 |
1374 | 41 withNextFrame(framebuffer, commandbuffer): |
1399 | 42 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) |
1374 | 43 withRenderPass( |
44 vulkan.swapchain.renderPass, | |
45 framebuffer, | |
46 commandbuffer, | |
47 vulkan.swapchain.width, | |
48 vulkan.swapchain.height, | |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
49 vec4(0, 0, 0, 0), |
1374 | 50 ): |
51 withPipeline(commandbuffer, pipeline): | |
1399 | 52 renderGlyphs(commandbuffer, pipeline, glyphs) |
1374 | 53 |
1400
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
54 # cleanup |
1374 | 55 checkVkResult vkDeviceWaitIdle(vulkan.device) |
56 destroyPipeline(pipeline) | |
57 destroyRenderData(renderdata) | |
58 | |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
59 proc test_02_multi_counter(time: float32) = |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
60 var font1 = loadFont[MAX_CODEPOINTS]("Overhaul.ttf", lineHeightPixels = 40) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
61 var font2 = loadFont[MAX_CODEPOINTS]("Overhaul.ttf", lineHeightPixels = 160) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
62 var font3 = loadFont[MAX_CODEPOINTS]("DejaVuSans.ttf", lineHeightPixels = 160) |
1327 | 63 var renderdata = initRenderData() |
64 | |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
65 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
66 renderPass = vulkan.swapchain.renderPass |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
67 ) |
1327 | 68 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
69 assignBuffers(renderdata, font1.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
70 assignBuffers(renderdata, font2.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
71 assignBuffers(renderdata, font3.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
72 uploadImages(renderdata, font1.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
73 uploadImages(renderdata, font2.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
74 uploadImages(renderdata, font3.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
75 initDescriptorSet(renderdata, pipeline.layout(0), font1.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
76 initDescriptorSet(renderdata, pipeline.layout(0), font2.descriptorSet) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
77 initDescriptorSet(renderdata, pipeline.layout(0), font3.descriptorSet) |
1327 | 78 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
79 var glyphs1 = font1.initGlyphs(10, baseScale = 0.1) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
80 var glyphs2 = font2.initGlyphs(10, baseScale = 0.1) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
81 var glyphs3 = font3.initGlyphs(10, baseScale = 0.1) |
1327 | 82 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
83 assignBuffers(renderdata, glyphs1) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
84 assignBuffers(renderdata, glyphs2) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
85 assignBuffers(renderdata, glyphs3) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
86 |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
87 var labels = [" 0", " 1", " 2"] |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
88 |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
89 var start = getMonoTime() |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
90 var p = 0 |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
91 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
92 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
93 glyphs1.reset() |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
94 glyphs2.reset() |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
95 glyphs3.reset() |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
96 |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
97 glyphs1.add($(p + 0), vec3(0.3, 0.5)) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
98 glyphs2.add($(p + 1), vec3(0.5, 0.5)) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
99 glyphs3.add($(p + 2), vec3(0.7, 0.5)) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
100 |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
101 glyphs1.updateAllGPUBuffers(flush = true) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
102 glyphs2.updateAllGPUBuffers(flush = true) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
103 glyphs3.updateAllGPUBuffers(flush = true) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
104 |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
105 inc p |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
106 withNextFrame(framebuffer, commandbuffer): |
1332 | 107 withRenderPass( |
108 vulkan.swapchain.renderPass, | |
109 framebuffer, | |
110 commandbuffer, | |
111 vulkan.swapchain.width, | |
112 vulkan.swapchain.height, | |
113 vec4(0, 0, 0, 0), | |
114 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
115 withPipeline(commandbuffer, pipeline): |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
116 bindDescriptorSet(commandbuffer, font1.descriptorSet, 0, pipeline) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
117 renderGlyphs(commandbuffer, pipeline, glyphs1) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
118 bindDescriptorSet(commandbuffer, font2.descriptorSet, 0, pipeline) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
119 renderGlyphs(commandbuffer, pipeline, glyphs2) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
120 bindDescriptorSet(commandbuffer, font3.descriptorSet, 0, pipeline) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
121 renderGlyphs(commandbuffer, pipeline, glyphs3) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
122 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
123 # cleanup |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
124 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
|
125 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
126 destroyRenderData(renderdata) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
127 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
128 #[ |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
129 proc test_03_layouting(time: float32) = |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
130 var font = loadFont[MAX_CODEPOINTS]("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
|
131 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
|
132 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
133 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
134 renderPass = vulkan.swapchain.renderPass |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
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 |
1335 | 137 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas.copy())) |
1327 | 138 uploadImages(renderdata, ds) |
1332 | 139 initDescriptorSet(renderdata, pipeline.layout(0), ds) |
1327 | 140 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
141 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
|
142 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
143 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
|
144 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
|
145 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
146 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
|
147 font, |
1327 | 148 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
|
149 $horizontal & " aligned", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
150 horizontalAlignment = horizontal, |
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 vertical in VerticalAlignment: |
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 $vertical & " aligned", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
159 verticalAlignment = vertical, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
160 ) |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
161 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
|
162 renderdata, |
1292
5de466f5f087
add: color utils and textbox refactoring
sam <sam@basx.dev>
parents:
1283
diff
changeset
|
163 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
|
164 font, |
1327 | 165 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
|
166 """Paragraph |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
167 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
|
168 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
169 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
|
170 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
|
171 verticalAlignment = Top, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
172 horizontalAlignment = Left, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
173 ) |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
174 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 withNextFrame(framebuffer, commandbuffer): |
1327 | 179 bindDescriptorSet(commandbuffer, ds, 0, pipeline) |
1332 | 180 withRenderPass( |
181 vulkan.swapchain.renderPass, | |
182 framebuffer, | |
183 commandbuffer, | |
184 vulkan.swapchain.width, | |
185 vulkan.swapchain.height, | |
186 vec4(0, 0, 0, 0), | |
187 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
188 withPipeline(commandbuffer, pipeline): |
1327 | 189 for i in 0 ..< labels.len: |
1332 | 190 render( |
191 commandbuffer, | |
192 pipeline, | |
193 labels[i], | |
194 vec3(0.5 - i.float32 * 0.1, 0.5 - i.float32 * 0.1), | |
195 vec4(1, 1, 1, 1), | |
196 ) | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
197 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
198 # cleanup |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
199 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
|
200 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
201 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
|
202 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
203 proc test_04_lots_of_texts(time: float32) = |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
204 var font = loadFont[MAX_CODEPOINTS]("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
|
205 var renderdata = initRenderData() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
206 |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
207 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
208 renderPass = vulkan.swapchain.renderPass |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
209 ) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
210 |
1335 | 211 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas.copy())) |
1327 | 212 uploadImages(renderdata, ds) |
1332 | 213 initDescriptorSet(renderdata, pipeline.layout(0), ds) |
1327 | 214 |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
215 var labels: seq[Textbox] |
1327 | 216 var positions = newSeq[Vec3f](100) |
217 var colors = newSeq[Vec4f](100) | |
1329 | 218 var scales = newSeq[Vec2f](100) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
219 for i in 0 ..< 100: |
1327 | 220 positions[i] = vec3(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1)) |
1332 | 221 colors[i] = |
222 vec4(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)) | |
1329 | 223 scales[i] = vec2(rand(0.5'f32 .. 1.5'f32), rand(0.5'f32 .. 1.5'f32)) |
1332 | 224 labels.add initTextbox(renderdata, pipeline.layout(0), font, 0.001, $i) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
225 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
226 var start = getMonoTime() |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
227 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
228 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
|
229 l.refresh() |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
230 withNextFrame(framebuffer, commandbuffer): |
1327 | 231 bindDescriptorSet(commandbuffer, ds, 0, pipeline) |
1332 | 232 withRenderPass( |
233 vulkan.swapchain.renderPass, | |
234 framebuffer, | |
235 commandbuffer, | |
236 vulkan.swapchain.width, | |
237 vulkan.swapchain.height, | |
238 vec4(0, 0, 0, 0), | |
239 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
240 withPipeline(commandbuffer, pipeline): |
1327 | 241 for i in 0 ..< labels.len: |
1332 | 242 render( |
243 commandbuffer, pipeline, labels[i], positions[i], colors[i], scales[i] | |
244 ) | |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
245 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
246 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
247 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
|
248 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
249 destroyRenderData(renderdata) |
1399 | 250 ]# |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
251 |
1236 | 252 when isMainModule: |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
253 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
|
254 initVulkan() |
1236 | 255 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
256 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
|
257 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
|
258 setupSwapchain(renderpass = renderpass) |
1236 | 259 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
260 # tests a simple triangle with minimalistic shader and vertex format |
1404
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
261 test_01_static_label(time) |
80cfa19d1e2c
did: finally get text/glyph layouting correct again, 2/4 test adapted to new glyph API
sam <sam@basx.dev>
parents:
1403
diff
changeset
|
262 test_02_multi_counter(time) |
1379
9ca552dad5fc
did: continue working on new glyph-renderer
sam <sam@basx.dev>
parents:
1374
diff
changeset
|
263 # test_03_layouting(time) |
9ca552dad5fc
did: continue working on new glyph-renderer
sam <sam@basx.dev>
parents:
1374
diff
changeset
|
264 # 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
|
265 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
266 checkVkResult vkDeviceWaitIdle(vulkan.device) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
267 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
|
268 clearSwapchain() |
1236 | 269 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
270 destroyVulkan() |