Mercurial > games > semicongine
annotate src/vulkan_helpers.nim @ 479:16842d15319a
add: basic vertex buffer functionality
author | Sam <sam@basx.dev> |
---|---|
date | Thu, 05 Jan 2023 01:16:48 +0700 |
parents | 871ee602bf95 |
children |
rev | line source |
---|---|
462 | 1 import std/tables |
461 | 2 import std/strutils |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
3 import std/strformat |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
4 import std/logging |
471 | 5 import std/macros |
462 | 6 |
7 import ./vulkan | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
8 import ./window |
462 | 9 |
471 | 10 |
11 const ENABLEVULKANVALIDATIONLAYERS* = not defined(release) | |
461 | 12 |
13 | |
14 template checkVkResult*(call: untyped) = | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
15 when defined(release): |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
16 discard call |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
17 else: |
478 | 18 # yes, a bit cheap, but this is only for nice debug output |
19 var callstr = astToStr(call).replace("\n", "") | |
20 while callstr.find(" ") >= 0: | |
21 callstr = callstr.replace(" ", " ") | |
22 debug "CALLING vulkan: ", callstr | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
23 let value = call |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
24 if value != VK_SUCCESS: |
471 | 25 error "Vulkan error: ", astToStr(call), " returned ", $value |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
26 raise newException(Exception, "Vulkan error: " & astToStr(call) & " returned " & $value) |
461 | 27 |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
28 func addrOrNil[T](obj: var openArray[T]): ptr T = |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
29 if obj.len > 0: addr(obj[0]) else: nil |
461 | 30 |
478 | 31 func VK_MAKE_API_VERSION*(variant: uint32, major: uint32, minor: uint32, patch: uint32): uint32 {.compileTime.} = |
461 | 32 (variant shl 29) or (major shl 22) or (minor shl 12) or patch |
33 | |
462 | 34 |
478 | 35 func filterForSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): seq[VkSurfaceFormatKHR] = |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
36 for format in formats: |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
37 if format.format == VK_FORMAT_B8G8R8A8_SRGB and format.colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR: |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
38 result.add(format) |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
39 |
478 | 40 func getSuitableSurfaceFormat*(formats: seq[VkSurfaceFormatKHR]): VkSurfaceFormatKHR = |
465
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
41 let usableSurfaceFormats = filterForSurfaceFormat(formats) |
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
42 if len(usableSurfaceFormats) == 0: |
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
43 raise newException(Exception, "No suitable surface formats found") |
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
44 return usableSurfaceFormats[0] |
2fcb9268072b
did: refactor, add resizing, proper cleanup
Sam <sam@basx.dev>
parents:
463
diff
changeset
|
45 |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
46 |
478 | 47 func cleanString*(str: openArray[char]): string = |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
48 for i in 0 ..< len(str): |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
49 if str[i] == char(0): |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
50 result = join(str[0 ..< i]) |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
51 break |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
52 |
461 | 53 proc getInstanceExtensions*(): seq[string] = |
54 var extensionCount: uint32 | |
55 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), nil) | |
56 var extensions = newSeq[VkExtensionProperties](extensionCount) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
57 checkVkResult vkEnumerateInstanceExtensionProperties(nil, addr(extensionCount), addrOrNil(extensions)) |
461 | 58 |
59 for extension in extensions: | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
60 result.add(cleanString(extension.extensionName)) |
461 | 61 |
62 | |
63 proc getDeviceExtensions*(device: VkPhysicalDevice): seq[string] = | |
64 var extensionCount: uint32 | |
65 checkVkResult vkEnumerateDeviceExtensionProperties(device, nil, addr(extensionCount), nil) | |
66 var extensions = newSeq[VkExtensionProperties](extensionCount) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
67 checkVkResult vkEnumerateDeviceExtensionProperties(device, nil, addr(extensionCount), addrOrNil(extensions)) |
461 | 68 |
69 for extension in extensions: | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
70 result.add(cleanString(extension.extensionName)) |
461 | 71 |
72 | |
73 proc getValidationLayers*(): seq[string] = | |
74 var n_layers: uint32 | |
75 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), nil) | |
76 var layers = newSeq[VkLayerProperties](n_layers) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
77 checkVkResult vkEnumerateInstanceLayerProperties(addr(n_layers), addrOrNil(layers)) |
461 | 78 |
79 for layer in layers: | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
80 result.add(cleanString(layer.layerName)) |
461 | 81 |
82 | |
83 proc getVulkanPhysicalDevices*(instance: VkInstance): seq[VkPhysicalDevice] = | |
84 var n_devices: uint32 | |
85 checkVkResult vkEnumeratePhysicalDevices(instance, addr(n_devices), nil) | |
86 result = newSeq[VkPhysicalDevice](n_devices) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
87 checkVkResult vkEnumeratePhysicalDevices(instance, addr(n_devices), addrOrNil(result)) |
461 | 88 |
89 | |
90 proc getQueueFamilies*(device: VkPhysicalDevice): seq[VkQueueFamilyProperties] = | |
91 var n_queuefamilies: uint32 | |
92 vkGetPhysicalDeviceQueueFamilyProperties(device, addr(n_queuefamilies), nil) | |
93 result = newSeq[VkQueueFamilyProperties](n_queuefamilies) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
94 vkGetPhysicalDeviceQueueFamilyProperties(device, addr(n_queuefamilies), addrOrNil(result)) |
461 | 95 |
96 | |
97 proc getDeviceSurfaceFormats*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkSurfaceFormatKHR] = | |
98 var n_formats: uint32 | |
99 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), nil); | |
100 result = newSeq[VkSurfaceFormatKHR](n_formats) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
101 checkVkResult vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, addr(n_formats), addrOrNil(result)) |
461 | 102 |
103 | |
104 proc getDeviceSurfacePresentModes*(device: VkPhysicalDevice, surface: VkSurfaceKHR): seq[VkPresentModeKHR] = | |
105 var n_modes: uint32 | |
106 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), nil); | |
107 result = newSeq[VkPresentModeKHR](n_modes) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
108 checkVkResult vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, addr(n_modes), addrOrNil(result)) |
461 | 109 |
110 | |
111 proc getSwapChainImages*(device: VkDevice, swapChain: VkSwapchainKHR): seq[VkImage] = | |
112 var n_images: uint32 | |
113 checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), nil); | |
114 result = newSeq[VkImage](n_images) | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
115 checkVkResult vkGetSwapchainImagesKHR(device, swapChain, addr(n_images), addrOrNil(result)); |
461 | 116 |
117 | |
478 | 118 func getPresentMode*(modes: seq[VkPresentModeKHR]): VkPresentModeKHR = |
461 | 119 let preferredModes = [ |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
120 VK_PRESENT_MODE_MAILBOX_KHR, # triple buffering |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
121 VK_PRESENT_MODE_FIFO_RELAXED_KHR, # double duffering |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
122 VK_PRESENT_MODE_FIFO_KHR, # double duffering |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
123 VK_PRESENT_MODE_IMMEDIATE_KHR, # single buffering |
461 | 124 ] |
125 for preferredMode in preferredModes: | |
126 for mode in modes: | |
127 if preferredMode == mode: | |
128 return mode | |
129 # should never be reached, but seems to be garuanteed by vulkan specs to always be available | |
130 return VK_PRESENT_MODE_FIFO_KHR | |
131 | |
132 | |
133 proc createVulkanInstance*(vulkanVersion: uint32): VkInstance = | |
471 | 134 |
473 | 135 var requiredExtensions = @["VK_KHR_surface".cstring] |
471 | 136 when defined(linux): |
473 | 137 requiredExtensions.add("VK_KHR_xlib_surface".cstring) |
471 | 138 when defined(windows): |
473 | 139 requiredExtensions.add("VK_KHR_win32_surface".cstring) |
140 when ENABLEVULKANVALIDATIONLAYERS: | |
141 requiredExtensions.add("VK_EXT_debug_utils".cstring) | |
471 | 142 |
461 | 143 let availableExtensions = getInstanceExtensions() |
144 for extension in requiredExtensions: | |
471 | 145 assert $extension in availableExtensions, $extension |
461 | 146 |
147 let availableLayers = getValidationLayers() | |
148 var usableLayers = newSeq[cstring]() | |
149 | |
150 when ENABLEVULKANVALIDATIONLAYERS: | |
473 | 151 const desiredLayers = ["VK_LAYER_KHRONOS_validation".cstring, "VK_LAYER_MESA_overlay".cstring] |
461 | 152 for layer in desiredLayers: |
153 if $layer in availableLayers: | |
154 usableLayers.add(layer) | |
155 | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
156 echo "Available validation layers: ", availableLayers |
461 | 157 echo "Using validation layers: ", usableLayers |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
158 echo "Available extensions: ", availableExtensions |
461 | 159 echo "Using extensions: ", requiredExtensions |
160 | |
161 var appinfo = VkApplicationInfo( | |
162 sType: VK_STRUCTURE_TYPE_APPLICATION_INFO, | |
163 pApplicationName: "Hello Triangle", | |
164 pEngineName: "Custom engine", | |
165 apiVersion: vulkanVersion, | |
166 ) | |
167 var createinfo = VkInstanceCreateInfo( | |
168 sType: VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, | |
169 pApplicationInfo: addr(appinfo), | |
170 enabledLayerCount: usableLayers.len.uint32, | |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
171 ppEnabledLayerNames: cast[ptr UncheckedArray[cstring]](addrOrNil(usableLayers)), |
461 | 172 enabledExtensionCount: requiredExtensions.len.uint32, |
473 | 173 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions[0])) |
461 | 174 ) |
175 checkVkResult vkCreateInstance(addr(createinfo), nil, addr(result)) | |
176 | |
177 loadVK_KHR_surface() | |
471 | 178 when defined(linux): |
179 loadVK_KHR_xlib_surface() | |
180 when defined(windows): | |
181 loadVK_KHR_win32_surface() | |
461 | 182 loadVK_KHR_swapchain() |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
183 when ENABLEVULKANVALIDATIONLAYERS: |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
184 loadVK_EXT_debug_utils(result) |
461 | 185 |
186 | |
187 proc getVulcanDevice*( | |
188 physicalDevice: var VkPhysicalDevice, | |
189 features: var VkPhysicalDeviceFeatures, | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
190 graphicsQueueFamily: uint32, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
191 presentationQueueFamily: uint32, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
192 ): (VkDevice, VkQueue, VkQueue) = |
461 | 193 # setup queue and device |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
194 # TODO: need check this, possibly wrong logic, see Vulkan tutorial |
461 | 195 var priority = 1.0'f32 |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
196 var queueCreateInfo = [ |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
197 VkDeviceQueueCreateInfo( |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
198 sType: VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
199 queueFamilyIndex: graphicsQueueFamily, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
200 queueCount: 1, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
201 pQueuePriorities: addr(priority), |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
202 ), |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
203 ] |
461 | 204 |
205 var requiredExtensions = ["VK_KHR_swapchain".cstring] | |
206 var deviceCreateInfo = VkDeviceCreateInfo( | |
207 sType: VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
208 queueCreateInfoCount: uint32(queueCreateInfo.len), |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
209 pQueueCreateInfos: addrOrNil(queueCreateInfo), |
461 | 210 pEnabledFeatures: addr(features), |
211 enabledExtensionCount: requiredExtensions.len.uint32, | |
212 ppEnabledExtensionNames: cast[ptr UncheckedArray[cstring]](addr(requiredExtensions)) | |
213 ) | |
214 checkVkResult vkCreateDevice(physicalDevice, addr(deviceCreateInfo), nil, addr(result[0])) | |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
215 vkGetDeviceQueue(result[0], graphicsQueueFamily, 0'u32, addr(result[1])); |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
216 vkGetDeviceQueue(result[0], presentationQueueFamily, 0'u32, addr(result[2])); |
462 | 217 |
463
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
218 proc debugCallback*( |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
219 messageSeverity: VkDebugUtilsMessageSeverityFlagBitsEXT, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
220 messageTypes: VkDebugUtilsMessageTypeFlagsEXT, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
221 pCallbackData: VkDebugUtilsMessengerCallbackDataEXT, |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
222 userData: pointer |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
223 ): VkBool32 {.cdecl.} = |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
224 echo &"{messageSeverity}: {VkDebugUtilsMessageTypeFlagBitsEXT(messageTypes)}: {pCallbackData.pMessage}" |
91544fc1afe5
did: hello world triangle, a bit of code organization
Sam <sam@basx.dev>
parents:
462
diff
changeset
|
225 return VK_FALSE |
466
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
226 |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
227 proc getSurfaceCapabilities*(device: VkPhysicalDevice, surface: VkSurfaceKHR): VkSurfaceCapabilitiesKHR = |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
228 checkVkResult device.vkGetPhysicalDeviceSurfaceCapabilitiesKHR(surface, addr(result)) |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
229 |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
230 when defined(linux): |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
231 proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
232 var surfaceCreateInfo = VkXlibSurfaceCreateInfoKHR( |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
233 sType: VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
234 dpy: window.display, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
235 window: window.window, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
236 ) |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
237 checkVkResult vkCreateXlibSurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
238 when defined(windows): |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
239 proc createVulkanSurface*(instance: VkInstance, window: NativeWindow): VkSurfaceKHR = |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
240 var surfaceCreateInfo = VkWin32SurfaceCreateInfoKHR( |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
241 sType: VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
242 hinstance: window.hinstance, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
243 hwnd: window.hwnd, |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
244 ) |
1dd9e2393a9e
add: structure code for crossplatform, add some input handling + bugfixes
Sam <sam@basx.dev>
parents:
465
diff
changeset
|
245 checkVkResult vkCreateWin32SurfaceKHR(instance, addr(surfaceCreateInfo), nil, addr(result)) |