Mercurial > games > semicongine
comparison src/vulkan_helpers.nim @ 4:af9183acb173
did: refactor, add resizing, proper cleanup
| author | Sam <sam@basx.dev> |
|---|---|
| date | Tue, 20 Dec 2022 00:28:05 +0700 |
| parents | 213fdf8d31dd |
| children | 4ed9cb098315 |
comparison
equal
deleted
inserted
replaced
| 3:5d54ef652619 | 4:af9183acb173 |
|---|---|
| 14 | 14 |
| 15 template checkVkResult*(call: untyped) = | 15 template checkVkResult*(call: untyped) = |
| 16 when defined(release): | 16 when defined(release): |
| 17 discard call | 17 discard call |
| 18 else: | 18 else: |
| 19 debug(&"CALLING vulkan: {astToStr(call)}") | |
| 19 let value = call | 20 let value = call |
| 20 debug(&"CALLING vulkan: {astToStr(call)}") | |
| 21 if value != VK_SUCCESS: | 21 if value != VK_SUCCESS: |
| 22 raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) | 22 raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) |
| 23 | 23 |
| 24 | 24 |
| 25 proc VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = | 25 proc VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = |
| 28 | 28 |
| 29 proc filterForSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): seq[VkSurfaceFormatKHR] = | 29 proc filterForSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): seq[VkSurfaceFormatKHR] = |
| 30 for format in formats: | 30 for format in formats: |
| 31 if format.format == VK_FORMAT_B8G8R8A8_SRGB and format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: | 31 if format.format == VK_FORMAT_B8G8R8A8_SRGB and format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: |
| 32 result.add(format) | 32 result.add(format) |
| 33 | |
| 34 proc getSuitableSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): VkSurfaceFormatKHR = | |
| 35 let usableSurfaceFormats = filterForSurfaceFormat(formats) | |
| 36 if len(usableSurfaceFormats) == 0: | |
| 37 raise newException(Exception, "No suitable surface formats found") | |
| 38 return usableSurfaceFormats[0] | |
| 33 | 39 |
| 34 | 40 |
| 35 proc cleanString*(str: openArray[char]): string = | 41 proc cleanString*(str: openArray[char]): string = |
| 36 for i in 0 ..< len(str): | 42 for i in 0 ..< len(str): |
| 37 if str[i] == char(0): | 43 if str[i] == char(0): |
