1
1
package uno.glfw
2
2
3
- import ab.appBuffer
3
+ import glm_.BYTES
4
4
import glm_.bool
5
5
import glm_.f
6
6
import glm_.i
@@ -11,6 +11,7 @@ import glm_.vec4.Vec4i
11
11
import gln.debug.GlDebugSeverity
12
12
import gln.debug.GlDebugSource
13
13
import gln.debug.GlDebugType
14
+ import kool.stak
14
15
import org.lwjgl.glfw.*
15
16
import org.lwjgl.glfw.GLFW.*
16
17
import org.lwjgl.opengl.GL
@@ -20,7 +21,6 @@ import org.lwjgl.system.Callback
20
21
import org.lwjgl.system.MemoryStack
21
22
import org.lwjgl.system.MemoryUtil.*
22
23
import org.lwjgl.vulkan.VkInstance
23
- import uno.kotlin.first
24
24
import uno.kotlin.getOrfirst
25
25
import java.nio.ByteBuffer
26
26
import java.nio.FloatBuffer
@@ -129,18 +129,18 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
129
129
fun setSizeLimit (width : IntRange , height : IntRange ) = glfwSetWindowSizeLimits(handle, width.start, height.start, width.endInclusive, height.endInclusive)
130
130
131
131
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
135
135
nglfwGetWindowPos(handle, x, y)
136
136
return field(memGetInt(x), memGetInt(y))
137
137
}
138
138
set(value) = glfwSetWindowPos(handle, value.x, value.y)
139
139
140
140
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
144
144
nglfwGetWindowSize(handle, x, y)
145
145
return field(memGetInt(x), memGetInt(y))
146
146
}
@@ -157,27 +157,27 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
157
157
set(value) = glfwSetWindowAspectRatio(handle, value.x, value.y)
158
158
159
159
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
163
163
nglfwGetFramebufferSize(handle, x, y)
164
164
return field(memGetInt(x), memGetInt(y))
165
165
}
166
166
167
167
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
173
173
nglfwGetWindowFrameSize(handle, x, y, z, w)
174
174
return field(memGetInt(x), memGetInt(y), memGetInt(z), memGetInt(w))
175
175
}
176
176
177
177
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
181
181
nglfwGetWindowContentScale(handle, x, y)
182
182
return field(memGetFloat(x), memGetFloat(y))
183
183
}
@@ -247,9 +247,9 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
247
247
}
248
248
249
249
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
253
253
nglfwGetCursorPos(handle, x, y)
254
254
return field(memGetDouble(x), memGetDouble(y))
255
255
}
@@ -354,7 +354,7 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
354
354
// Event handlers are called by the GLFW callback mechanism and should not be called directly
355
355
//
356
356
357
- open fun onWindowResized (newSize : Vec2i ) = appBuffer.reset()
357
+ open fun onWindowResized (newSize : Vec2i ) {}
358
358
open fun onWindowClosed () {}
359
359
360
360
// Keyboard handling
@@ -413,8 +413,8 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
413
413
val joystick3Buttons: ByteBuffer ?
414
414
get() = getJoystickButtons(GLFW_JOYSTICK_3 )
415
415
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 )
418
418
val result = nglfwGetJoystickButtons(joystickId, count)
419
419
return memByteBufferSafe(result, memGetInt(count))
420
420
}
@@ -426,8 +426,8 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
426
426
val joystick3Axes: FloatBuffer ?
427
427
get() = getJoystickAxes(GLFW_JOYSTICK_3 )
428
428
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 )
431
431
val result = nglfwGetJoystickAxes(joystickId, count)
432
432
return memFloatBufferSafe(result, memGetInt(count))
433
433
}
@@ -445,16 +445,15 @@ open class GlfwWindow(var handle: GlfwWindowHandle) {
445
445
inline fun loop (condition : () -> Boolean , block : (MemoryStack ) -> Unit ) {
446
446
while (condition()) {
447
447
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
+ }
454
453
}
455
454
}
456
455
457
- infix fun createSurface (instance : VkInstance ) = glfw.createWindowSurface(handle, instance)
456
+ // infix fun createSurface(instance: VkInstance) = glfw.createWindowSurface(handle, instance)
458
457
459
458
fun swapBuffers () = glfwSwapBuffers(handle)
460
459
inline fun present () = swapBuffers()
0 commit comments