comparison src/engine.nim @ 10:0660ba9d1930

did: make it work on windows
author sam <sam@basx.dev>
date Sat, 24 Dec 2022 22:32:46 +0700
parents 1134f41a49e9
children 3415afff1d1a
comparison
equal deleted inserted replaced
8:1134f41a49e9 10:0660ba9d1930
10 import ./events 10 import ./events
11 11
12 import ./glslang/glslang 12 import ./glslang/glslang
13 13
14 const MAX_FRAMES_IN_FLIGHT = 2 14 const MAX_FRAMES_IN_FLIGHT = 2
15 const DEBUG_LOG = not defined(release)
15 16
16 var logger = newConsoleLogger() 17 var logger = newConsoleLogger()
17 addHandler(logger) 18 addHandler(logger)
18 19
19 20
135 return VkExtent2D( 136 return VkExtent2D(
136 width: min(max(uint32(width), capabilities.minImageExtent.width), capabilities.maxImageExtent.width), 137 width: min(max(uint32(width), capabilities.minImageExtent.width), capabilities.maxImageExtent.width),
137 height: min(max(uint32(height), capabilities.minImageExtent.height), capabilities.maxImageExtent.height), 138 height: min(max(uint32(height), capabilities.minImageExtent.height), capabilities.maxImageExtent.height),
138 ) 139 )
139 140
140 when not defined(release): 141 when DEBUG_LOG:
141 proc setupDebugLog(instance: VkInstance): VkDebugUtilsMessengerEXT = 142 proc setupDebugLog(instance: VkInstance): VkDebugUtilsMessengerEXT =
142 var createInfo = VkDebugUtilsMessengerCreateInfoEXT( 143 var createInfo = VkDebugUtilsMessengerCreateInfoEXT(
143 sType: VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT, 144 sType: VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
144 messageSeverity: VkDebugUtilsMessageSeverityFlagsEXT( 145 messageSeverity: VkDebugUtilsMessageSeverityFlagsEXT(
145 ord(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) or 146 ord(VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT) or
420 result[0], 421 result[0],
421 vulkan.renderPass, 422 vulkan.renderPass,
422 vulkan.frameDimension 423 vulkan.frameDimension
423 ) 424 )
424 425
425 # createFramebuffers();
426
427 426
428 proc setupCommandBuffers(device: VkDevice, graphicsQueueFamily: uint32): (VkCommandPool, array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer]) = 427 proc setupCommandBuffers(device: VkDevice, graphicsQueueFamily: uint32): (VkCommandPool, array[MAX_FRAMES_IN_FLIGHT, VkCommandBuffer]) =
429 # set up command buffer 428 # set up command buffer
430 var poolInfo = VkCommandPoolCreateInfo( 429 var poolInfo = VkCommandPoolCreateInfo(
431 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, 430 sType: VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
463 462
464 # setup vulkan functions 463 # setup vulkan functions
465 vkLoad1_0() 464 vkLoad1_0()
466 vkLoad1_1() 465 vkLoad1_1()
467 vkLoad1_2() 466 vkLoad1_2()
467
468 checkGlslangResult glslang_initialize_process() 468 checkGlslangResult glslang_initialize_process()
469 469
470 # create vulkan instance 470 # create vulkan instance
471 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION) 471 result.vulkan.instance = createVulkanInstance(VULKAN_VERSION)
472 when not defined(release): 472 when DEBUG_LOG:
473 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog() 473 result.vulkan.debugMessenger = result.vulkan.instance.setupDebugLog()
474 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window) 474 result.vulkan.surface = result.vulkan.instance.createVulkanSurface(result.window)
475 result.vulkan.device = result.vulkan.instance.setupVulkanDeviceAndQueues(result.vulkan.surface) 475 result.vulkan.device = result.vulkan.instance.setupVulkanDeviceAndQueues(result.vulkan.surface)
476 476
477 # get basic frame information 477 # get basic frame information
637 for shaderStage in engine.vulkan.pipeline.shaderStages: 637 for shaderStage in engine.vulkan.pipeline.shaderStages:
638 engine.vulkan.device.device.vkDestroyShaderModule(shaderStage.module, nil) 638 engine.vulkan.device.device.vkDestroyShaderModule(shaderStage.module, nil)
639 639
640 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil) 640 engine.vulkan.instance.vkDestroySurfaceKHR(engine.vulkan.surface, nil)
641 engine.vulkan.device.device.vkDestroyDevice(nil) 641 engine.vulkan.device.device.vkDestroyDevice(nil)
642 when ENABLEVULKANVALIDATIONLAYERS: 642 when DEBUG_LOG:
643 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil) 643 engine.vulkan.instance.vkDestroyDebugUtilsMessengerEXT(engine.vulkan.debugMessenger, nil)
644 glslang_finalize_process() 644 glslang_finalize_process()
645 engine.vulkan.instance.vkDestroyInstance(nil) 645 engine.vulkan.instance.vkDestroyInstance(nil)
646 engine.window.trash() 646 engine.window.trash()