Mercurial > games > semicongine
comparison tests/test_text.nim @ 1379:9ca552dad5fc
did: continue working on new glyph-renderer
author | sam <sam@basx.dev> |
---|---|
date | Thu, 12 Dec 2024 19:17:43 +0700 |
parents | 92c089136a05 |
children | 4aa9e703af48 |
comparison
equal
deleted
inserted
replaced
1375:ca3299ea1bdf | 1379:9ca552dad5fc |
---|---|
10 import ../semicongine | 10 import ../semicongine |
11 | 11 |
12 type FontDS = object | 12 type FontDS = object |
13 fontAtlas: Image[Gray] | 13 fontAtlas: Image[Gray] |
14 | 14 |
15 type EMPTY = object | |
16 | |
15 proc test_01_static_label_new(time: float32) = | 17 proc test_01_static_label_new(time: float32) = |
16 var font = loadFont("Overhaul.ttf", lineHeightPixels = 160) | 18 var font = loadFont("Overhaul.ttf", lineHeightPixels = 160) |
17 var renderdata = initRenderData() | 19 var renderdata = initRenderData() |
18 var pipeline = | 20 var pipeline = |
19 createPipeline[GlyphShader[200]](renderPass = vulkan.swapchain.renderPass) | 21 createPipeline[GlyphShader[200]](renderPass = vulkan.swapchain.renderPass) |
20 | 22 var glyphs = Glyphs( |
21 var ds = asDescriptorSetData(GlyphDescriptors[200](fontAtlas: font.fontAtlas.copy())) | 23 position: asGPUArray([vec3()], VertexBufferMapped), |
24 scale: asGPUArray([1'f32], VertexBufferMapped), | |
25 color: asGPUArray([vec4(1, 1, 1, 1)], VertexBufferMapped), | |
26 glyphIndex: asGPUArray([0'u16], VertexBufferMapped), | |
27 ) | |
28 | |
29 var ds = | |
30 asDescriptorSetData(GlyphDescriptorSet[200](fontAtlas: font.fontAtlas.copy())) | |
31 assignBuffers(renderdata, glyphs) | |
32 assignBuffers(renderdata, ds) | |
22 uploadImages(renderdata, ds) | 33 uploadImages(renderdata, ds) |
23 initDescriptorSet(renderdata, pipeline.layout(0), ds) | 34 initDescriptorSet(renderdata, pipeline.layout(0), ds) |
24 | 35 |
25 var start = getMonoTime() | 36 var start = getMonoTime() |
26 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: | 37 while ((getMonoTime() - start).inMilliseconds().int / 1000) < time: |
33 vulkan.swapchain.width, | 44 vulkan.swapchain.width, |
34 vulkan.swapchain.height, | 45 vulkan.swapchain.height, |
35 vec4(0, 0, 0, 0), | 46 vec4(0, 0, 0, 0), |
36 ): | 47 ): |
37 withPipeline(commandbuffer, pipeline): | 48 withPipeline(commandbuffer, pipeline): |
38 render(commandbuffer, pipeline, label1, vec3(), vec4(1, 1, 1, 1)) | 49 render(commandbuffer, pipeline, EMPTY(), glyphs, fixedVertexCount = 6) |
39 | 50 |
40 # cleanup | 51 # cleanup |
41 checkVkResult vkDeviceWaitIdle(vulkan.device) | 52 checkVkResult vkDeviceWaitIdle(vulkan.device) |
42 destroyPipeline(pipeline) | 53 destroyPipeline(pipeline) |
43 destroyRenderData(renderdata) | 54 destroyRenderData(renderdata) |
67 vulkan.swapchain.width, | 78 vulkan.swapchain.width, |
68 vulkan.swapchain.height, | 79 vulkan.swapchain.height, |
69 vec4(0, 0, 0, 0), | 80 vec4(0, 0, 0, 0), |
70 ): | 81 ): |
71 withPipeline(commandbuffer, pipeline): | 82 withPipeline(commandbuffer, pipeline): |
72 proc render( | 83 render(commandbuffer, pipeline, label1, vec3(), vec4(1, 1, 1, 1)) |
73 commandBuffer = commandbuffer, | |
74 pipeline = pipeline, | |
75 mesh: TMesh, | |
76 instances: TInstance, | |
77 fixedVertexCount = -1, | |
78 fixedInstanceCount = -1, | |
79 ) | |
80 | |
81 # cleanup | 84 # cleanup |
82 checkVkResult vkDeviceWaitIdle(vulkan.device) | 85 checkVkResult vkDeviceWaitIdle(vulkan.device) |
83 destroyPipeline(pipeline) | 86 destroyPipeline(pipeline) |
84 destroyRenderData(renderdata) | 87 destroyRenderData(renderdata) |
85 | 88 |
286 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer) | 289 var renderpass = createDirectPresentationRenderPass(depthBuffer = depthBuffer) |
287 setupSwapchain(renderpass = renderpass) | 290 setupSwapchain(renderpass = renderpass) |
288 | 291 |
289 # tests a simple triangle with minimalistic shader and vertex format | 292 # tests a simple triangle with minimalistic shader and vertex format |
290 test_01_static_label_new(time) | 293 test_01_static_label_new(time) |
291 test_01_static_label(time) | 294 # test_01_static_label(time) |
292 test_02_multiple_animated(time) | 295 # test_02_multiple_animated(time) |
293 test_03_layouting(time) | 296 # test_03_layouting(time) |
294 test_04_lots_of_texts(time) | 297 # test_04_lots_of_texts(time) |
295 | 298 |
296 checkVkResult vkDeviceWaitIdle(vulkan.device) | 299 checkVkResult vkDeviceWaitIdle(vulkan.device) |
297 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | 300 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) |
298 clearSwapchain() | 301 clearSwapchain() |
299 | 302 |