11package uno.glfw
22
3- import ab.appBuffer
3+ import glm_.BYTES
44import glm_.bool
55import glm_.f
66import glm_.i
@@ -11,6 +11,7 @@ import glm_.vec4.Vec4i
1111import gln.debug.GlDebugSeverity
1212import gln.debug.GlDebugSource
1313import gln.debug.GlDebugType
14+ import kool.stak
1415import org.lwjgl.glfw.*
1516import org.lwjgl.glfw.GLFW.*
1617import org.lwjgl.opengl.GL
@@ -20,7 +21,6 @@ import org.lwjgl.system.Callback
2021import org.lwjgl.system.MemoryStack
2122import org.lwjgl.system.MemoryUtil.*
2223import org.lwjgl.vulkan.VkInstance
23- import uno.kotlin.first
2424import uno.kotlin.getOrfirst
2525import java.nio.ByteBuffer
2626import java.nio.FloatBuffer
@@ -129,18 +129,18 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
129129 fun setSizeLimit (width : IntRange , height : IntRange ) = glfwSetWindowSizeLimits(handle, width.start, height.start, width.endInclusive, height.endInclusive)
130130
131131 var pos = Vec2i ()
132- get() {
133- val x = appBuffer.int
134- val y = appBuffer.int
132+ get() = stak {
133+ val x = it.nmalloc( Int . BYTES * 2 )
134+ val y = x + Int . BYTES
135135 nglfwGetWindowPos(handle, x, y)
136136 return field(memGetInt(x), memGetInt(y))
137137 }
138138 set(value) = glfwSetWindowPos(handle, value.x, value.y)
139139
140140 var size = Vec2i ()
141- get() {
142- val x = appBuffer.int
143- val y = appBuffer.int
141+ get() = stak {
142+ val x = it.nmalloc( Int . BYTES * 2 )
143+ val y = x + Int . BYTES
144144 nglfwGetWindowSize(handle, x, y)
145145 return field(memGetInt(x), memGetInt(y))
146146 }
@@ -157,27 +157,27 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
157157 set(value) = glfwSetWindowAspectRatio(handle, value.x, value.y)
158158
159159 val framebufferSize = Vec2i ()
160- get() {
161- val x = appBuffer.int
162- val y = appBuffer.int
160+ get() = stak {
161+ val x = it.nmalloc( Int . BYTES * 2 )
162+ val y = x + Int . BYTES
163163 nglfwGetFramebufferSize(handle, x, y)
164164 return field(memGetInt(x), memGetInt(y))
165165 }
166166
167167 val frameSize = Vec4i ()
168- get() {
169- val x = appBuffer.int
170- val y = appBuffer.int
171- val z = appBuffer.int
172- val w = appBuffer.int
168+ get() = stak {
169+ val x = it.nmalloc( Int . BYTES * 4 )
170+ val y = x + Int . BYTES
171+ val z = y + Int . BYTES
172+ val w = z + Int . BYTES
173173 nglfwGetWindowFrameSize(handle, x, y, z, w)
174174 return field(memGetInt(x), memGetInt(y), memGetInt(z), memGetInt(w))
175175 }
176176
177177 val contentScale = Vec2 ()
178- get() {
179- val x = appBuffer.float
180- val y = appBuffer.float
178+ get() = stak {
179+ val x = it.nmalloc( Float . BYTES * 2 )
180+ val y = x + Float . BYTES
181181 nglfwGetWindowContentScale(handle, x, y)
182182 return field(memGetFloat(x), memGetFloat(y))
183183 }
@@ -247,9 +247,9 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
247247 }
248248
249249 var cursorPos = Vec2d ()
250- get() {
251- val x = appBuffer.double
252- val y = appBuffer.double
250+ get() = stak {
251+ val x = it.nmalloc( Double . BYTES * 2 )
252+ val y = x + Double . BYTES
253253 nglfwGetCursorPos(handle, x, y)
254254 return field(memGetDouble(x), memGetDouble(y))
255255 }
@@ -354,7 +354,7 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
354354 // Event handlers are called by the GLFW callback mechanism and should not be called directly
355355 //
356356
357- open fun onWindowResized (newSize : Vec2i ) = appBuffer.reset()
357+ open fun onWindowResized (newSize : Vec2i ) {}
358358 open fun onWindowClosed () {}
359359
360360 // Keyboard handling
@@ -413,8 +413,8 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
413413 val joystick3Buttons: ByteBuffer ?
414414 get() = getJoystickButtons(GLFW_JOYSTICK_3 )
415415
416- fun getJoystickButtons (joystickId : Int ): ByteBuffer ? {
417- val count = appBuffer.int
416+ fun getJoystickButtons (joystickId : Int ): ByteBuffer ? = stak {
417+ val count = it.nmalloc( Int . BYTES )
418418 val result = nglfwGetJoystickButtons(joystickId, count)
419419 return memByteBufferSafe(result, memGetInt(count))
420420 }
@@ -426,8 +426,8 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
426426 val joystick3Axes: FloatBuffer ?
427427 get() = getJoystickAxes(GLFW_JOYSTICK_3 )
428428
429- fun getJoystickAxes (joystickId : Int ): FloatBuffer ? {
430- val count = appBuffer.int
429+ fun getJoystickAxes (joystickId : Int ): FloatBuffer ? = stak {
430+ val count = it.nmalloc( Int . BYTES )
431431 val result = nglfwGetJoystickAxes(joystickId, count)
432432 return memFloatBufferSafe(result, memGetInt(count))
433433 }
@@ -445,16 +445,15 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
445445 inline fun loop (condition : () -> Boolean , block : (MemoryStack ) -> Unit ) {
446446 while (condition()) {
447447 glfwPollEvents()
448- val stack = MemoryStack .stackGet()
449- block(stack.push())
450- if (autoSwap)
451- glfwSwapBuffers(handle)
452- stack.pop()
453- appBuffer.reset() // TODO delete
448+ stak {
449+ block(it)
450+ if (autoSwap)
451+ glfwSwapBuffers(handle)
452+ }
454453 }
455454 }
456455
457- infix fun createSurface (instance : VkInstance ) = glfw.createWindowSurface(handle, instance)
456+ // infix fun createSurface(instance: VkInstance) = glfw.createWindowSurface(handle, instance)
458457
459458 fun swapBuffers () = glfwSwapBuffers(handle)
460459 inline fun present () = swapBuffers()
0 commit comments