Mercurial > games > semicongine
annotate tests/test_text.nim @ 1240:42eeb59f3a43
add: more tests, line and point rendering
author | sam <sam@basx.dev> |
---|---|
date | Mon, 22 Jul 2024 12:42:35 +0700 |
parents | 69489a678141 |
children | a0ed1a918fda |
rev | line source |
---|---|
1236 | 1 import std/os |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
2 import std/algorithm |
1238
03634915bbdb
add: tests for updating texts, does not pass validation atm
sam <sam@basx.dev>
parents:
1237
diff
changeset
|
3 import std/strutils |
1236 | 4 import std/sequtils |
5 import std/monotimes | |
6 import std/times | |
7 import std/options | |
8 import std/random | |
9 | |
10 import ../semiconginev2 | |
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 | 13 var renderdata = InitRenderData() |
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 | 16 |
17 var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160) | |
18 var label1 = InitTextbox( | |
19 renderdata, | |
20 pipeline.descriptorSetLayouts[0], | |
21 font, | |
22 "Hello semicongine!", | |
23 color = NewVec4f(1, 1, 1, 1), | |
24 scale = 0.0005, | |
25 ) | |
26 | |
27 var start = getMonoTime() | |
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): |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
31 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
1236 | 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 | 34 |
35 # cleanup | |
36 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
37 DestroyPipeline(pipeline) | |
38 DestroyRenderData(renderdata) | |
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", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
54 color = NewVec4f(0, 1, 1, 1), |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
55 scale = 0.004, |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
56 position = NewVec3f(-0.3, 0.5) |
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", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
63 color = NewVec4f(1, 0, 1, 1), |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
64 scale = 0.001, |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
65 position = NewVec3f(0, 0) |
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", |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
72 color = NewVec4f(1, 1, 0, 1), |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
73 scale = 0.001, |
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
74 position = NewVec3f(0.3, -0.5) |
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) |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
87 labels[i].Position = labels[i].Position + NewVec3f(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): |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
92 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(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", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
116 color = NewVec4f(1, 1, 1, 1), |
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, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
118 position = NewVec3f(0, 0.9 - (horizontal.float * 0.15)), |
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", |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
127 color = NewVec4f(1, 1, 1, 1), |
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, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
129 position = NewVec3f(-0.35 + (vertical.float * 0.35), 0.3), |
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, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
141 color = NewVec4f(1, 1, 1, 1), |
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, |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
143 position = NewVec3f(-0.9, 0.1), |
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): |
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
153 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
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, |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
176 color = NewVec4f(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
177 scale = rand(0.0002 .. 0.002), |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
178 position = NewVec3f(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1)) |
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): |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): |
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 | 197 when isMainModule: |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
198 var time = 1000'f32 |
1236 | 199 InitVulkan() |
200 | |
201 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true) | |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
202 SetupSwapchain(renderpass = renderpass) |
1236 | 203 |
204 # tests a simple triangle with minimalistic shader and vertex format | |
1237
97813ac43cfb
add: multi-text with all properties animated
sam <sam@basx.dev>
parents:
1236
diff
changeset
|
205 # test_01_static_label(time, swapchain) |
1239
69489a678141
add: better syncing, better swapchain access, correct font offset, two font-rendering tests
sam <sam@basx.dev>
parents:
1238
diff
changeset
|
206 # test_02_multiple_animated(time) |
1240
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
207 # test_03_layouting(time) |
42eeb59f3a43
add: more tests, line and point rendering
sam <sam@basx.dev>
parents:
1239
diff
changeset
|
208 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
|
209 |
1236 | 210 |
211 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
212 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | |
213 | |
214 DestroyVulkan() |