comparison src/zamikongine/engine.nim @ 22:b45a5d338cd0

did: improve alotof_triangles example, remove glslang lib, use only binary, easier cross-compilation
author Sam <sam@basx.dev>
date Wed, 11 Jan 2023 00:43:17 +0700
parents beb86492b178
children 71bbe11d8de8
comparison
equal deleted inserted replaced
21:316923e9247c 22:b45a5d338cd0
12 import ./shader 12 import ./shader
13 import ./vertex 13 import ./vertex
14 import ./buffer 14 import ./buffer
15 import ./thing 15 import ./thing
16 import ./mesh 16 import ./mesh
17
18 import ./glslang/glslang
19 17
20 const MAX_FRAMES_IN_FLIGHT = 2 18 const MAX_FRAMES_IN_FLIGHT = 2
21 const DEBUG_LOG = not defined(release) 19 const DEBUG_LOG = not defined(release)
22 20
23 var logger = newConsoleLogger() 21 var logger = newConsoleLogger()
453 # setup vulkan functions 451 # setup vulkan functions
454 vkLoad1_0() 452 vkLoad1_0()
455 vkLoad1_1() 453 vkLoad1_1()
456 vkLoad1_2() 454 vkLoad1_2()
457 455
458 checkGlslangResult glslang_initialize_process()
459
460 # create vulkan instance 456 # create vulkan instance
461 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION) 457 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION)
462 when DEBUG_LOG: 458 when DEBUG_LOG:
463 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog() 459 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog()
464 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window) 460 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window)
503 fragmentShader, 499 fragmentShader,
504 ) 500 )
505 var allmeshes: seq[Mesh[T]] 501 var allmeshes: seq[Mesh[T]]
506 for mesh in partsOfType[ref Mesh[T]](engine.currentscenedata): 502 for mesh in partsOfType[ref Mesh[T]](engine.currentscenedata):
507 allmeshes.add(mesh[]) 503 allmeshes.add(mesh[])
508 var ubermesh = createUberMesh(allmeshes) 504 if allmeshes.len > 0:
509 engine.vulkan.vertexBuffers.add createVertexBuffers(ubermesh, engine.vulkan.device.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue) 505 var ubermesh = createUberMesh(allmeshes)
506 engine.vulkan.vertexBuffers.add createVertexBuffers(ubermesh, engine.vulkan.device.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue)
510 507
511 var allindexedmeshes: seq[IndexedMesh[T, U]] 508 var allindexedmeshes: seq[IndexedMesh[T, U]]
512 for mesh in partsOfType[ref IndexedMesh[T, U]](engine.currentscenedata): 509 for mesh in partsOfType[ref IndexedMesh[T, U]](engine.currentscenedata):
513 allindexedmeshes.add(mesh[]) 510 allindexedmeshes.add(mesh[])
514 var indexedubermesh = createUberMesh(allindexedmeshes) 511 if allindexedmeshes.len > 0:
515 engine.vulkan.indexedVertexBuffers.add createIndexedVertexBuffers(indexedubermesh, engine.vulkan.device.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue) 512 var indexedubermesh = createUberMesh(allindexedmeshes)
513 engine.vulkan.indexedVertexBuffers.add createIndexedVertexBuffers(indexedubermesh, engine.vulkan.device.device, engine.vulkan.device.physicalDevice.device, engine.vulkan.commandPool, engine.vulkan.device.graphicsQueue)
516 514
517 proc recordCommandBuffer(renderPass: VkRenderPass, pipeline: VkPipeline, commandBuffer: VkCommandBuffer, framebuffer: VkFramebuffer, frameDimension: VkExtent2D, engine: var Engine) = 515 proc recordCommandBuffer(renderPass: VkRenderPass, pipeline: VkPipeline, commandBuffer: VkCommandBuffer, framebuffer: VkFramebuffer, frameDimension: VkExtent2D, engine: var Engine) =
518 var 516 var
519 beginInfo = VkCommandBufferBeginInfo( 517 beginInfo = VkCommandBufferBeginInfo(
520 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, 518 sType: VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
676 674
677 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil) 675 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil)
678 engine.vulkan.device.device.vkDestroyDevice(nil) 676 engine.vulkan.device.device.vkDestroyDevice(nil)
679 when DEBUG_LOG: 677 when DEBUG_LOG:
680 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil) 678 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil)
681 glslang_finalize_process()
682 engine.window.trash() 679 engine.window.trash()
683 engine.vulkan.instance.vkDestroyInstance(nil) 680 engine.vulkan.instance.vkDestroyInstance(nil)