Mercurial > games > semicongine
comparison tests/test_gltf.nim @ 1423:3b8a736c45a7
did: put almost all global state into a single struct
| author | sam <sam@basx.dev> |
|---|---|
| date | Thu, 09 Jan 2025 23:03:47 +0700 |
| parents | 5e5a3311ca44 |
| children | 676fc13685a9 |
comparison
equal
deleted
inserted
replaced
| 1422:6f0c1b347403 | 1423:3b8a736c45a7 |
|---|---|
| 4 import std/times | 4 import std/times |
| 5 import std/options | 5 import std/options |
| 6 | 6 |
| 7 import ../semicongine | 7 import ../semicongine |
| 8 | 8 |
| 9 proc test_gltf(time: float32) = | 9 proc test_gltf(time: float32, renderPass: RenderPass) = |
| 10 var renderdata = initRenderData() | 10 var renderdata = initRenderData() |
| 11 | 11 |
| 12 type | 12 type |
| 13 ObjectData = object | 13 ObjectData = object |
| 14 transform: Mat4 | 14 transform: Mat4 |
| 132 newSeqWith(primitive[0].position.data.len, vec4(1, 1, 1, 1)), VertexBuffer | 132 newSeqWith(primitive[0].position.data.len, vec4(1, 1, 1, 1)), VertexBuffer |
| 133 ) | 133 ) |
| 134 renderdata.assignBuffers(primitive[0]) | 134 renderdata.assignBuffers(primitive[0]) |
| 135 renderdata.assignBuffers(descriptors) | 135 renderdata.assignBuffers(descriptors) |
| 136 | 136 |
| 137 var pipeline = | 137 var pipeline = createPipeline(Shader(), renderPass = renderPass, cullMode = []) |
| 138 createPipeline(Shader(), renderPass = vulkan.swapchain.renderPass, cullMode = []) | |
| 139 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) | 138 initDescriptorSet(renderdata, pipeline.descriptorSetLayouts[0], descriptors) |
| 140 | 139 |
| 141 renderdata.flushAllMemory() | 140 renderdata.flushAllMemory() |
| 142 | 141 |
| 143 proc drawNode( | 142 proc drawNode( |
| 200 | 199 |
| 201 updateGPUBuffer(descriptors.data.camera) | 200 updateGPUBuffer(descriptors.data.camera) |
| 202 | 201 |
| 203 withNextFrame(framebuffer, commandbuffer): | 202 withNextFrame(framebuffer, commandbuffer): |
| 204 withRenderPass( | 203 withRenderPass( |
| 205 vulkan.swapchain.renderPass, | 204 renderPass, |
| 206 framebuffer, | 205 framebuffer, |
| 207 commandbuffer, | 206 commandbuffer, |
| 208 vulkan.swapchain.width, | 207 frameWidth(), |
| 209 vulkan.swapchain.height, | 208 frameHeight(), |
| 210 vec4(0, 0, 0, 0), | 209 vec4(0, 0, 0, 0), |
| 211 ): | 210 ): |
| 212 withPipeline(commandbuffer, pipeline): | 211 withPipeline(commandbuffer, pipeline): |
| 213 bindDescriptorSet(commandbuffer, descriptors, 0, pipeline) | 212 bindDescriptorSet(commandbuffer, descriptors, 0, pipeline) |
| 214 for nodeId in gltfData.scenes[0]: | 213 for nodeId in gltfData.scenes[0]: |
| 218 nodeId = nodeId, | 217 nodeId = nodeId, |
| 219 transform = rotate(PI / 2, Z), | 218 transform = rotate(PI / 2, Z), |
| 220 ) | 219 ) |
| 221 | 220 |
| 222 # cleanup | 221 # cleanup |
| 223 checkVkResult vkDeviceWaitIdle(vulkan.device) | 222 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
| 224 destroyPipeline(pipeline) | 223 destroyPipeline(pipeline) |
| 225 destroyRenderData(renderdata) | 224 destroyRenderData(renderdata) |
| 226 | 225 |
| 227 when isMainModule: | 226 when isMainModule: |
| 228 var time = 1000'f32 | 227 var time = 1000'f32 |
| 229 initVulkan() | 228 initEngine("Test glTF") |
| 230 | 229 |
| 231 var renderpass = createDirectPresentationRenderPass( | 230 var renderpass = createDirectPresentationRenderPass( |
| 232 depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT | 231 depthBuffer = true, samples = VK_SAMPLE_COUNT_4_BIT |
| 233 ) | 232 ) |
| 234 setupSwapchain(renderpass = renderpass) | 233 setupSwapchain(renderpass = renderpass) |
| 235 lockMouse(true) | 234 lockMouse(true) |
| 236 # showSystemCursor(false) | 235 # showSystemCursor(false) |
| 237 | 236 |
| 238 # tests a simple triangle with minimalistic shader and vertex format | 237 # tests a simple triangle with minimalistic shader and vertex format |
| 239 test_gltf(time) | 238 test_gltf(time, renderpass) |
| 240 | 239 |
| 241 checkVkResult vkDeviceWaitIdle(vulkan.device) | 240 checkVkResult vkDeviceWaitIdle(engine().vulkan.device) |
| 242 vkDestroyRenderPass(vulkan.device, renderpass.vk, nil) | 241 destroyRenderPass(renderpass) |
| 243 clearSwapchain() | 242 clearSwapchain() |
| 244 | 243 |
| 245 destroyVulkan() | 244 destroyVulkan() |
