Mercurial > games > semicongine
comparison tests/test_text.nim @ 1406:aeb15aa9768c
did: continue text layout, improve vector api
author | sam <sam@basx.dev> |
---|---|
date | Sat, 21 Dec 2024 19:32:59 +0700 |
parents | 46bac138ad6c |
children | 56f927b89716 |
comparison
equal
deleted
inserted
replaced
1405:46bac138ad6c | 1406:aeb15aa9768c |
---|---|
121 checkVkResult vkDeviceWaitIdle(vulkan.device) | 121 checkVkResult vkDeviceWaitIdle(vulkan.device) |
122 destroyPipeline(pipeline) | 122 destroyPipeline(pipeline) |
123 destroyRenderData(renderdata) | 123 destroyRenderData(renderdata) |
124 | 124 |
125 proc test_03_layouting(time: float32) = | 125 proc test_03_layouting(time: float32) = |
126 var font = loadFont[MAX_CODEPOINTS]("DejaVuSans.ttf", lineHeightPixels = 40) | 126 var font = loadFont[MAX_CODEPOINTS]("DejaVuSans.ttf", lineHeightPixels = 160) |
127 var renderdata = initRenderData() | 127 var renderdata = initRenderData() |
128 | 128 |
129 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( | 129 var pipeline = createPipeline[GlyphShader[MAX_CODEPOINTS]]( |
130 renderPass = vulkan.swapchain.renderPass | 130 renderPass = vulkan.swapchain.renderPass |
131 ) | 131 ) |
132 | |
133 var ds = asDescriptorSetData(FontDS(fontAtlas: font.fontAtlas.copy())) | |
134 | 132 |
135 assignBuffers(renderdata, font.descriptorSet) | 133 assignBuffers(renderdata, font.descriptorSet) |
136 uploadImages(renderdata, font.descriptorSet) | 134 uploadImages(renderdata, font.descriptorSet) |
137 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet) | 135 initDescriptorSet(renderdata, pipeline.layout(0), font.descriptorSet) |
138 | 136 |
139 var glyphs = font.initGlyphs(1000, baseScale = 0.1) | 137 var glyphs = font.initGlyphs(1000, baseScale = 0.1) |
140 assignBuffers(renderdata, glyphs) | 138 assignBuffers(renderdata, glyphs) |
141 | 139 |
142 for horizontal in HorizontalAlignment: | |
143 glyphs.add $horizontal & " aligned" | |
144 for vertical in VerticalAlignment: | |
145 glyphs.add $vertical & " aligned" | |
146 | |
147 glyphs.add( | |
148 """Paragraph | |
149 This is a somewhat longer paragraph with a few newlines and a maximum width of 0.2. | |
150 | |
151 It should display with some space above and have a pleasing appearance overall! :)""", | |
152 verticalAlignment = Top, | |
153 horizontalAlignment = Left, | |
154 ) | |
155 | |
156 var start = getMonoTime() | 140 var start = getMonoTime() |
157 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 141 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
158 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time | 142 let progress = ((getMonoTime() - start).inMilliseconds().int / 1000) / time |
143 | |
144 glyphs.reset() | |
145 glyphs.add("Anchor Center", vec3(0, 0), anchor = vec2(0, 0)) | |
146 glyphs.add("Anchor top left", vec3(0, 0), anchor = vec2(-1, 1)) | |
147 glyphs.add("Anchor top right", vec3(0, 0), anchor = vec2(1, 1)) | |
148 glyphs.add("Anchor bottom left", vec3(0, 0), anchor = vec2(-1, -1)) | |
149 glyphs.add("Anchor bottom right", vec3(0, 0), anchor = vec2(1, -1)) | |
150 | |
151 glyphs.add( | |
152 """Paragraph | |
153 This is a somewhat longer paragraph with a few newlines and a maximum width of 0.2. | |
154 | |
155 It should display with some space above and have a pleasing appearance overall! :)""", | |
156 vec3(0.5, 0.5), | |
157 anchor = vec2(0, 0), | |
158 alignment = Center, | |
159 ) | |
160 glyphs.updateAllGPUBuffers(flush = true) | |
161 | |
159 withNextFrame(framebuffer, commandbuffer): | 162 withNextFrame(framebuffer, commandbuffer): |
160 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) | 163 bindDescriptorSet(commandbuffer, font.descriptorSet, 0, pipeline) |
161 withRenderPass( | 164 withRenderPass( |
162 vulkan.swapchain.renderPass, | 165 vulkan.swapchain.renderPass, |
163 framebuffer, | 166 framebuffer, |
223 destroyPipeline(pipeline) | 226 destroyPipeline(pipeline) |
224 destroyRenderData(renderdata) | 227 destroyRenderData(renderdata) |
225 ]# | 228 ]# |
226 | 229 |
227 when isMainModule: | 230 when isMainModule: |
228 var time = 1'f32 | 231 var time = 100'f32 |
229 initVulkan() | 232 initVulkan() |
230 | 233 |
231 for depthBuffer in [true, false]: | 234 for depthBuffer in [true, false]: |
232 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer) | 235 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer) |
233 setupSwapchain(renderpass = renderpass) | 236 setupSwapchain(renderpass = renderpass) |
234 | 237 |
235 # tests a simple triangle with minimalistic shader and vertex format | 238 # tests a simple triangle with minimalistic shader and vertex format |
236 test_01_static_label(time) | 239 # test_01_static_label(time) |
237 test_02_multi_counter(time) | 240 # test_02_multi_counter(time) |
238 test_03_layouting(time) | 241 test_03_layouting(time) |
239 # test_04_lots_of_texts(time) | 242 # test_04_lots_of_texts(time) |
240 | 243 |
241 checkVkResult vkDeviceWaitIdle(vulkan.device) | 244 checkVkResult vkDeviceWaitIdle(vulkan.device) |
242 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | 245 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |