Mercurial > games > semicongine
diff src/zamikongine/vulkan_helpers.nim @ 38:c3c963e7c1a6
did: tons of stuff, input, refactoring, fix some errors, some template improvment, sorry for super-commit
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 18 Jan 2023 09:52:03 +0700 |
parents | b45a5d338cd0 |
children |
line wrap: on
line diff
--- a/src/zamikongine/vulkan_helpers.nim Mon Jan 16 00:51:03 2023 +0700 +++ b/src/zamikongine/vulkan_helpers.nim Wed Jan 18 09:52:03 2023 +0700 @@ -7,10 +7,6 @@ import ./vulkan import ./window - -const ENABLEVULKANVALIDATIONLAYERS* = not defined(release) - - template checkVkResult*(call: untyped) = when defined(release): discard call @@ -25,6 +21,14 @@ error "Vulkan error: ", astToStr(call), " returned ", $value raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) +# the included code need checkVkResult, therefore having the template above +when defined(linux): + include ./platform/linux/vulkan +when defined(windows): + include ./platform/windows/vulkan + +const ENABLEVULKANVALIDATIONLAYERS* = not defined(release) + func addrOrNil[T](obj: var openArray[T]): ptr T = if obj.len > 0: addr(obj[0]) else: nil @@ -132,11 +136,7 @@ proc createVulkanInstance*(vulkanVersion: uint32): VkInstance = - var requiredExtensions = @["VK_KHR_surface".cstring] - when defined(linux): - requiredExtensions.add("VK_KHR_xlib_surface".cstring) - when defined(windows): - requiredExtensions.add("VK_KHR_win32_surface".cstring) + var requiredExtensions = @["VK_KHR_surface".cstring] & REQUIRED_PLATFORM_EXTENSIONS when ENABLEVULKANVALIDATIONLAYERS: requiredExtensions.add("VK_EXT_debug_utils".cstring) @@ -177,10 +177,7 @@ checkVkResult vkCreateInstance(addr(createinfo), nil, addr(result)) loadVK_KHR_surface() - when defined(linux): - loadVK_KHR_xlib_surface() - when defined(windows): - loadVK_KHR_win32_surface() + load_platform_extensions() loadVK_KHR_swapchain() when ENABLEVULKANVALIDATIONLAYERS: loadVK_EXT_debug_utils(result) @@ -228,20 +225,3 @@ proc getSurfaceCapabilities*(device: VkPhysicalDevice, surface: VkSurfaceKHR): VkSurfaceCapabilitiesKHR = checkVkResult device.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(surface, addr(result)) - -when defined(linux): - proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = - var surfaceCreateInfo = VkXlibSurfaceCreateInfoKHR( - sType: VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, - dpy: window.display, - window: window.window, - ) - checkVkResult vkCreateXlibSurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) -when defined(windows): - proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = - var surfaceCreateInfo = VkWin32SurfaceCreateInfoKHR( - sType: VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, - hinstance: window.hinstance, - hwnd: window.hwnd, - ) - checkVkResult vkCreateWin32SurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result))