Mercurial > games > semicongine
diff 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 |
line wrap: on
line diff
--- a/semiconginev2/rendering.nim Sun Jul 21 11:31:11 2024 +0700 +++ b/semiconginev2/rendering.nim Mon Jul 22 00:46:10 2024 +0700 @@ -42,6 +42,8 @@ graphicsQueueFamily*: uint32 graphicsQueue*: VkQueue debugMessenger: VkDebugUtilsMessengerEXT + # populated through the InitSwapchain proc + swapchain*: Swapchain # unclear as of yet anisotropy*: float32 = 0 # needs to be enable during device creation Renderpass* = ref object @@ -80,8 +82,6 @@ var vulkan*: VulkanGlobals var fullscreen: bool -func currentFiF*(swapchain: Swapchain): int = swapchain.currentFiF - type # type aliases 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] @@ -320,7 +320,18 @@ ) vulkan.graphicsQueue = svkGetDeviceQueue(vulkan.device, vulkan.graphicsQueueFamily, VK_QUEUE_GRAPHICS_BIT) +proc ClearSwapchain*() = + assert vulkan.swapchain != nil, "Swapchain has not been initialized yet" + DestroySwapchain(vulkan.swapchain) + vulkan.swapchain = nil + +proc SetupSwapchain*(renderPass: RenderPass, vSync: bool = false) = + assert vulkan.swapchain == nil, "Swapchain has already been initialized yet" + vulkan.swapchain = InitSwapchain(renderPass, vSync = vSync) + proc DestroyVulkan*() = + if vulkan.swapchain != nil: + DestroySwapchain(vulkan.swapchain) vkDestroyDevice(vulkan.device, nil) vkDestroySurfaceKHR(vulkan.instance, vulkan.surface, nil) vkDestroyDebugUtilsMessengerEXT(vulkan.instance, vulkan.debugMessenger, nil) @@ -334,7 +345,13 @@ fullscreen = enable vulkan.window.Fullscreen(fullscreen) -func GetAspectRatio*(swapchain: Swapchain): float32 = swapchain.width.float32 / swapchain.height.float32 +proc GetAspectRatio*(): float32 = + assert vulkan.swapchain != nil, "Swapchain has not been initialized yet" + vulkan.swapchain.width.float32 / vulkan.swapchain.height.float32 + +proc currentFiF*(): int = + assert vulkan.swapchain != nil, "Swapchain has not been initialized yet" + vulkan.swapchain.currentFiF proc MaxFramebufferSampleCount*(maxSamples = VK_SAMPLE_COUNT_8_BIT): VkSampleCountFlagBits = let limits = svkGetPhysicalDeviceProperties().limits