comparison tests/test_text.nim @ 1237:97813ac43cfb

add: multi-text with all properties animated
author sam <sam@basx.dev>
date Sun, 21 Jul 2024 00:03:48 +0700
parents 176383220123
children 03634915bbdb
comparison
equal deleted inserted replaced
1236:176383220123 1237:97813ac43cfb
7 7
8 import ../semiconginev2 8 import ../semiconginev2
9 9
10 proc test_01_static_label(time: float32, swapchain: var Swapchain) = 10 proc test_01_static_label(time: float32, swapchain: var Swapchain) =
11 var renderdata = InitRenderData() 11 var renderdata = InitRenderData()
12
13 # scale: float32 = 1,
14 # position: Vec3f = NewVec3f(),
15 # color: Vec4f = NewVec4f(0, 0, 0, 1),
16 12
17 var pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass) 13 var pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass)
18 14
19 var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160) 15 var font = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
20 var label1 = InitTextbox( 16 var label1 = InitTextbox(
37 # cleanup 33 # cleanup
38 checkVkResult vkDeviceWaitIdle(vulkan.device) 34 checkVkResult vkDeviceWaitIdle(vulkan.device)
39 DestroyPipeline(pipeline) 35 DestroyPipeline(pipeline)
40 DestroyRenderData(renderdata) 36 DestroyRenderData(renderdata)
41 37
38 proc test_02_multiple_animated(time: float32, swapchain: var Swapchain) =
39 var renderdata = InitRenderData()
40
41 var pipeline = CreatePipeline[DefaultFontShader](renderPass = swapchain.renderPass)
42
43 var font1 = LoadFont("Overhaul.ttf", lineHeightPixels = 40)
44 var font2 = LoadFont("Overhaul.ttf", lineHeightPixels = 160)
45 var font3 = LoadFont("DejaVuSans.ttf", lineHeightPixels = 160)
46 var labels = [
47 InitTextbox(
48 renderdata,
49 pipeline.descriptorSetLayouts[0],
50 font1,
51 "0",
52 color = NewVec4f(0, 1, 1, 1),
53 scale = 0.004,
54 position = NewVec3f(-0.3, 0.5)
55 ),
56 InitTextbox(
57 renderdata,
58 pipeline.descriptorSetLayouts[0],
59 font2,
60 "1",
61 color = NewVec4f(1, 0, 1, 1),
62 scale = 0.001,
63 position = NewVec3f(0, 0)
64 ),
65 InitTextbox(
66 renderdata,
67 pipeline.descriptorSetLayouts[0],
68 font3,
69 "2",
70 color = NewVec4f(1, 1, 0, 1),
71 scale = 0.001,
72 position = NewVec3f(0.3, -0.5)
73 )
74 ]
75
76 var start = getMonoTime()
77 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
78 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
79 for i in 0 ..< labels.len:
80 var c = labels[i].Color
81 c[i] = progress
82 labels[i].Color = c
83 labels[i].Scale = labels[i].Scale * 1.002
84 labels[i].Position = labels[i].Position + NewVec3f(0.001 * (i.float - 1'f))
85 labels[i].Refresh(swapchain.GetAspectRatio())
86 WithNextFrame(swapchain, framebuffer, commandbuffer):
87 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
88 WithPipeline(commandbuffer, pipeline):
89 for label in labels:
90 Render(label, commandbuffer, pipeline, swapchain.currentFiF)
91
92 # cleanup
93 checkVkResult vkDeviceWaitIdle(vulkan.device)
94 DestroyPipeline(pipeline)
95 DestroyRenderData(renderdata)
96
97 proc test_03_layouting(time: float32, swapchain: var Swapchain) =
98 discard # TODO
99 proc test_04_lots_of_texts(time: float32, swapchain: var Swapchain) =
100 discard # TODO
101
42 when isMainModule: 102 when isMainModule:
43 var time = 10'f32 103 var time = 10'f32
44 InitVulkan() 104 InitVulkan()
45 105
46 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true) 106 var renderpass = CreateDirectPresentationRenderPass(depthBuffer = true)
47 var swapchain = InitSwapchain(renderpass = renderpass).get() 107 var swapchain = InitSwapchain(renderpass = renderpass).get()
48 108
49 # tests a simple triangle with minimalistic shader and vertex format 109 # tests a simple triangle with minimalistic shader and vertex format
50 test_01_static_label(time, swapchain) 110 # test_01_static_label(time, swapchain)
111 test_02_multiple_animated(time, swapchain)
51 112
52 checkVkResult vkDeviceWaitIdle(vulkan.device) 113 checkVkResult vkDeviceWaitIdle(vulkan.device)
53 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) 114 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil)
54 DestroySwapchain(swapchain) 115 DestroySwapchain(swapchain)
55 116