comparison 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
comparison
equal deleted inserted replaced
1280:a89a70ea3da2 1281:c09cdff9a97e
18 var label1 = InitTextbox( 18 var label1 = InitTextbox(
19 renderdata, 19 renderdata,
20 pipeline.descriptorSetLayouts[0], 20 pipeline.descriptorSetLayouts[0],
21 font, 21 font,
22 "Hello semicongine!", 22 "Hello semicongine!",
23 color = NewVec4f(1, 1, 1, 1), 23 color = vec4(1, 1, 1, 1),
24 scale = 0.0005, 24 scale = 0.0005,
25 ) 25 )
26 26
27 var start = getMonoTime() 27 var start = getMonoTime()
28 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 28 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
29 label1.Refresh() 29 label1.Refresh()
30 WithNextFrame(framebuffer, commandbuffer): 30 WithNextFrame(framebuffer, commandbuffer):
31 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 31 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
32 WithPipeline(commandbuffer, pipeline): 32 WithPipeline(commandbuffer, pipeline):
33 Render(label1, commandbuffer, pipeline) 33 Render(label1, commandbuffer, pipeline)
34 34
35 # cleanup 35 # cleanup
36 checkVkResult vkDeviceWaitIdle(vulkan.device) 36 checkVkResult vkDeviceWaitIdle(vulkan.device)
49 InitTextbox( 49 InitTextbox(
50 renderdata, 50 renderdata,
51 pipeline.descriptorSetLayouts[0], 51 pipeline.descriptorSetLayouts[0],
52 font1, 52 font1,
53 " 0", 53 " 0",
54 color = NewVec4f(0, 1, 1, 1), 54 color = vec4(0, 1, 1, 1),
55 scale = 0.004, 55 scale = 0.004,
56 position = NewVec3f(-0.3, 0.5) 56 position = vec3(-0.3, 0.5)
57 ), 57 ),
58 InitTextbox( 58 InitTextbox(
59 renderdata, 59 renderdata,
60 pipeline.descriptorSetLayouts[0], 60 pipeline.descriptorSetLayouts[0],
61 font2, 61 font2,
62 " 1", 62 " 1",
63 color = NewVec4f(1, 0, 1, 1), 63 color = vec4(1, 0, 1, 1),
64 scale = 0.001, 64 scale = 0.001,
65 position = NewVec3f(0, 0) 65 position = vec3(0, 0)
66 ), 66 ),
67 InitTextbox( 67 InitTextbox(
68 renderdata, 68 renderdata,
69 pipeline.descriptorSetLayouts[0], 69 pipeline.descriptorSetLayouts[0],
70 font3, 70 font3,
71 " 2", 71 " 2",
72 color = NewVec4f(1, 1, 0, 1), 72 color = vec4(1, 1, 0, 1),
73 scale = 0.001, 73 scale = 0.001,
74 position = NewVec3f(0.3, -0.5) 74 position = vec3(0.3, -0.5)
75 ) 75 )
76 ] 76 ]
77 77
78 var start = getMonoTime() 78 var start = getMonoTime()
79 var p = 0 79 var p = 0
82 for i in 0 ..< labels.len: 82 for i in 0 ..< labels.len:
83 var c = labels[i].Color 83 var c = labels[i].Color
84 c[i] = progress 84 c[i] = progress
85 labels[i].Color = c 85 labels[i].Color = c
86 labels[i].Scale = labels[i].Scale * (1.0 + (i + 1).float * 0.001) 86 labels[i].Scale = labels[i].Scale * (1.0 + (i + 1).float * 0.001)
87 labels[i].Position = labels[i].Position + NewVec3f(0.001 * (i.float - 1'f)) 87 labels[i].Position = labels[i].Position + vec3(0.001 * (i.float - 1'f))
88 labels[i].text = $(p + i) 88 labels[i].text = $(p + i)
89 labels[i].Refresh() 89 labels[i].Refresh()
90 inc p 90 inc p
91 WithNextFrame(framebuffer, commandbuffer): 91 WithNextFrame(framebuffer, commandbuffer):
92 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 92 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
93 WithPipeline(commandbuffer, pipeline): 93 WithPipeline(commandbuffer, pipeline):
94 for label in labels: 94 for label in labels:
95 Render(label, commandbuffer, pipeline) 95 Render(label, commandbuffer, pipeline)
96 96
97 # cleanup 97 # cleanup
111 labels.add InitTextbox( 111 labels.add InitTextbox(
112 renderdata, 112 renderdata,
113 pipeline.descriptorSetLayouts[0], 113 pipeline.descriptorSetLayouts[0],
114 font, 114 font,
115 $horizontal & " aligned", 115 $horizontal & " aligned",
116 color = NewVec4f(1, 1, 1, 1), 116 color = vec4(1, 1, 1, 1),
117 scale = 0.001, 117 scale = 0.001,
118 position = NewVec3f(0, 0.9 - (horizontal.float * 0.15)), 118 position = vec3(0, 0.9 - (horizontal.float * 0.15)),
119 horizontalAlignment = horizontal, 119 horizontalAlignment = horizontal,
120 ) 120 )
121 for vertical in VerticalAlignment: 121 for vertical in VerticalAlignment:
122 labels.add InitTextbox( 122 labels.add InitTextbox(
123 renderdata, 123 renderdata,
124 pipeline.descriptorSetLayouts[0], 124 pipeline.descriptorSetLayouts[0],
125 font, 125 font,
126 $vertical & " aligned", 126 $vertical & " aligned",
127 color = NewVec4f(1, 1, 1, 1), 127 color = vec4(1, 1, 1, 1),
128 scale = 0.001, 128 scale = 0.001,
129 position = NewVec3f(-0.35 + (vertical.float * 0.35), 0.3), 129 position = vec3(-0.35 + (vertical.float * 0.35), 0.3),
130 verticalAlignment = vertical, 130 verticalAlignment = vertical,
131 ) 131 )
132 labels.add InitTextbox( 132 labels.add InitTextbox(
133 renderdata, 133 renderdata,
134 pipeline.descriptorSetLayouts[0], 134 pipeline.descriptorSetLayouts[0],
136 """Paragraph 136 """Paragraph
137 This is a somewhat longer paragraph with a few newlines and a maximum width of 0.2. 137 This is a somewhat longer paragraph with a few newlines and a maximum width of 0.2.
138 138
139 It should display with some space above and have a pleasing appearance overall! :)""", 139 It should display with some space above and have a pleasing appearance overall! :)""",
140 maxWidth = 0.6, 140 maxWidth = 0.6,
141 color = NewVec4f(1, 1, 1, 1), 141 color = vec4(1, 1, 1, 1),
142 scale = 0.001, 142 scale = 0.001,
143 position = NewVec3f(-0.9, 0.1), 143 position = vec3(-0.9, 0.1),
144 verticalAlignment = Top, 144 verticalAlignment = Top,
145 horizontalAlignment = Left, 145 horizontalAlignment = Left,
146 ) 146 )
147 147
148 148
149 var start = getMonoTime() 149 var start = getMonoTime()
150 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 150 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
151 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time 151 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time
152 WithNextFrame(framebuffer, commandbuffer): 152 WithNextFrame(framebuffer, commandbuffer):
153 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 153 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
154 WithPipeline(commandbuffer, pipeline): 154 WithPipeline(commandbuffer, pipeline):
155 for label in labels: 155 for label in labels:
156 Render(label, commandbuffer, pipeline) 156 Render(label, commandbuffer, pipeline)
157 157
158 # cleanup 158 # cleanup
171 labels.add InitTextbox( 171 labels.add InitTextbox(
172 renderdata, 172 renderdata,
173 pipeline.descriptorSetLayouts[0], 173 pipeline.descriptorSetLayouts[0],
174 font, 174 font,
175 $i, 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)), 176 color = vec4(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), 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)) 178 position = vec3(rand(-0.5 .. 0.5), rand(-0.5 .. 0.5), rand(-0.1 .. 0.1))
179 ) 179 )
180 labels = labels.sortedByIt(-it.Position.z) 180 labels = labels.sortedByIt(-it.Position.z)
181 181
182 var start = getMonoTime() 182 var start = getMonoTime()
183 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: 183 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time:
184 for l in labels.mitems: 184 for l in labels.mitems:
185 l.Refresh() 185 l.Refresh()
186 WithNextFrame(framebuffer, commandbuffer): 186 WithNextFrame(framebuffer, commandbuffer):
187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, NewVec4f(0, 0, 0, 0)): 187 WithRenderPass(vulkan.swapchain.renderPass, framebuffer, commandbuffer, vulkan.swapchain.width, vulkan.swapchain.height, vec4(0, 0, 0, 0)):
188 WithPipeline(commandbuffer, pipeline): 188 WithPipeline(commandbuffer, pipeline):
189 for l in labels: 189 for l in labels:
190 Render(l, commandbuffer, pipeline) 190 Render(l, commandbuffer, pipeline)
191 191
192 # cleanup 192 # cleanup