Skip to content

Commit 26a7979

Browse files
committed
vulkan dep
1 parent 7bada9b commit 26a7979

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ apply plugin: 'com.github.johnrengelman.shadow'
3131

3232
dependencies {
3333

34-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
35-
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
34+
ext.kotlin = "org.jetbrains.kotlin:kotlin"
35+
implementation "$kotlin-stdlib:$kotlinVersion"
36+
implementation "$kotlin-reflect:$kotlinVersion"
3637

37-
implementation 'com.github.kotlin-graphics:gln:b6f92bf107aa87046bccb5d35edcccb50e767770'
38+
ext.kx = "com.github.kotlin-graphics"
39+
implementation "$kx:gln:b6f92bf107aa87046bccb5d35edcccb50e767770"
40+
implementation "$kx:vkk:e3791981b95038abf8a4dd1296fbdd7dfaf93279"
3841

3942
testImplementation 'io.kotlintest:kotlintest:2.0.7'
4043
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.0.6'
4144

42-
4345
// ext.jogl = "2.3.2"
4446
// compile "org.jogamp.gluegen:gluegen-rt:$jogl"
4547
// compile "org.jogamp.jogl:jogl-all:$jogl"
@@ -57,9 +59,10 @@ dependencies {
5759
ext.lwjglNatives = "natives-macos"
5860
break
5961
}
60-
["", "-glfw", "-jemalloc", "-openal", "-opengl", "-stb"].each {
62+
["", "-glfw", "-jemalloc", "-openal", "-opengl", "-stb", "-vulkan"].each {
6163
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
62-
runtime "org.lwjgl:lwjgl$it:$lwjglVersion:$lwjglNatives"
64+
if (it != "-vulkan")
65+
runtime "org.lwjgl:lwjgl$it:$lwjglVersion:$lwjglNatives"
6366
}
6467
}
6568

src/main/kotlin/uno/glfw/GlfwWindow.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import org.lwjgl.glfw.GLFW.*
1414
import org.lwjgl.system.MemoryUtil
1515
import org.lwjgl.system.MemoryUtil.memGetDouble
1616
import org.lwjgl.system.MemoryUtil.memGetInt
17+
import org.lwjgl.vulkan.VkInstance
18+
import vkk.appBuffer
1719
import java.nio.ByteBuffer
1820
import java.nio.FloatBuffer
1921

@@ -306,10 +308,16 @@ class GlfwWindow(val handle: Long) {
306308

307309
fun mouseButton(button: Int) = glfwGetMouseButton(handle, button)
308310

311+
fun getJoystickButtons(joystickId: Int): ByteBuffer? = glfwGetJoystickButtons(joystickId)
312+
fun getJoystickAxes(joystickId: Int): FloatBuffer? = glfwGetJoystickAxes(joystickId)
313+
309314
inline fun loop(block: () -> Unit) {
310-
while (isOpen) block()
315+
while (isOpen) {
316+
glfwPollEvents()
317+
block()
318+
appBuffer.reset()
319+
}
311320
}
312321

313-
fun getJoystickButtons(joystickId: Int): ByteBuffer? = glfwGetJoystickButtons(joystickId)
314-
fun getJoystickAxes(joystickId: Int): FloatBuffer? = glfwGetJoystickAxes(joystickId)
322+
infix fun createSurface(instance: VkInstance) = glfw.createWindowSurface(handle, instance)
315323
}

src/main/kotlin/uno/glfw/glfw.kt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
package uno.glfw
22

3+
import glm_.buffer.adr
34
import glm_.vec2.Vec2i
45
import org.lwjgl.glfw.GLFW.*
56
import 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
611
import 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

1222
object 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

Comments
 (0)