diff semiconginev2/rendering.nim @ 1226:c8e3037aca66 compiletime-tests

add: contrib stuff
author sam <sam@basx.dev>
date Wed, 17 Jul 2024 23:41:51 +0700
parents a3fa15c25026
children 4e465583ea32
line wrap: on
line diff
--- a/semiconginev2/rendering.nim	Wed Jul 17 22:20:59 2024 +0700
+++ b/semiconginev2/rendering.nim	Wed Jul 17 23:41:51 2024 +0700
@@ -68,6 +68,7 @@
     oldSwapchainCounter: int # swaps until old swapchain will be destroyed
 
 var vulkan*: VulkanGlobals
+var fullscreen: bool
 
 func currentFiF*(swapchain: Swapchain): int = swapchain.currentFiF
 
@@ -311,3 +312,33 @@
   vkDestroySurfaceKHR(vulkan.instance, vulkan.surface, nil)
   vkDestroyDebugUtilsMessengerEXT(vulkan.instance, vulkan.debugMessenger, nil)
   vkDestroyInstance(vulkan.instance, nil)
+
+proc ShowSystemCursor*() = vulkan.window.ShowSystemCursor()
+proc HideSystemCursor*() = vulkan.window.HideSystemCursor()
+proc Fullscreen*(): bool = fullscreen
+proc `Fullscreen=`*(enable: bool) =
+  if enable != fullscreen:
+    fullscreen = enable
+    vulkan.window.Fullscreen(fullscreen)
+
+func GetAspectRatio*(swapchain: Swapchain): float32 = swapchain.width.float32 / swapchain.height.float32
+
+proc MaxFramebufferSampleCount*(maxSamples = VK_SAMPLE_COUNT_8_BIT): VkSampleCountFlagBits =
+  let limits = svkGetPhysicalDeviceProperties().limits
+  let available = VkSampleCountFlags(
+    limits.framebufferColorSampleCounts.uint32 and limits.framebufferDepthSampleCounts.uint32
+  ).toEnums
+  return min(max(available), maxSamples)
+
+
+proc `[]`*(texture: Texture, x, y: uint32): auto =
+  assert x < texture.width, &"{x} < {texture.width} is not true"
+  assert y < texture.height, &"{y} < {texture.height} is not true"
+
+  texture[].imagedata[y * texture.width + x]
+
+proc `[]=`*[T](texture: var Texture[T], x, y: uint32, value: T) =
+  assert x < texture.width
+  assert y < texture.height
+
+  texture[].imagedata[y * texture.width + x] = value