Mercurial > games > semicongine
comparison tests/test_rendering.nim @ 1203:6360c8d17ce0 compiletime-tests
did: preprations to add rendering tests
| author | sam <sam@basx.dev> |
|---|---|
| date | Mon, 15 Jul 2024 20:06:42 +0700 |
| parents | |
| children | e2901100a596 |
comparison
equal
deleted
inserted
replaced
| 1202:a8864fe6fe6e | 1203:6360c8d17ce0 |
|---|---|
| 1 import std/options | |
| 2 import ../semicongine | |
| 3 | |
| 4 var | |
| 5 mainRenderpass: VkRenderPass | |
| 6 swapchain: Swapchain | |
| 7 | |
| 8 proc test_01_gl_triangle() = | |
| 9 var renderdata = InitRenderData() | |
| 10 | |
| 11 type | |
| 12 TrianglShader = object | |
| 13 position {.VertexAttribute.}: Vec3f | |
| 14 color {.VertexAttribute.}: Vec3f | |
| 15 fragmentColor {.Pass.}: Vec3f | |
| 16 outColor {.ShaderOutput.}: Vec4f | |
| 17 # code | |
| 18 vertexCode: string = """void main() { | |
| 19 fragmentColor = color; | |
| 20 gl_Position = vec4(position, 1);}""" | |
| 21 fragmentCode: string = """void main() { | |
| 22 outColor = vec4(fragmentColor, 1);}""" | |
| 23 TriangleMesh = object | |
| 24 position: GPUArray[Vec3f, VertexBuffer] | |
| 25 color: GPUArray[Vec3f, VertexBuffer] | |
| 26 Empty = object | |
| 27 var mesh = TriangleMesh( | |
| 28 position: asGPUArray([NewVec3f(-0.5, -0.5), NewVec3f(-0.5, 0.5), NewVec3f(0.5, -0.5)], VertexBuffer), | |
| 29 color: asGPUArray([NewVec3f(0, 0, 1), NewVec3f(0, 1, 0), NewVec3f(1, 0, 0)], VertexBuffer), | |
| 30 ) | |
| 31 | |
| 32 var | |
| 33 pipeline = CreatePipeline[TrianglShader](renderPass = mainRenderpass) | |
| 34 a, b: Empty | |
| 35 | |
| 36 while UpdateInputs(): | |
| 37 WithNextFrame(swapchain, framebuffer, commandbuffer): | |
| 38 WithRenderPass(mainRenderpass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): | |
| 39 WithPipeline(commandbuffer, pipeline): | |
| 40 # WithBind(commandBuffer, a, b, pipeline, swapchain.currentFiF.int): | |
| 41 Render( | |
| 42 commandbuffer = commandbuffer, | |
| 43 pipeline = pipeline, | |
| 44 globalSet = a, | |
| 45 materialSet = b, | |
| 46 mesh = mesh, | |
| 47 ) | |
| 48 | |
| 49 # cleanup | |
| 50 DestroyPipeline(pipeline) | |
| 51 DestroyRenderData(renderdata) | |
| 52 | |
| 53 | |
| 54 when isMainModule: | |
| 55 mainRenderpass = CreatePresentationRenderPass() | |
| 56 swapchain = InitSwapchain(renderpass = mainRenderpass).get() | |
| 57 | |
| 58 test_01_gl_triangle() | |
| 59 | |
| 60 checkVkResult vkDeviceWaitIdle(vulkan.device) | |
| 61 vkDestroyRenderPass(vulkan.device, mainRenderpass, nil) | |
| 62 DestroySwapchain(swapchain) | |
| 63 DestroyVulkan() |
