comparison semiconginev2/rendering.nim @ 1239:69489a678141

add: better syncing, better swapchain access, correct font offset, two font-rendering tests
author sam <sam@basx.dev>
date Mon, 22 Jul 2024 00:46:10 +0700
parents 841e12f33c47
children 42eeb59f3a43
comparison
equal deleted inserted replaced
1238:03634915bbdb 1239:69489a678141
40 surface: VkSurfaceKHR 40 surface: VkSurfaceKHR
41 window: NativeWindow 41 window: NativeWindow
42 graphicsQueueFamily*: uint32 42 graphicsQueueFamily*: uint32
43 graphicsQueue*: VkQueue 43 graphicsQueue*: VkQueue
44 debugMessenger: VkDebugUtilsMessengerEXT 44 debugMessenger: VkDebugUtilsMessengerEXT
45 # populated through the InitSwapchain proc
46 swapchain*: Swapchain
45 # unclear as of yet 47 # unclear as of yet
46 anisotropy*: float32 = 0 # needs to be enable during device creation 48 anisotropy*: float32 = 0 # needs to be enable during device creation
47 Renderpass* = ref object 49 Renderpass* = ref object
48 vk*: VkRenderPass 50 vk*: VkRenderPass
49 samples*: VkSampleCountFlagBits 51 samples*: VkSampleCountFlagBits
77 oldSwapchain: Swapchain 79 oldSwapchain: Swapchain
78 oldSwapchainCounter: int # swaps until old swapchain will be destroyed 80 oldSwapchainCounter: int # swaps until old swapchain will be destroyed
79 81
80 var vulkan*: VulkanGlobals 82 var vulkan*: VulkanGlobals
81 var fullscreen: bool 83 var fullscreen: bool
82
83 func currentFiF*(swapchain: Swapchain): int = swapchain.currentFiF
84 84
85 type 85 type
86 # type aliases 86 # type aliases
87 SupportedGPUType = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64] 87 SupportedGPUType = float32 | float64 | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | TVec2[int32] | TVec2[int64] | TVec3[int32] | TVec3[int64] | TVec4[int32] | TVec4[int64] | TVec2[uint32] | TVec2[uint64] | TVec3[uint32] | TVec3[uint64] | TVec4[uint32] | TVec4[uint64] | TVec2[float32] | TVec2[float64] | TVec3[float32] | TVec3[float64] | TVec4[float32] | TVec4[float64] | TMat2[float32] | TMat2[float64] | TMat23[float32] | TMat23[float64] | TMat32[float32] | TMat32[float64] | TMat3[float32] | TMat3[float64] | TMat34[float32] | TMat34[float64] | TMat43[float32] | TMat43[float64] | TMat4[float32] | TMat4[float64]
88 Gray = TVec1[uint8] 88 Gray = TVec1[uint8]
318 pAllocator = nil, 318 pAllocator = nil,
319 pDevice = addr vulkan.device 319 pDevice = addr vulkan.device
320 ) 320 )
321 vulkan.graphicsQueue = svkGetDeviceQueue(vulkan.device, vulkan.graphicsQueueFamily, VK_QUEUE_GRAPHICS_BIT) 321 vulkan.graphicsQueue = svkGetDeviceQueue(vulkan.device, vulkan.graphicsQueueFamily, VK_QUEUE_GRAPHICS_BIT)
322 322
323 proc ClearSwapchain*() =
324 assert vulkan.swapchain != nil, "Swapchain has not been initialized yet"
325 DestroySwapchain(vulkan.swapchain)
326 vulkan.swapchain = nil
327
328 proc SetupSwapchain*(renderPass: RenderPass, vSync: bool = false) =
329 assert vulkan.swapchain == nil, "Swapchain has already been initialized yet"
330 vulkan.swapchain = InitSwapchain(renderPass, vSync = vSync)
331
323 proc DestroyVulkan*() = 332 proc DestroyVulkan*() =
333 if vulkan.swapchain != nil:
334 DestroySwapchain(vulkan.swapchain)
324 vkDestroyDevice(vulkan.device, nil) 335 vkDestroyDevice(vulkan.device, nil)
325 vkDestroySurfaceKHR(vulkan.instance, vulkan.surface, nil) 336 vkDestroySurfaceKHR(vulkan.instance, vulkan.surface, nil)
326 vkDestroyDebugUtilsMessengerEXT(vulkan.instance, vulkan.debugMessenger, nil) 337 vkDestroyDebugUtilsMessengerEXT(vulkan.instance, vulkan.debugMessenger, nil)
327 vkDestroyInstance(vulkan.instance, nil) 338 vkDestroyInstance(vulkan.instance, nil)
328 339
332 proc `Fullscreen=`*(enable: bool) = 343 proc `Fullscreen=`*(enable: bool) =
333 if enable != fullscreen: 344 if enable != fullscreen:
334 fullscreen = enable 345 fullscreen = enable
335 vulkan.window.Fullscreen(fullscreen) 346 vulkan.window.Fullscreen(fullscreen)
336 347
337 func GetAspectRatio*(swapchain: Swapchain): float32 = swapchain.width.float32 / swapchain.height.float32 348 proc GetAspectRatio*(): float32 =
349 assert vulkan.swapchain != nil, "Swapchain has not been initialized yet"
350 vulkan.swapchain.width.float32 / vulkan.swapchain.height.float32
351
352 proc currentFiF*(): int =
353 assert vulkan.swapchain != nil, "Swapchain has not been initialized yet"
354 vulkan.swapchain.currentFiF
338 355
339 proc MaxFramebufferSampleCount*(maxSamples = VK_SAMPLE_COUNT_8_BIT): VkSampleCountFlagBits = 356 proc MaxFramebufferSampleCount*(maxSamples = VK_SAMPLE_COUNT_8_BIT): VkSampleCountFlagBits =
340 let limits = svkGetPhysicalDeviceProperties().limits 357 let limits = svkGetPhysicalDeviceProperties().limits
341 let available = VkSampleCountFlags( 358 let available = VkSampleCountFlags(
342 limits.framebufferColorSampleCounts.uint32 and limits.framebufferDepthSampleCounts.uint32 359 limits.framebufferColorSampleCounts.uint32 and limits.framebufferDepthSampleCounts.uint32