annotate tests/test_text.nim @ 1281:c09cdff9a97e

merge
author sam <sam@basx.dev>
date Mon, 29 Jul 2024 15:53:03 +0700
parents 4cf9872f7bb6
children 3308b88e53a6
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) =
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
13 var renderdata = InitRenderData()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
14
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
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
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
17 var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
18 var label1 = InitTextbox(
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
19 renderdata,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
20 pipeline.descriptorSetLayouts[0],
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:
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
29 label1.Refresh()
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
30 WithNextFrame(framebuffer, commandbuffer):
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
31 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
32 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
33 Render(label1, commandbuffer, pipeline)
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)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
37 DestroyPipeline(pipeline)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
38 DestroyRenderData(renderdata)
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) =
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
41 var renderdata = InitRenderData()
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
42
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
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
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
45 var font1 = LoadFont("Overhaul.ttf", lineHeightPixels = 40)
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
46 var font2 = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
47 var font3 = LoadFont("DejaVuSans.ttf", lineHeightPixels = 160)
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
48 var labels = [
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
49 InitTextbox(
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
50 renderdata,
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
51 pipeline.descriptorSetLayouts[0],
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 ),
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
58 InitTextbox(
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
59 renderdata,
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
60 pipeline.descriptorSetLayouts[0],
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 ),
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
67 InitTextbox(
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
68 renderdata,
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
69 pipeline.descriptorSetLayouts[0],
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:
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
83 var c = labels[i].Color
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
84 c[i] = progress
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
85 labels[i].Color = c
1238
03634915bbdb add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents: 1237
diff changeset
86 labels[i].Scale = labels[i].Scale * (1.0 + (i + 1).float * 0.001)
1281
sam <sam@basx.dev>
parents: 1267
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)
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
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
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
91 WithNextFrame(framebuffer, commandbuffer):
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
92 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
1237
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
93 WithPipeline(commandbuffer, pipeline):
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
94 for label in labels:
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
95 Render(label, commandbuffer, pipeline)
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)
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
99 DestroyPipeline(pipeline)
97813ac43cfb add: multi-text with all properties animated
sam <sam@basx.dev>
parents: 1236
diff changeset
100 DestroyRenderData(renderdata)
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) =
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
103 var renderdata = InitRenderData()
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
104
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
105 var pipeline = CreatePipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
106
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
107 var font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 40)
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:
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
111 labels.add InitTextbox(
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
112 renderdata,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
113 pipeline.descriptorSetLayouts[0],
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:
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
122 labels.add InitTextbox(
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
123 renderdata,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
124 pipeline.descriptorSetLayouts[0],
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 )
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
132 labels.add InitTextbox(
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
133 renderdata,
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
134 pipeline.descriptorSetLayouts[0],
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
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
152 WithNextFrame(framebuffer, commandbuffer):
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
153 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
1239
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
154 WithPipeline(commandbuffer, pipeline):
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:
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
156 Render(label, commandbuffer, pipeline)
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)
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
160 DestroyPipeline(pipeline)
69489a678141 add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents: 1238
diff changeset
161 DestroyRenderData(renderdata)
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) =
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
164 var renderdata = InitRenderData()
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
165
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
166 var pipeline = CreatePipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
167
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
168 var font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 160)
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:
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
171 labels.add InitTextbox(
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
172 renderdata,
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
173 pipeline.descriptorSetLayouts[0],
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 )
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
180 labels = labels.sortedByIt(-it.Position.z)
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:
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
185 l.Refresh()
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
186 WithNextFrame(framebuffer, commandbuffer):
1281
sam <sam@basx.dev>
parents: 1267
diff changeset
187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
1240
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
188 WithPipeline(commandbuffer, pipeline):
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
189 for l in labels:
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
190 Render(l, commandbuffer, pipeline)
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)
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
diff changeset
194 DestroyPipeline(pipeline)
42eeb59f3a43 add: more tests, line and point rendering
sam <sam@basx.dev>
parents: 1239
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
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
199 InitVulkan()
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]:
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
202 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = depthBuffer)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
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)
a0ed1a918fda fix: letters sometimes overlapping other letters quad
sam <sam@basx.dev>
parents: 1240
diff changeset
213 ClearSwapchain()
1236
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
214
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
215 DestroyVulkan()