Mercurial > games > semicongine
annotate tests/test_text.nim @ 1410:99d5b42cf32d
did: simplify text rendering API
author | sam <sam@basx.dev> |
---|---|
date | Thu, 26 Dec 2024 11:20:47 +0700 |
parents | 5a56f8ac328b |
children | bc6782c0edd6 |
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 |
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
|
14 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
|
15 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
|
16 # const FONTNAME = "DejaVuSans.ttf" |
1379
9ca552dad5fc
did: continue working on new glyph-renderer
sam <sam@basx.dev>
parents:
1374
diff
changeset
|
17 |
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
|
18 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
|
19 var font = loadFont[MAX_CODEPOINTS](FONTNAME, lineHeightPixels = 200) |
1374 | 20 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
|
21 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
|
22 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
|
23 ) |
1410 | 24 var textbuffer = font.initTextBuffer(1000, renderdata, baseScale = 0.1) |
1374 | 25 |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
26 font.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
27 font.addToPipeline(renderdata, pipeline) |
1399 | 28 |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
29 discard textbuffer.add("Hello semicongine!", vec3()) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
30 |
1374 | 31 var start = getMonoTime() |
32 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
|
33 let t = getMonoTime() |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
34 if windowWasResized(): |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
35 textbuffer.refresh() |
1400
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
36 |
1374 | 37 withNextFrame(framebuffer, commandbuffer): |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
38 font.bindTo(pipeline, commandbuffer) |
1374 | 39 withRenderPass( |
40 vulkan.swapchain.renderPass, | |
41 framebuffer, | |
42 commandbuffer, | |
43 vulkan.swapchain.width, | |
44 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
|
45 vec4(0, 0, 0, 0), |
1374 | 46 ): |
47 withPipeline(commandbuffer, pipeline): | |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
48 renderTextBuffer(commandbuffer, pipeline, textbuffer) |
1374 | 49 |
1400
20602878744e
did: finished basic implementation of new glyph-rendering system
sam <sam@basx.dev>
parents:
1399
diff
changeset
|
50 # cleanup |
1374 | 51 checkVkResult vkDeviceWaitIdle(vulkan.device) |
52 destroyPipeline(pipeline) | |
53 destroyRenderData(renderdata) | |
54 | |
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
|
55 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
|
56 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
|
57 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
|
58 var font3 = loadFont[MAX_CODEPOINTS]("DejaVuSans.ttf", lineHeightPixels = 160) |
1327 | 59 var renderdata = initRenderData() |
60 | |
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
|
61 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
|
62 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
|
63 ) |
1327 | 64 |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
65 font1.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
66 font2.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
67 font3.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
68 font1.addToPipeline(renderdata, pipeline) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
69 font2.addToPipeline(renderdata, pipeline) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
70 font3.addToPipeline(renderdata, pipeline) |
1327 | 71 |
1410 | 72 var textbuffer1 = font1.initTextBuffer(10, renderdata, baseScale = 0.1) |
73 var textbuffer2 = font2.initTextBuffer(10, renderdata, baseScale = 0.1) | |
74 var textbuffer3 = font3.initTextBuffer(10, renderdata, baseScale = 0.1) | |
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
|
75 |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
76 var p = 0 |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
77 let l1 = textbuffer1.add($(p + 0), vec3(0.3, 0.5), capacity = 5) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
78 let l2 = textbuffer2.add($(p + 1), vec3(0.5, 0.5), capacity = 5) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
79 let l3 = textbuffer3.add($(p + 2), vec3(0.7, 0.5), capacity = 5) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
80 |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
81 var start = getMonoTime() |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
82 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
83 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
|
84 |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
85 inc p |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
86 |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
87 textbuffer1.text(l1, $(p + 0)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
88 textbuffer2.text(l2, $(p + 1)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
89 textbuffer3.text(l3, $(p + 2)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
90 |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
91 textbuffer1.refresh() |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
92 textbuffer2.refresh() |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
93 textbuffer3.refresh() |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
94 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
95 withNextFrame(framebuffer, commandbuffer): |
1332 | 96 withRenderPass( |
97 vulkan.swapchain.renderPass, | |
98 framebuffer, | |
99 commandbuffer, | |
100 vulkan.swapchain.width, | |
101 vulkan.swapchain.height, | |
102 vec4(0, 0, 0, 0), | |
103 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
104 withPipeline(commandbuffer, pipeline): |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
105 bindDescriptorSet(commandbuffer, font1.descriptorSet, 3, pipeline) |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
106 renderTextBuffer(commandbuffer, pipeline, textbuffer1) |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
107 bindDescriptorSet(commandbuffer, font2.descriptorSet, 3, pipeline) |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
108 renderTextBuffer(commandbuffer, pipeline, textbuffer2) |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
109 bindDescriptorSet(commandbuffer, font3.descriptorSet, 3, pipeline) |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
110 renderTextBuffer(commandbuffer, pipeline, textbuffer3) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
111 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
112 # cleanup |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
113 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
|
114 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
115 destroyRenderData(renderdata) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
116 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
117 proc test_03_layouting(time: float32) = |
1406
aeb15aa9768c
did: continue text layout, improve vector api
sam <sam@basx.dev>
parents:
1405
diff
changeset
|
118 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
|
119 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
|
120 |
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
|
121 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
|
122 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
|
123 ) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
124 |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
125 font.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
126 font.addToPipeline(renderdata, pipeline) |
1405 | 127 |
1410 | 128 var textbuffer = font.initTextBuffer(1000, renderdata, baseScale = 0.1) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
129 |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
130 discard textbuffer.add("Anchor at center", vec3(0, 0), anchor = vec2(0, 0)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
131 discard textbuffer.add("Anchor at top left`", vec3(-1, 1), anchor = vec2(-1, 1)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
132 discard textbuffer.add("Anchor at top right", vec3(1, 1), anchor = vec2(1, 1)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
133 discard textbuffer.add("Anchor at bottom left", vec3(-1, -1), anchor = vec2(-1, -1)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
134 discard textbuffer.add("Anchor at bottom right", vec3(1, -1), anchor = vec2(1, -1)) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
135 |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
136 discard textbuffer.add( |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
137 "Mutiline text\nLeft aligned\nCool!", vec3(-0.5, -0.5), alignment = Left |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
138 ) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
139 discard textbuffer.add( |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
140 "Mutiline text\nCenter aligned\nCool!!", vec3(0, -0.5), alignment = Center |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
141 ) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
142 discard textbuffer.add( |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
143 "Mutiline text\nRight aligned\nCool!!!", vec3(0.5, -0.5), alignment = Right |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
144 ) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
145 |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
146 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
|
147 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
|
148 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
149 if windowWasResized(): |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
150 textbuffer.refresh() |
1406
aeb15aa9768c
did: continue text layout, improve vector api
sam <sam@basx.dev>
parents:
1405
diff
changeset
|
151 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
152 withNextFrame(framebuffer, commandbuffer): |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
153 bindDescriptorSet(commandbuffer, font.descriptorSet, 3, pipeline) |
1332 | 154 withRenderPass( |
155 vulkan.swapchain.renderPass, | |
156 framebuffer, | |
157 commandbuffer, | |
158 vulkan.swapchain.width, | |
159 vulkan.swapchain.height, | |
160 vec4(0, 0, 0, 0), | |
161 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
162 withPipeline(commandbuffer, pipeline): |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
163 renderTextBuffer(commandbuffer, pipeline, textbuffer) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
164 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
165 # cleanup |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
166 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
|
167 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
168 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
|
169 |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
170 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
|
171 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
|
172 var renderdata = initRenderData() |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
173 |
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
|
174 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
|
175 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
|
176 ) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
177 |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
178 font.upload(renderdata) |
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
179 font.addToPipeline(renderdata, pipeline) |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
180 |
1410 | 181 var textbuffer = font.initTextBuffer(3000, renderdata, baseScale = 0.1) |
1327 | 182 |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
183 for i in 0 ..< 1000: |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
184 discard textbuffer.add( |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
185 $i, |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
186 vec3(rand(-0.8 .. 0.8), rand(-0.8 .. 0.8), rand(-0.1 .. 0.1)), |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
187 color = |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
188 vec4(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)), |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
189 scale = rand(0.5'f32 .. 1.5'f32), |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
190 ) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
191 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
192 var start = getMonoTime() |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
193 var last = start |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
194 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
195 let n = getMonoTime() |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
196 echo (n - last).inMicroseconds() / 1000 |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
197 last = n |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
198 withNextFrame(framebuffer, commandbuffer): |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
199 if windowWasResized(): |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
200 textbuffer.refresh() |
1409
5a56f8ac328b
did: improve descriptor-set handling + last fixes for new font/text rendering api
sam <sam@basx.dev>
parents:
1408
diff
changeset
|
201 bindDescriptorSet(commandbuffer, font.descriptorSet, 3, pipeline) |
1332 | 202 withRenderPass( |
203 vulkan.swapchain.renderPass, | |
204 framebuffer, | |
205 commandbuffer, | |
206 vulkan.swapchain.width, | |
207 vulkan.swapchain.height, | |
208 vec4(0, 0, 0, 0), | |
209 ): | |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
210 withPipeline(commandbuffer, pipeline): |
1407
56f927b89716
did: finally got typography right, still improving text-rendering API to cache text parts
sam <sam@basx.dev>
parents:
1406
diff
changeset
|
211 renderTextBuffer(commandbuffer, pipeline, textbuffer) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
212 |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
213 # cleanup |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
214 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
|
215 destroyPipeline(pipeline) |
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
216 destroyRenderData(renderdata) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
217 |
1236 | 218 when isMainModule: |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
219 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
|
220 initVulkan() |
1236 | 221 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
222 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
|
223 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
|
224 setupSwapchain(renderpass = renderpass) |
1236 | 225 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
226 # tests a simple triangle with minimalistic shader and vertex format |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
227 test_01_static_label(time) |
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
228 test_02_multi_counter(time) |
1405 | 229 test_03_layouting(time) |
1408
17d960ff6a24
did: implement decent text rendering (I hope, we'll see)
sam <sam@basx.dev>
parents:
1407
diff
changeset
|
230 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
|
231 |
1241
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
232 checkVkResult vkDeviceWaitIdle(vulkan.device) |
a0ed1a918fda
fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents:
1240
diff
changeset
|
233 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
|
234 clearSwapchain() |
1236 | 235 |
1283
0369fa1ffbd9
did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents:
1282
diff
changeset
|
236 destroyVulkan() |