annotate tests/test_text.nim @ 1236:176383220123

add: first font-rendering test
author sam <sam@basx.dev>
date Sat, 20 Jul 2024 17:45:44 +0700
parents
children 97813ac43cfb
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
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
2 import std/sequtils
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
3 import std/monotimes
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
4 import std/times
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
5 import std/options
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
6 import std/random
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
7
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
8 import ../semiconginev2
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
9
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
10 proc test_01_static_label(time: float32, swapchain: var Swapchain) =
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
11 var renderdata = InitRenderData()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
12
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
13 # scale: float32 = 1,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
14 # position: Vec3f = NewVec3f(),
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
15 # color: Vec4f = NewVec4f(0, 0, 0, 1),
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 pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
18
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
19 var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
20 var label1 = InitTextbox(
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
21 renderdata,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
22 pipeline.descriptorSetLayouts[0],
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
23 font,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
24 "Hello semicongine!",
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
25 color = NewVec4f(1, 1, 1, 1),
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
26 scale = 0.0005,
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
27 )
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
28
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
29 var start = getMonoTime()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
30 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
31 label1.Refresh(swapchain.GetAspectRatio())
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
32 WithNextFrame(swapchain, framebuffer, commandbuffer):
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
33 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
34 WithPipeline(commandbuffer, pipeline):
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
35 Render(label1, commandbuffer, pipeline, swapchain.currentFiF)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
36
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
37 # cleanup
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
38 checkVkResult vkDeviceWaitIdle(vulkan.device)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
39 DestroyPipeline(pipeline)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
40 DestroyRenderData(renderdata)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
41
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
42 when isMainModule:
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
43 var time = 10'f32
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
44 InitVulkan()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
45
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
46 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
47 var swapchain = InitSwapchain(renderpass = renderpass).get()
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
48
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
49 # tests a simple triangle with minimalistic shader and vertex format
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
50 test_01_static_label(time, swapchain)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
51
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
52 checkVkResult vkDeviceWaitIdle(vulkan.device)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
53 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
54 DestroySwapchain(swapchain)
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
55
176383220123 add: first font-rendering test
sam <sam@basx.dev>
parents:
diff changeset
56 DestroyVulkan()