annotate tests/test_text.nim @ 1311:b22c3b7bc026

fix: release build error
author sam <sam@basx.dev>
date Fri, 09 Aug 2024 12:46:38 +0700
parents 5de466f5f087
children 385dbd68a947
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
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
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
4 import std/sequtils
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
5 import std/monotimes
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
6 import std/times
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
7 import std/options
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
8 import std/random
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
9
1267
4cf9872f7bb6 did: rename back to old name (no v2)
sam <sam@basx.dev>
parents: 1241
diff changeset
10 import ../semicongine
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
11
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
12 proc test_01_static_label(time: float32) =
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
13 var renderdata = initRenderData()
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
14
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
15 var pipeline = createPipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
16
1282
3308b88e53a6 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1281
diff changeset
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 label1 = initTextbox(
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
19 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
20 pipeline.layout(0),
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
21 font,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
22 "Hello semicongine!",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
23 color = vec4(1, 1, 1, 1),
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
24 scale = 0.0005,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
25 )
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
26
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
27 var start = getMonoTime()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
28 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
29 label1.refresh()
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
30 withNextFrame(framebuffer, commandbuffer):
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
31 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
32 withPipeline(commandbuffer, pipeline):
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
33 render(commandbuffer, pipeline, label1)
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
34
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
35 # cleanup
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
36 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
37 destroyPipeline(pipeline)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
38 destroyRenderData(renderdata)
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
39
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
40 proc test_02_multiple_animated(time: float32) =
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
41 var renderdata = initRenderData()
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
42
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
43 var pipeline = createPipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
44
1282
3308b88e53a6 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1281
diff changeset
45 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
46 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
47 var font3 = loadFont("DejaVuSans.ttf", lineHeightPixels = 160)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
48 var labels = [
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
49 initTextbox(
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
50 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
51 pipeline.layout(0),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
52 font1,
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
53 " 0",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
54 color = vec4(0, 1, 1, 1),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
55 scale = 0.004,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
56 position = vec3(-0.3, 0.5)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
57 ),
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
58 initTextbox(
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
59 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
60 pipeline.layout(0),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
61 font2,
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
62 " 1",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
63 color = vec4(1, 0, 1, 1),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
64 scale = 0.001,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
65 position = vec3(0, 0)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
66 ),
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
67 initTextbox(
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
68 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
69 pipeline.layout(0),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
70 font3,
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
71 " 2",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
72 color = vec4(1, 1, 0, 1),
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
73 scale = 0.001,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
74 position = vec3(0.3, -0.5)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
75 )
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
76 ]
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
77
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
78 var start = getMonoTime()
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
79 var p = 0
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
80 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
81 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
82 for i in 0 ..< labels.len:
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
83 var c = labels[i].color
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
84 c[i] = progress
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
85 labels[i].color = c
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
86 labels[i].scale = labels[i].scale * (1.0 + (i + 1).float * 0.001)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
87 labels[i].position = labels[i].position + vec3(0.001 * (i.float - 1'f))
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
88 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
89 labels[i].refresh()
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
90 inc p
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
91 withNextFrame(framebuffer, commandbuffer):
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
92 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
93 withPipeline(commandbuffer, pipeline):
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
94 for label in labels:
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
95 render(commandbuffer, pipeline, label)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
96
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
97 # cleanup
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
98 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
99 destroyPipeline(pipeline)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
100 destroyRenderData(renderdata)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
101
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
102 proc test_03_layouting(time: float32) =
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
103 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
104
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
105 var pipeline = createPipeline[DefaultFontShader](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
106
1282
3308b88e53a6 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1281
diff changeset
107 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 40)
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
108 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
109
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
110 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
111 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
112 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
113 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
114 font,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
115 $horizontal & " aligned",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
116 color = 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
117 scale = 0.001,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
118 position = vec3(0, 0.9 - (horizontal.float * 0.15)),
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
119 horizontalAlignment = horizontal,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
120 )
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
121 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
122 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
123 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
124 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
125 font,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
126 $vertical & " aligned",
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
127 color = 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
128 scale = 0.001,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
129 position = vec3(-0.35 + (vertical.float * 0.35), 0.3),
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
130 verticalAlignment = vertical,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
131 )
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
132 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
133 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
134 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
135 font,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
136 """Paragraph
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
137 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
138
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
139 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
140 maxWidth = 0.6,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
141 color = 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
142 scale = 0.001,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
143 position = vec3(-0.9, 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
144 verticalAlignment = Top,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
145 horizontalAlignment = Left,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
146 )
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
147
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
148
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
149 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
150 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
151 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
152 withNextFrame(framebuffer, commandbuffer):
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
153 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
154 withPipeline(commandbuffer, pipeline):
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
155 for label in labels:
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
156 render(commandbuffer, pipeline, label)
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
157
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
158 # cleanup
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
159 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
160 destroyPipeline(pipeline)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
161 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
162
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
163 proc test_04_lots_of_texts(time: float32) =
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
164 var renderdata = initRenderData()
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
165
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
166 var pipeline = createPipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
167
1282
3308b88e53a6 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1281
diff changeset
168 var font = loadFont("DejaVuSans.ttf", lineHeightPixels = 160)
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
169 var labels: seq[Textbox]
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
170 for i in 0 ..< 100:
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
171 labels.add initTextbox(
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
172 renderdata,
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
173 pipeline.layout(0),
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
174 font,
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
175 $i,
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
176 color = vec4(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)),
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
177 scale = rand(0.0002 .. 0.002),
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
178 position = vec3(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1))
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
179 )
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
180 labels = labels.sortedByIt(-it.position.z)
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
181
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
182 var start = getMonoTime()
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
183 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
184 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
185 l.refresh()
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
186 withNextFrame(framebuffer, commandbuffer):
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
187 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
188 withPipeline(commandbuffer, pipeline):
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
189 for l in labels:
1292
5de466f5f087 add: color utils and textbox refactoring
sam <sam@basx.dev>
parents: 1283
diff changeset
190 render(commandbuffer, pipeline, l)
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 # cleanup
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
193 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
194 destroyPipeline(pipeline)
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
195 destroyRenderData(renderdata)
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
196
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
197 when isMainModule:
1241
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
198 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
199 initVulkan()
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
200
1241
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
201 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
202 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
203 setupSwapchain(renderpass = renderpass)
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
204
1241
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
205 # 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
206 test_01_static_label(time)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
207 test_02_multiple_animated(time)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
208 test_03_layouting(time)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
209 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
210
1241
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
211 checkVkResult vkDeviceWaitIdle(vulkan.device)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
212 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
213 clearSwapchain()
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
214
1283
0369fa1ffbd9 did: undo part of stupid API renaming a few weeks back ;(
sam <sam@basx.dev>
parents: 1282
diff changeset
215 destroyVulkan()