comparison 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
comparison
equal deleted inserted replaced
1239:69489a678141 1240:42eeb59f3a43
1 import std/os 1 import std/os
2 import std/algorithm
2 import std/strutils 3 import std/strutils
3 import std/sequtils 4 import std/sequtils
4 import std/monotimes 5 import std/monotimes
5 import std/times 6 import std/times
6 import std/options 7 import std/options
158 checkVkResult vkDeviceWaitIdle(vulkan.device) 159 checkVkResult vkDeviceWaitIdle(vulkan.device)
159 DestroyPipeline(pipeline) 160 DestroyPipeline(pipeline)
160 DestroyRenderData(renderdata) 161 DestroyRenderData(renderdata)
161 162
162 proc test_04_lots_of_texts(time: float32) = 163 proc test_04_lots_of_texts(time: float32) =
163 discard # TODO 164 var renderdata = InitRenderData()
165
166 var pipeline = CreatePipeline[DefaultFontShader](renderPass = vulkan.swapchain.renderPass)
167
168 var font = LoadFont("DejaVuSans.ttf", lineHeightPixels = 160)
169 var labels: seq[Textbox]
170 for i in 0 ..< 100:
171 labels.add InitTextbox(
172 renderdata,
173 pipeline.descriptorSetLayouts[0],
174 font,
175 $i,
176 color = NewVec4f(rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0), rand(0.5 .. 1.0)),
177 scale = rand(0.0002 .. 0.002),
178 position = NewVec3f(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1))
179 )
180 labels = labels.sortedByIt(-it.Position.z)
181
182 var start = getMonoTime()
183 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
184 for l in labels.mitems:
185 l.Refresh()
186 WithNextFrame(framebuffer, commandbuffer):
187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)):
188 WithPipeline(commandbuffer, pipeline):
189 for l in labels:
190 Render(l, commandbuffer, pipeline)
191
192 # cleanup
193 checkVkResult vkDeviceWaitIdle(vulkan.device)
194 DestroyPipeline(pipeline)
195 DestroyRenderData(renderdata)
164 196
165 when isMainModule: 197 when isMainModule:
166 var time = 10'f32 198 var time = 1000'f32
167 InitVulkan() 199 InitVulkan()
168 200
169 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true) 201 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true)
170 SetupSwapchain(renderpass = renderpass) 202 SetupSwapchain(renderpass = renderpass)
171 203
172 # tests a simple triangle with minimalistic shader and vertex format 204 # tests a simple triangle with minimalistic shader and vertex format
173 # test_01_static_label(time, swapchain) 205 # test_01_static_label(time, swapchain)
174 # test_02_multiple_animated(time) 206 # test_02_multiple_animated(time)
175 test_03_layouting(time) 207 # test_03_layouting(time)
208 test_04_lots_of_texts(time)
176 209
177 210
178 checkVkResult vkDeviceWaitIdle(vulkan.device) 211 checkVkResult vkDeviceWaitIdle(vulkan.device)
179 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) 212 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)
180 213