11package uno.glfw
22
3+ import glm_.buffer.adr
34import glm_.vec2.Vec2i
45import org.lwjgl.glfw.GLFW.*
56import org.lwjgl.glfw.GLFWErrorCallback
7+ import org.lwjgl.glfw.GLFWVulkan
8+ import org.lwjgl.system.MemoryUtil
9+ import org.lwjgl.system.MemoryUtil.NULL
10+ import org.lwjgl.system.MemoryUtil.memGetLong
611import org.lwjgl.system.Platform
12+ import org.lwjgl.vulkan.VkInstance
13+ import vkk.VK_CHECK_RESULT
14+ import vkk.VkSurfaceKHR
15+ import vkk.adr
16+ import vkk.appBuffer
717
818/* *
919 * Created by elect on 22/04/17.
1020 */
1121
1222object glfw {
1323
24+ @Throws(RuntimeException ::class )
1425 fun init () {
1526
1627 GLFWErrorCallback .createPrint(System .err).set()
1728 if (! glfwInit())
18- throw IllegalStateException (" Unable to initialize GLFW" )
29+ throw RuntimeException (" Unable to initialize GLFW" )
1930
2031 /* This window hint is required to use OpenGL 3.1+ on macOS */
2132 if (Platform .get() == Platform .MACOSX )
2233 windowHint.forwardComp = true
2334 }
2435
36+ val vulkanSupported get() = GLFWVulkan .glfwVulkanSupported()
37+
2538 fun <T > windowHint (block : windowHint.() -> T ) = windowHint.block()
2639
2740 val primaryMonitor get() = glfwGetPrimaryMonitor()
@@ -45,5 +58,24 @@ object glfw {
4558 }
4659
4760 fun pollEvents () = glfwPollEvents()
61+
62+ val requiredInstanceExtensions: ArrayList <String >
63+ get() {
64+ val pCount = appBuffer.intBuffer
65+ val ppNames = GLFWVulkan .nglfwGetRequiredInstanceExtensions(pCount.adr)
66+ val a = GLFWVulkan .glfwGetRequiredInstanceExtensions()
67+ val count = pCount[0 ]
68+ val pNames = MemoryUtil .memPointerBufferSafe(ppNames, count) ? : return arrayListOf ()
69+ val res = ArrayList <String >(count)
70+ for (i in 0 until count)
71+ res + = MemoryUtil .memASCII(pNames[i])
72+ return res
73+ }
74+
75+ fun createWindowSurface (windowHandle : Long , instance : VkInstance ): VkSurfaceKHR {
76+ val pSurface = appBuffer.long
77+ VK_CHECK_RESULT (GLFWVulkan .nglfwCreateWindowSurface(instance.adr, windowHandle, NULL , pSurface))
78+ return memGetLong(pSurface)
79+ }
4880}
4981
0 commit comments