comparison tests/test_rendering.nim @ 1233:1cf698973dca

did: cleanup tests and old platform layer files
author sam <sam@basx.dev>
date Fri, 19 Jul 2024 21:25:42 +0700
parents 32a977c71ba5
children c70fee6568f6
comparison
equal deleted inserted replaced
1232:32a977c71ba5 1233:1cf698973dca
1 import std/os
1 import std/sequtils 2 import std/sequtils
2 import std/monotimes 3 import std/monotimes
3 import std/times 4 import std/times
4 import std/options 5 import std/options
5 import std/random 6 import std/random
414 var c = 0 415 var c = 0
415 var tStart = getMonoTime() 416 var tStart = getMonoTime()
416 var t = tStart 417 var t = tStart
417 while UpdateInputs() and c < nFrames: 418 while UpdateInputs() and c < nFrames:
418 419
419 let t = getMonoTime() - tStart 420 let tStartLoop = getMonoTime() - tStart
420 421
421 uniforms1.data.data.data.mvp = ( 422 uniforms1.data.data.data.mvp = (
422 Perspective(-PI / 2, GetAspectRatio(swapchain), 0.01, 100) * 423 Perspective(-PI / 2, GetAspectRatio(swapchain), 0.01, 100) *
423 Translate(0, 0, 2) * 424 Translate(0, 0, 2) *
424 Rotate(PI / 4, X) * 425 Rotate(PI / 4, X) *
425 Rotate(PI * 0.5 * (t.inMicroseconds() / 1_000_000), Y) 426 Rotate(PI * 0.1 * (tStartLoop.inMicroseconds() / 1_000_000), Y)
426 ) 427 )
427 UpdateGPUBuffer(uniforms1.data.data, flush = true) 428 UpdateGPUBuffer(uniforms1.data.data, flush = true)
428 WithNextFrame(swapchain, framebuffer, commandbuffer): 429 WithNextFrame(swapchain, framebuffer, commandbuffer):
429 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)): 430 WithRenderPass(swapchain.renderPass, framebuffer, commandbuffer, swapchain.width, swapchain.height, NewVec4f(0, 0, 0, 0)):
430 WithPipeline(commandbuffer, pipeline): 431 WithPipeline(commandbuffer, pipeline):
431 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF): 432 WithBind(commandbuffer, (uniforms1, ), pipeline, swapchain.currentFiF):
432 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh) 433 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = mesh)
433 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor) 434 Render(commandbuffer = commandbuffer, pipeline = pipeline, mesh = floor)
435
436 let tEndLoop = getMonoTime() - tStart
437 let looptime = tEndLoop - tStartLoop
438 let waitTime = 16_666 - looptime.inMicroseconds
439 if waitTime > 0:
440 echo "sleep ", waitTime / 1000
441 sleep((waitTime / 1000).int)
434 inc c 442 inc c
435 443
436 # cleanup 444 # cleanup
437 checkVkResult vkDeviceWaitIdle(vulkan.device) 445 checkVkResult vkDeviceWaitIdle(vulkan.device)
438 DestroyPipeline(pipeline) 446 DestroyPipeline(pipeline)