diff --git a/build.gradle b/build.gradle
index 700731d..ed22fd9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,8 +4,8 @@ plugins {
id 'maven'
id 'java'
id 'java-library'
- id "org.jetbrains.kotlin.jvm" version "1.3.11"
- id "com.github.johnrengelman.shadow" version '4.0.3'
+ id "org.jetbrains.kotlin.jvm" version "1.3.21"
+ id "com.github.johnrengelman.shadow" version '4.0.4'
}
// jitpack
@@ -14,10 +14,10 @@ group = 'com.github.kotlin-graphics'
ext{
moduleName = 'com.github.kotlin_graphics.openvr'
kotlin = 'org.jetbrains.kotlin:kotlin'
- kotlin_version = '1.3.11'
- kotlintest_version = '3.1.11'
+ kotlin_version = '1.3.21'
+ kotlintest_version = '3.2.1'
uno_version = 'd04fa5dcb3735347e11cd3480615e574b1ffaa0b'
- lwjgl_version = "3.2.1"
+ lwjgl_version = "3.2.2-SNAPSHOT"
lwjgl_natives = current() == WINDOWS ? "windows" : current() == LINUX ? "linux" : "macos"
}
@@ -28,19 +28,13 @@ dependencies {
testImplementation "io.kotlintest:kotlintest-runner-junit5:$kotlintest_version"
ext.kx = "com.github.kotlin-graphics"
- implementation "$kx:uno-sdk:24550988e24b8fc99428e599b62f2e81a6f0b334"
+ implementation "$kx:uno-sdk:60edf33067835253aa30ac79bd5129363fee953f"
["", "-glfw", "-jemalloc", "-openal", "-opengl", "-stb", "-openvr", "-vulkan"].each {
implementation "org.lwjgl:lwjgl$it:$lwjgl_version"
if (it != "-vulkan")
runtime "org.lwjgl:lwjgl$it:$lwjgl_version:natives-$lwjgl_natives"
}
-
- constraints {
- testImplementation("$kotlin-stdlib:$kotlin_version")
- testImplementation("$kotlin-stdlib-jdk7:$kotlin_version")
- testImplementation("$kotlin-reflect:$kotlin_version")
- }
}
repositories {
@@ -50,12 +44,12 @@ repositories {
}
task sourcesJar(type: Jar, dependsOn: classes) {
- classifier = 'sources'
+ archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
+ archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
@@ -74,4 +68,6 @@ test.useJUnitPlatform()
// outputs.upToDateWhen { false }
// showStandardStreams = true
// }
-//}
\ No newline at end of file
+//}
+
+shadowJar.archiveClassifier = 'all'
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index c071d6a..e1d4a5a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
diff --git a/src/main/kotlin/openvr/lib/ivrApplications.kt b/src/main/kotlin/openvr/lib/ivrApplications.kt
index 0bd9769..ee88c24 100644
--- a/src/main/kotlin/openvr/lib/ivrApplications.kt
+++ b/src/main/kotlin/openvr/lib/ivrApplications.kt
@@ -1,10 +1,10 @@
package openvr.lib
import kool.*
+import kool.lib.toByteArray
import org.lwjgl.openvr.AppOverrideKeys
import org.lwjgl.openvr.OpenVR.IVRApplications
import org.lwjgl.openvr.VRApplications.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.*
import java.nio.ByteBuffer
@@ -130,7 +130,7 @@ object vrApplications : vrInterface {
* @param temporary
*/
fun addApplicationManifest(applicationManifestFullPath: String, temporary: Boolean = false): Error =
- Error of nVRApplications_AddApplicationManifest(addressOfAscii(applicationManifestFullPath), temporary)
+ stak { Error of nVRApplications_AddApplicationManifest(it.addressOfAscii(applicationManifestFullPath), temporary) }
/**
* Removes an application manifest from the list to load when building the list of installed applications.
@@ -138,7 +138,7 @@ object vrApplications : vrInterface {
* @param applicationManifestFullPath
*/
infix fun removeApplicationManifest(applicationManifestFullPath: String): Error =
- Error of nVRApplications_RemoveApplicationManifest(addressOfAscii(applicationManifestFullPath))
+ stak { Error of nVRApplications_RemoveApplicationManifest(it.addressOfAscii(applicationManifestFullPath)) }
/**
* Returns true if an application is installed.
@@ -146,7 +146,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun isApplicationInstalled(appKey: String): Boolean =
- nVRApplications_IsApplicationInstalled(addressOfAscii(appKey))
+ stak { nVRApplications_IsApplicationInstalled(it.addressOfAscii(appKey)) }
/** Returns the number of applications available in the list. */
val applicationCount: Int
@@ -163,9 +163,11 @@ object vrApplications : vrInterface {
* @param appKeyBuffer
*/
@JvmOverloads
- fun getApplicationKeyByIndex(applicationIndex: Int, pErr: VRApplicationErrorBuffer = pError): ByteBuffer =
- stackGet().malloc(maxKeyLength).apply {
- pErr[0] = nVRApplications_GetApplicationKeyByIndex(applicationIndex, adr, maxKeyLength)
+ fun getApplicationKeyByIndex(applicationIndex: Int, pErr: VRApplicationErrorBuffer = pError): ByteArray =
+ stak {
+ val buf = it.malloc(maxKeyLength)
+ pErr[0] = nVRApplications_GetApplicationKeyByIndex(applicationIndex, buf.adr, maxKeyLength)
+ buf.toByteArray()
}
/**
@@ -179,9 +181,11 @@ object vrApplications : vrInterface {
* @param appKeyBuffer
*/
@JvmOverloads
- fun getApplicationKeyByProcessId(processId: Int, pErr: VRApplicationErrorBuffer = pError): ByteBuffer =
- stackGet().malloc(maxKeyLength).apply {
- pErr[0] = nVRApplications_GetApplicationKeyByProcessId(processId, adr, maxKeyLength)
+ fun getApplicationKeyByProcessId(processId: Int, pErr: VRApplicationErrorBuffer = pError): ByteArray =
+ stak {
+ val buf = it.malloc(maxKeyLength)
+ pErr[0] = nVRApplications_GetApplicationKeyByProcessId(processId, buf.adr, maxKeyLength)
+ buf.toByteArray()
}
/**
@@ -192,7 +196,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun launchApplication(appKey: String): Error =
- Error of nVRApplications_LaunchApplication(addressOfAscii(appKey))
+ stak { Error of nVRApplications_LaunchApplication(it.addressOfAscii(appKey)) }
/**
* Launches an instance of an application of type template, with its app key being {@code newAppKey} (which must be unique) and optionally override
@@ -203,7 +207,7 @@ object vrApplications : vrInterface {
* @param keys
*/
fun launchTemplateApplication(templateAppKey: String, newAppKey: String, keys: AppOverrideKeys.Buffer): Error =
- Error of nVRApplications_LaunchTemplateApplication(addressOfAscii(templateAppKey), addressOfAscii(newAppKey), keys.adr, keys.rem)
+ stak { Error of nVRApplications_LaunchTemplateApplication(it.addressOfAscii(templateAppKey), it.addressOfAscii(newAppKey), keys.adr, keys.rem) }
/**
* Launches the application currently associated with this mime type and passes it the option args, typically the filename or object name of the item
@@ -213,7 +217,7 @@ object vrApplications : vrInterface {
* @param args
*/
fun launchApplicationFromMimeType(mimeType: String, args: String): Error =
- Error of nVRApplications_LaunchApplicationFromMimeType(addressOfAscii(mimeType), addressOfAscii(args))
+ stak { Error of nVRApplications_LaunchApplicationFromMimeType(it.addressOfAscii(mimeType), it.addressOfAscii(args)) }
/**
* Launches the dashboard overlay application if it is not already running. This call is only valid for dashboard overlay applications.
@@ -221,7 +225,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun launchDashboardOverlay(appKey: String): Error =
- Error of nVRApplications_LaunchDashboardOverlay(addressOfAscii(appKey))
+ stak { Error of nVRApplications_LaunchDashboardOverlay(it.addressOfAscii(appKey)) }
/**
* Cancel a pending launch for an application.
@@ -229,7 +233,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun cancelApplicationLaunch(appKey: String): Boolean =
- nVRApplications_CancelApplicationLaunch(addressOfAscii(appKey))
+ stak { nVRApplications_CancelApplicationLaunch(it.addressOfAscii(appKey)) }
/**
* Identifies a running application. OpenVR can't always tell which process started in response to a URL. This function allows a URL handler (or the
@@ -240,7 +244,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
fun identifyApplication(processId: Int, appKey: String): Error =
- Error of nVRApplications_IdentifyApplication(processId, addressOfAscii(appKey))
+ stak { Error of nVRApplications_IdentifyApplication(processId, it.addressOfAscii(appKey)) }
/**
* Returns the process ID for an application. Return 0 if the application was not found or is not running.
@@ -248,7 +252,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun getApplicationProcessId(appKey: String): Int =
- nVRApplications_GetApplicationProcessId(addressOfAscii(appKey))
+ stak { nVRApplications_GetApplicationProcessId(it.addressOfAscii(appKey)) }
/**
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -280,12 +284,13 @@ object vrApplications : vrInterface {
* @param error
*/
@JvmOverloads
- fun getApplicationPropertyString(appKey: String, property: Property, propertyValueBufferLen: Int = vr.maxPropertyStringSize, error: VRApplicationErrorBuffer = pError): String = stackGet().run {
- val appKeyEncoded = addressOfAscii(appKey)
- val propertyValueBuffer = malloc(propertyValueBufferLen)
- val result = nVRApplications_GetApplicationPropertyString(appKeyEncoded, property.i, propertyValueBuffer.adr, propertyValueBufferLen, error.adr)
- memASCII(propertyValueBuffer, result - 1)
- }
+ fun getApplicationPropertyString(appKey: String, property: Property, propertyValueBufferLen: Int = vr.maxPropertyStringSize, error: VRApplicationErrorBuffer = pError): String =
+ stak {
+ val appKeyEncoded = it.addressOfAscii(appKey)
+ val propertyValueBuffer = it.malloc(propertyValueBufferLen)
+ val result = nVRApplications_GetApplicationPropertyString(appKeyEncoded, property.i, propertyValueBuffer.adr, propertyValueBufferLen, error.adr)
+ memASCII(propertyValueBuffer, result - 1)
+ }
/**
* Returns a bool value for an application property. Returns false in all error cases.
@@ -298,7 +303,7 @@ object vrApplications : vrInterface {
*/
@JvmOverloads
fun getApplicationPropertyBool(appKey: String, property: Property, error: VRApplicationErrorBuffer = pError): Boolean =
- nVRApplications_GetApplicationPropertyBool(addressOfAscii(appKey), property.i, error.adr)
+ stak { nVRApplications_GetApplicationPropertyBool(it.addressOfAscii(appKey), property.i, error.adr) }
/**
* Returns a uint64 value for an application property. Returns 0 in all error cases.
@@ -311,7 +316,7 @@ object vrApplications : vrInterface {
*/
@JvmOverloads
fun getApplicationPropertyLong(appKey: String, property: Property, error: VRApplicationErrorBuffer = pError): Long =
- nVRApplications_GetApplicationPropertyUint64(addressOfAscii(appKey), property.i, error.adr)
+ stak { nVRApplications_GetApplicationPropertyUint64(it.addressOfAscii(appKey), property.i, error.adr) }
/**
* Sets the application auto-launch flag. This is only valid for applications which return true for
@@ -321,7 +326,7 @@ object vrApplications : vrInterface {
* @param autoLaunch
*/
fun setApplicationAutoLaunch(appKey: String, autoLaunch: Boolean): Error =
- Error of nVRApplications_SetApplicationAutoLaunch(addressOfAscii(appKey), autoLaunch)
+ stak { Error of nVRApplications_SetApplicationAutoLaunch(it.addressOfAscii(appKey), autoLaunch) }
/**
* Gets the application auto-launch flag. This is only valid for applications which return true for
@@ -330,7 +335,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun getApplicationAutoLaunch(appKey: String): Boolean =
- nVRApplications_GetApplicationAutoLaunch(addressOfAscii(appKey))
+ stak { nVRApplications_GetApplicationAutoLaunch(it.addressOfAscii(appKey)) }
/**
* Adds this mime-type to the list of supported mime types for this application.
@@ -339,7 +344,7 @@ object vrApplications : vrInterface {
* @param mimeType
*/
fun setDefaultApplicationForMimeType(appKey: String, mimeType: String): Error =
- Error of nVRApplications_SetDefaultApplicationForMimeType(addressOfAscii(appKey), addressOfAscii(mimeType))
+ stak { Error of nVRApplications_SetDefaultApplicationForMimeType(it.addressOfAscii(appKey), it.addressOfAscii(mimeType)) }
/**
* Return the app key that will open this mime type. TODO offer a more convenient one?
@@ -348,8 +353,8 @@ object vrApplications : vrInterface {
* @param appKeyBuffer
*/
fun getDefaultApplicationForMimeType(mimeType: String, appKeyBuffer: ByteBuffer?): Boolean =
- nVRApplications_GetDefaultApplicationForMimeType(addressOfAscii(mimeType), appKeyBuffer?.adr
- ?: NULL, appKeyBuffer?.cap ?: 0)
+ stak { nVRApplications_GetDefaultApplicationForMimeType(it.addressOfAscii(mimeType), appKeyBuffer?.adr
+ ?: NULL, appKeyBuffer?.cap ?: 0) }
/**
* Get the list of supported mime types for this application, comma-delimited. TODO offer a more convenient one?
@@ -358,8 +363,8 @@ object vrApplications : vrInterface {
* @param mimeTypesBuffer
*/
fun getApplicationSupportedMimeTypes(appKey: String, mimeTypesBuffer: ByteBuffer?): Boolean =
- nVRApplications_GetApplicationSupportedMimeTypes(addressOfAscii(appKey), mimeTypesBuffer?.adr
- ?: NULL, mimeTypesBuffer?.rem ?: 0)
+ stak { nVRApplications_GetApplicationSupportedMimeTypes(it.addressOfAscii(appKey), mimeTypesBuffer?.adr
+ ?: NULL, mimeTypesBuffer?.rem ?: 0) }
/**
* Get the list of app-keys that support this mime type, comma-delimited, the return value is number of bytes you need to return the full string.
@@ -367,11 +372,13 @@ object vrApplications : vrInterface {
* @param mimeType
* @param appKeysThatSupportBufferSize
*/
- fun getApplicationsThatSupportMimeType(mimeType: String, appKeysThatSupportBufferSize: Int): String {
- val appKeysThatSupportBuffer = stackGet().malloc(appKeysThatSupportBufferSize)
- val result = nVRApplications_GetApplicationsThatSupportMimeType(addressOfAscii(mimeType), appKeysThatSupportBuffer.adr, appKeysThatSupportBufferSize)
- return memASCII(appKeysThatSupportBuffer, result - 1)
- }
+ fun getApplicationsThatSupportMimeType(mimeType: String, appKeysThatSupportBufferSize: Int): String =
+ stak {
+ val appKeysThatSupportBuffer = it.malloc(appKeysThatSupportBufferSize)
+ val pMimeType = it.addressOfAscii(mimeType)
+ val result = nVRApplications_GetApplicationsThatSupportMimeType(pMimeType, appKeysThatSupportBuffer.adr, appKeysThatSupportBufferSize)
+ memASCII(appKeysThatSupportBuffer, result - 1)
+ }
/**
* Get the args list from an app launch that had the process already running, you call this when you get a {@link VR#EVREventType_VREvent_ApplicationMimeTypeLoad}.
@@ -379,11 +386,12 @@ object vrApplications : vrInterface {
* @param handle
* @param argsSize
*/
- fun getApplicationLaunchArguments(handle: Int, argsSize: Int): String {
- val args = stackGet().malloc(argsSize)
- val result = nVRApplications_GetApplicationLaunchArguments(handle, args.adr, argsSize)
- return memASCII(args, result - 1)
- }
+ fun getApplicationLaunchArguments(handle: Int, argsSize: Int): String =
+ stak {
+ val args = it.malloc(argsSize)
+ val result = nVRApplications_GetApplicationLaunchArguments(handle, args.adr, argsSize)
+ memASCII(args, result - 1)
+ }
/**
* Returns the app key for the application that is starting up.
@@ -414,7 +422,7 @@ object vrApplications : vrInterface {
* @param appKey
*/
infix fun performApplicationPrelaunchCheck(appKey: String): Error =
- Error of nVRApplications_PerformApplicationPrelaunchCheck(addressOfAscii(appKey))
+ stak { Error of nVRApplications_PerformApplicationPrelaunchCheck(it.addressOfAscii(appKey)) }
/**
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -441,7 +449,7 @@ object vrApplications : vrInterface {
* @param workingDirectory
*/
fun launchInternalProcess(binaryPath: String, arguments: String, workingDirectory: String): Error =
- Error of nVRApplications_LaunchInternalProcess(addressOfAscii(binaryPath), addressOfAscii(arguments), addressOfAscii(workingDirectory))
+ stak { Error of nVRApplications_LaunchInternalProcess(it.addressOfAscii(binaryPath), it.addressOfAscii(arguments), it.addressOfAscii(workingDirectory)) }
/**
* Returns the current scene process ID according to the application system. A scene process will get scene focus once it starts rendering, but it will
diff --git a/src/main/kotlin/openvr/lib/ivrChaperone.kt b/src/main/kotlin/openvr/lib/ivrChaperone.kt
index 1280046..157df47 100644
--- a/src/main/kotlin/openvr/lib/ivrChaperone.kt
+++ b/src/main/kotlin/openvr/lib/ivrChaperone.kt
@@ -2,11 +2,11 @@ package openvr.lib
import glm_.BYTES
import glm_.vec2.Vec2i
+import kool.stak
import org.lwjgl.openvr.HmdColor
import org.lwjgl.openvr.HmdQuad
import org.lwjgl.openvr.VRChaperone
import org.lwjgl.openvr.VRChaperone.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.memGetInt
@@ -53,13 +53,14 @@ object vrChaperone : vrInterface {
*
* @param size
*/
- infix fun getPlayAreaSize(size: Vec2i): Boolean {
- val x = stackGet().nmalloc(1, Vec2i.size)
- val y = x + Int.BYTES
- return nVRChaperone_GetPlayAreaSize(x, y).also {
- size.put(memGetInt(x), memGetInt(y))
- }
- }
+ infix fun getPlayAreaSize(size: Vec2i): Boolean =
+ stak {
+ val x = it.nmalloc(1, Vec2i.size)
+ val y = x + Int.BYTES
+ nVRChaperone_GetPlayAreaSize(x, y).also {
+ size.put(memGetInt(x), memGetInt(y))
+ }
+ }
/**
* Returns the 4 corner positions of the Play Area (formerly named Soft Bounds).
@@ -70,7 +71,7 @@ object vrChaperone : vrInterface {
* @param rect
*/
infix fun getPlayAreaRect(rect: HmdQuad): Boolean =
- nVRChaperone_GetPlayAreaRect(rect.adr)
+ nVRChaperone_GetPlayAreaRect(rect.adr)
/** Reload Chaperone data from the .vrchap file on disk. */
fun reloadInfo() = VRChaperone_ReloadInfo()
@@ -90,7 +91,7 @@ object vrChaperone : vrInterface {
* @param outputCameraColor
*/
fun getBoundsColor(outputColorArray: HmdColor.Buffer, collisionBoundsFadeDistance: Float, outputCameraColor: HmdColor) =
- nVRChaperone_GetBoundsColor(outputColorArray.adr, outputColorArray.rem, collisionBoundsFadeDistance, outputCameraColor.adr)
+ nVRChaperone_GetBoundsColor(outputColorArray.adr, outputColorArray.rem, collisionBoundsFadeDistance, outputCameraColor.adr)
/** Determine whether the bounds are showing right now. */
val areBoundsVisible: Boolean
diff --git a/src/main/kotlin/openvr/lib/ivrChaperoneSetup.kt b/src/main/kotlin/openvr/lib/ivrChaperoneSetup.kt
index 5d7350e..33a703f 100644
--- a/src/main/kotlin/openvr/lib/ivrChaperoneSetup.kt
+++ b/src/main/kotlin/openvr/lib/ivrChaperoneSetup.kt
@@ -5,11 +5,11 @@ import glm_.mat4x4.Mat4
import glm_.vec2.Vec2
import kool.adr
import kool.rem
+import kool.stak
import org.lwjgl.openvr.HmdQuad
import org.lwjgl.openvr.HmdVector2
import org.lwjgl.openvr.VRChaperoneSetup
import org.lwjgl.openvr.VRChaperoneSetup.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.NULL
import org.lwjgl.system.MemoryUtil.memGetFloat
import java.nio.ByteBuffer
@@ -59,13 +59,14 @@ object vrChaperoneSetup : vrInterface {
*
* @param size
*/
- infix fun getWorkingPlayAreaSize(size: Vec2): Boolean {
- val x = stackGet().nmalloc(1, Vec2.size)
- val y = x + Int.BYTES
- return nVRChaperoneSetup_GetWorkingPlayAreaSize(x, x + Int.BYTES).also {
- size(memGetFloat(x), memGetFloat(y))
- }
- }
+ infix fun getWorkingPlayAreaSize(size: Vec2): Boolean =
+ stak {
+ val x = it.nmalloc(1, Vec2.size)
+ val y = x + Int.BYTES
+ nVRChaperoneSetup_GetWorkingPlayAreaSize(x, y).also {
+ size(memGetFloat(x), memGetFloat(y))
+ }
+ }
/**
* Returns the 4 corner positions of the Play Area (formerly named Soft Bounds) from the working copy.
@@ -93,7 +94,7 @@ object vrChaperoneSetup : vrInterface {
* @param quadsCount
*/
fun getLiveCollisionBoundsInfo(quadsBuffer: HmdQuad.Buffer?, quadsCount: IntBuffer): Boolean =
- nVRChaperoneSetup_GetLiveCollisionBoundsInfo(quadsBuffer?.adr ?: NULL, quadsCount.adr)
+ nVRChaperoneSetup_GetLiveCollisionBoundsInfo(quadsBuffer?.adr ?: NULL, quadsCount.adr)
/**
* Returns the preferred seated position from the working copy.
@@ -137,7 +138,7 @@ object vrChaperoneSetup : vrInterface {
/** Sets the Collision Bounds in the working copy. */
infix fun setWorkingPerimeter(pointBuffer: HmdVector2.Buffer) =
- nVRChaperoneSetup_SetWorkingPerimeter(pointBuffer.adr, pointBuffer.rem)
+ nVRChaperoneSetup_SetWorkingPerimeter(pointBuffer.adr, pointBuffer.rem)
/**
* Sets the preferred seated position in the working copy.
@@ -145,7 +146,7 @@ object vrChaperoneSetup : vrInterface {
* @param matSeatedZeroPoseToRawTrackingPose
*/
infix fun setWorkingSeatedZeroPoseToRawTrackingPose(matSeatedZeroPoseToRawTrackingPose: Mat4) =
- nVRChaperoneSetup_SetWorkingSeatedZeroPoseToRawTrackingPose(vr.HmdMatrix34(matSeatedZeroPoseToRawTrackingPose).adr)
+ nVRChaperoneSetup_SetWorkingSeatedZeroPoseToRawTrackingPose(vr.HmdMatrix34(matSeatedZeroPoseToRawTrackingPose).adr)
/**
* Sets the preferred standing position in the working copy.
@@ -153,7 +154,7 @@ object vrChaperoneSetup : vrInterface {
* @param matStandingZeroPoseToRawTrackingPose
*/
infix fun setWorkingStandingZeroPoseToRawTrackingPose(matStandingZeroPoseToRawTrackingPose: Mat4) =
- nVRChaperoneSetup_SetWorkingStandingZeroPoseToRawTrackingPose(vr.HmdMatrix34(matStandingZeroPoseToRawTrackingPose).adr)
+ nVRChaperoneSetup_SetWorkingStandingZeroPoseToRawTrackingPose(vr.HmdMatrix34(matStandingZeroPoseToRawTrackingPose).adr)
/**
* Tear everything down and reload it from the file on disk.
@@ -168,7 +169,7 @@ object vrChaperoneSetup : vrInterface {
* @param matSeatedZeroPoseToRawTrackingPose
*/
infix fun getLiveSeatedZeroPoseToRawTrackingPose(matSeatedZeroPoseToRawTrackingPose: Mat4): Boolean =
- nVRChaperoneSetup_GetLiveSeatedZeroPoseToRawTrackingPose(vr.HmdMatrix34(matSeatedZeroPoseToRawTrackingPose).adr)
+ nVRChaperoneSetup_GetLiveSeatedZeroPoseToRawTrackingPose(vr.HmdMatrix34(matSeatedZeroPoseToRawTrackingPose).adr)
fun exportLiveToBuffer(buffer: ByteBuffer?, bufferLength: IntBuffer): Boolean =
VRChaperoneSetup.nVRChaperoneSetup_ExportLiveToBuffer(buffer?.adr ?: NULL, bufferLength.adr)
diff --git a/src/main/kotlin/openvr/lib/ivrCompositor.kt b/src/main/kotlin/openvr/lib/ivrCompositor.kt
index 226684b..337b520 100644
--- a/src/main/kotlin/openvr/lib/ivrCompositor.kt
+++ b/src/main/kotlin/openvr/lib/ivrCompositor.kt
@@ -3,10 +3,10 @@ package openvr.lib
import glm_.vec4.Vec4
import kool.adr
import kool.cap
+import kool.stak
import org.lwjgl.PointerBuffer
import org.lwjgl.openvr.*
import org.lwjgl.openvr.VRCompositor.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.NULL
import org.lwjgl.system.MemoryUtil.memASCII
import org.lwjgl.vulkan.VkPhysicalDevice
@@ -349,10 +349,10 @@ object vrCompositor : vrInterface {
* The string will be a space separated list of-required instance extensions to enable in {@code VkCreateInstance}.
*/
val vulkanInstanceExtensionsRequired: List
- get() {
+ get() = stak {
val size = VRCompositor.nVRCompositor_GetVulkanInstanceExtensionsRequired(NULL, 0)
- val buffer = stackGet().malloc(size)
- return memASCII(buffer, buffer.cap - 1).split(' ')
+ val buffer = it.malloc(size)
+ memASCII(buffer, buffer.cap - 1).split(' ')
}
/**
@@ -362,11 +362,12 @@ object vrCompositor : vrInterface {
* @param physicalDevice
* @param unBufferSize
*/
- infix fun getVulkanDeviceExtensionsRequired(physicalDevice: VkPhysicalDevice): List {
- val size = VRCompositor.nVRCompositor_GetVulkanDeviceExtensionsRequired(physicalDevice.adr, NULL, 0)
- val buffer = stackGet().malloc(size)
- return memASCII(buffer, size - 1).split(' ')
- }
+ infix fun getVulkanDeviceExtensionsRequired(physicalDevice: VkPhysicalDevice): List =
+ stak {
+ val size = VRCompositor.nVRCompositor_GetVulkanDeviceExtensionsRequired(physicalDevice.adr, NULL, 0)
+ val buffer = it.malloc(size)
+ memASCII(buffer, size - 1).split(' ')
+ }
/**
* Vulkan/D3D12 Only
diff --git a/src/main/kotlin/openvr/lib/ivrDriverManager.kt b/src/main/kotlin/openvr/lib/ivrDriverManager.kt
index 4aa7761..38ea4cb 100644
--- a/src/main/kotlin/openvr/lib/ivrDriverManager.kt
+++ b/src/main/kotlin/openvr/lib/ivrDriverManager.kt
@@ -1,8 +1,8 @@
package openvr.lib
import kool.adr
+import kool.stak
import org.lwjgl.openvr.VRDriverManager.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.NULL
import org.lwjgl.system.MemoryUtil.memASCII
@@ -12,12 +12,13 @@ object vrDriverManager : vrInterface {
get() = VRDriverManager_GetDriverCount()
/** @return the length of the number of bytes necessary to hold this string including the trailing null */
- infix fun getDriverName(driver: DriverId): String {
- val bufferSize = nVRDriverManager_GetDriverName(driver, NULL, 0)
- val value = stackGet().malloc(bufferSize)
- val result = nVRDriverManager_GetDriverName(driver, value.adr, bufferSize)
- return memASCII(value, result - 1)
- }
+ infix fun getDriverName(driver: DriverId): String =
+ stak {
+ val bufferSize = nVRDriverManager_GetDriverName(driver, NULL, 0)
+ val value = it.malloc(bufferSize)
+ val result = nVRDriverManager_GetDriverName(driver, value.adr, bufferSize)
+ memASCII(value, result - 1)
+ }
/**
* Returns the property container handle for the specified driver.
@@ -25,7 +26,7 @@ object vrDriverManager : vrInterface {
* @param driverName the driver name
*/
infix fun getDriverHandle(driverName: String): DriverHandle =
- nVRDriverManager_GetDriverHandle(addressOfAscii(driverName))
+ stak { nVRDriverManager_GetDriverHandle(it.addressOfAscii(driverName)) }
override val version: String
get() = "IVRDriverManager_001"
diff --git a/src/main/kotlin/openvr/lib/ivrExtendedDisplay.kt b/src/main/kotlin/openvr/lib/ivrExtendedDisplay.kt
index 996bdf9..bcfea28 100644
--- a/src/main/kotlin/openvr/lib/ivrExtendedDisplay.kt
+++ b/src/main/kotlin/openvr/lib/ivrExtendedDisplay.kt
@@ -3,34 +3,36 @@ package openvr.lib
import glm_.BYTES
import glm_.vec2.Vec2i
import kool.adr
+import kool.stak
import org.lwjgl.openvr.VRExtendedDisplay.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.memGetInt
import java.nio.IntBuffer
object vrExtendedDisplay : vrInterface {
/** Size and position that the window needs to be on the VR display. */
- fun getWindowBounds(pos: Vec2i, size: Vec2i) {
- val x = stackGet().nmalloc(1, Vec2i.size * 2)
- val y = x + Int.BYTES
- val width = y + Int.BYTES
- val height = width + Int.BYTES
- nVRExtendedDisplay_GetWindowBounds(x, y, width, height)
- pos.put(memGetInt(x), memGetInt(y))
- size.put(memGetInt(width), memGetInt(height))
- }
+ fun getWindowBounds(pos: Vec2i, size: Vec2i) =
+ stak {
+ val x = it.nmalloc(1, Vec2i.size * 2)
+ val y = x + Int.BYTES
+ val width = y + Int.BYTES
+ val height = width + Int.BYTES
+ nVRExtendedDisplay_GetWindowBounds(x, y, width, height)
+ pos.put(memGetInt(x), memGetInt(y))
+ size.put(memGetInt(width), memGetInt(height))
+ }
/** Gets the viewport in the frame buffer to draw the output of the distortion into. */
- fun getEyeOutputViewport(eye: VREye, pos: Vec2i, size: Vec2i) {
- val x = stackGet().nmalloc(1, Vec2i.size * 2)
- val y = x + Int.BYTES
- val width = y + Int.BYTES
- val height = width + Int.BYTES
- nVRExtendedDisplay_GetEyeOutputViewport(eye.i, x, y, width, height)
- pos.put(memGetInt(x), memGetInt(y))
- size.put(memGetInt(width), memGetInt(height))
- }
+ fun getEyeOutputViewport(eye: VREye, pos: Vec2i, size: Vec2i) =
+ stak {
+ val x = it.nmalloc(1, Vec2i.size * 2)
+ val y = x + Int.BYTES
+ val width = y + Int.BYTES
+ val height = width + Int.BYTES
+ nVRExtendedDisplay_GetEyeOutputViewport(eye.i, x, y, width, height)
+ pos.put(memGetInt(x), memGetInt(y))
+ size.put(memGetInt(width), memGetInt(height))
+ }
/**
* D3D10/11 Only
diff --git a/src/main/kotlin/openvr/lib/ivrIOBuffer.kt b/src/main/kotlin/openvr/lib/ivrIOBuffer.kt
index 990b3dd..37ce354 100644
--- a/src/main/kotlin/openvr/lib/ivrIOBuffer.kt
+++ b/src/main/kotlin/openvr/lib/ivrIOBuffer.kt
@@ -2,6 +2,7 @@ package openvr.lib
import kool.adr
import kool.rem
+import kool.stak
import org.lwjgl.openvr.VRIOBuffer.*
import org.lwjgl.system.MemoryUtil.NULL
import java.nio.ByteBuffer
@@ -43,7 +44,7 @@ object vrIOBuffer : vrInterface {
* @param buffer ~ IOBufferHandle *
*/
fun open(path: String, mode: Mode, elementSize: Int, elements: Int, buffer: LongBuffer): Error =
- Error of nVRIOBuffer_Open(addressOfAscii(path), mode.i, elementSize, elements, buffer.adr)
+ stak { Error of nVRIOBuffer_Open(it.addressOfAscii(path), mode.i, elementSize, elements, buffer.adr) }
/** Closes a previously opened or created buffer. */
infix fun close(buffer: IOBufferHandle): Error = Error of VRIOBuffer_Close(buffer)
diff --git a/src/main/kotlin/openvr/lib/ivrInput.kt b/src/main/kotlin/openvr/lib/ivrInput.kt
index b059b3c..81b2427 100644
--- a/src/main/kotlin/openvr/lib/ivrInput.kt
+++ b/src/main/kotlin/openvr/lib/ivrInput.kt
@@ -1,5 +1,6 @@
package openvr.lib
+import glm_.BYTES
import kool.set
import kool.adr
import kool.rem
@@ -59,7 +60,8 @@ object vrInput : vrInterface {
pError[0] = value.i
}
- enum class VRSkeletalTransformSpace { Model, Parent;
+ enum class VRSkeletalTransformSpace {
+ Model, Parent;
@JvmField
val i = ordinal
@@ -69,7 +71,8 @@ object vrInput : vrInterface {
}
}
- enum class VRSkeletalReferencePose { BindPose, OpenHand, Fist, GripLimit;
+ enum class VRSkeletalReferencePose {
+ BindPose, OpenHand, Fist, GripLimit;
@JvmField
val i = ordinal
@@ -79,7 +82,8 @@ object vrInput : vrInterface {
}
}
- enum class VRFinger { Thumb, Index, Middle, Ring, Pinky;
+ enum class VRFinger {
+ Thumb, Index, Middle, Ring, Pinky;
@JvmField
val i = ordinal
@@ -89,7 +93,8 @@ object vrInput : vrInterface {
}
}
- enum class VRFingerSplay { Thumb_Index, Index_Middle, Middle_Ring, Ring_Pinky;
+ enum class VRFingerSplay {
+ Thumb_Index, Index_Middle, Middle_Ring, Ring_Pinky;
@JvmField
val i = ordinal
@@ -121,7 +126,8 @@ object vrInput : vrInterface {
}
}
- enum class VRInputFilterCancelType { Timers, Momentum;
+ enum class VRInputFilterCancelType {
+ Timers, Momentum;
@JvmField
val i = ordinal
@@ -142,7 +148,8 @@ object vrInput : vrInterface {
}
}
- enum class FilterCancelType { Timers, Momentum;
+ enum class FilterCancelType {
+ Timers, Momentum;
val i = ordinal
@@ -159,11 +166,11 @@ object vrInput : vrInterface {
*
* This call must be made before the first call to {@link #VRInput_UpdateActionState UpdateActionState} or {@link VRSystem#VRSystem_PollNextEvent PollNextEvent}.
*/
- fun setActionManifestPath(actionManifestPath: URL): Error {
- val file = File(actionManifestPath.file)
- val pPath = addressOfAscii(file.absolutePath)
- return Error of nVRInput_SetActionManifestPath(pPath)
- }
+ fun setActionManifestPath(actionManifestPath: URL): Error =
+ stak {
+ val file = File(actionManifestPath.file)
+ Error of nVRInput_SetActionManifestPath(it.addressOfAscii(file.absolutePath))
+ }
/**
* JVM custom
@@ -172,8 +179,10 @@ object vrInput : vrInterface {
*
* Note: Multi-thread unsafe if reading the error from the class property. */
fun getActionSetHandle(actionSetName: String, pErr: VRInputErrorBuffer = pError): VRActionSetHandle =
- stak.longAddress {
- pErr[0] = nVRInput_GetActionSetHandle(addressOfAscii(actionSetName), it)
+ stak {
+ val pHandle = it.nmalloc(8, Long.BYTES)
+ pErr[0] = nVRInput_GetActionSetHandle(it.addressOfAscii(actionSetName), pHandle)
+ memGetLong(pHandle)
}
/** JVM custom
@@ -182,8 +191,10 @@ object vrInput : vrInterface {
*
* Note: Multi-thread unsafe if reading the error from the class property. */
fun getActionHandle(actionName: String, pErr: VRInputErrorBuffer = pError): VRActionHandle =
- stak.longAddress {
- pErr[0] = nVRInput_GetActionHandle(addressOfAscii(actionName), it)
+ stak {
+ val pHandle = it.nmalloc(8, Long.BYTES)
+ pErr[0] = nVRInput_GetActionHandle(it.addressOfAscii(actionName), pHandle)
+ memGetLong(pHandle)
}
/** JVM custom
@@ -192,8 +203,10 @@ object vrInput : vrInterface {
*
* Note: Multi-thread unsafe if reading the error from the class property. */
fun getInputSourceHandle(inputSourcePath: String, pErr: VRInputErrorBuffer = pError): VRInputValueHandle =
- stak.longAddress {
- pErr[0] = nVRInput_GetInputSourceHandle(addressOfAscii(inputSourcePath), it)
+ stak {
+ val pHandle = it.nmalloc(8, Long.BYTES)
+ pErr[0] = nVRInput_GetInputSourceHandle(it.addressOfAscii(inputSourcePath), pHandle)
+ memGetLong(pHandle)
}
/**
diff --git a/src/main/kotlin/openvr/lib/ivrNotifications.kt b/src/main/kotlin/openvr/lib/ivrNotifications.kt
index 94ed4aa..a4954f7 100644
--- a/src/main/kotlin/openvr/lib/ivrNotifications.kt
+++ b/src/main/kotlin/openvr/lib/ivrNotifications.kt
@@ -1,6 +1,7 @@
package openvr.lib
import kool.adr
+import kool.stak
import org.lwjgl.openvr.NotificationBitmap
import org.lwjgl.openvr.VRNotifications.VRNotifications_RemoveNotification
import org.lwjgl.openvr.VRNotifications.nVRNotifications_CreateNotification
@@ -87,9 +88,12 @@ object vrNotifications : vrInterface {
* @param notificationId ~VRNotificationId
*/
fun createNotification(overlayHandle: VROverlayHandle, userValue: Long, type: Type, text: String,
- style: Style, image: NotificationBitmap?, notificationId: IntBuffer): Error =
- Error of nVRNotifications_CreateNotification(overlayHandle, userValue, type.i, addressOfAscii(text), style.i, image?.adr
- ?: NULL, notificationId.adr)
+ style: Style, image: NotificationBitmap?, notificationId: IntBuffer): Error =
+ stak {
+ val pText = it.addressOfAscii(text)
+ Error of nVRNotifications_CreateNotification(overlayHandle, userValue, type.i, pText, style.i, image?.adr
+ ?: NULL, notificationId.adr)
+ }
/**
* Destroy a notification, hiding it first if it currently shown to the user.
diff --git a/src/main/kotlin/openvr/lib/ivrOverlay.kt b/src/main/kotlin/openvr/lib/ivrOverlay.kt
index 9122be0..391b570 100644
--- a/src/main/kotlin/openvr/lib/ivrOverlay.kt
+++ b/src/main/kotlin/openvr/lib/ivrOverlay.kt
@@ -2,18 +2,16 @@ package openvr.lib
import glm_.BYTES
import glm_.mat4x4.Mat4
-import kool.set
import glm_.vec2.Vec2
import glm_.vec2.Vec2i
import glm_.vec3.Vec3
import kool.adr
import kool.rem
+import kool.set
import kool.stak
import org.lwjgl.PointerBuffer
import org.lwjgl.openvr.*
import org.lwjgl.openvr.VROverlay.*
-import org.lwjgl.system.MemoryStack.stackGet
-import org.lwjgl.system.MemoryUtil
import org.lwjgl.system.MemoryUtil.*
import java.nio.ByteBuffer
import java.nio.FloatBuffer
@@ -198,7 +196,7 @@ object vrOverlay : vrInterface {
* @param overlayHandle
*/
fun findOverlay(overlayKey: String, overlayHandle: VROverlayHandleBuffer): Error =
- Error of nVROverlay_FindOverlay(addressOfAscii(overlayKey), overlayHandle.adr)
+ stak { Error of nVROverlay_FindOverlay(it.addressOfAscii(overlayKey), overlayHandle.adr) }
/**
* Creates a new named overlay. All overlays start hidden and with default settings.
@@ -208,7 +206,7 @@ object vrOverlay : vrInterface {
* @param overlayHandle ~VROverlayHandle
*/
fun createOverlay(overlayKey: String, overlayName: String, overlayHandle: VROverlayHandleBuffer): Error =
- Error of nVROverlay_CreateOverlay(addressOfAscii(overlayKey), addressOfAscii(overlayName), overlayHandle.adr)
+ stak { Error of nVROverlay_CreateOverlay(it.addressOfAscii(overlayKey), it.addressOfAscii(overlayName), overlayHandle.adr) }
/**
* Destroys the specified overlay. When an application calls {@link VR#VR_ShutdownInternal ShutdownInternal} all overlays created by that app are automatically destroyed.
@@ -257,11 +255,12 @@ object vrOverlay : vrInterface {
* @param overlayHandle
* @param pErr
*/
- fun getOverlayKey(overlayHandle: VROverlayHandle, pErr: VROverlayErrorBuffer = pError): String {
- val value = stackGet().malloc(1, MaxKeyLength)
- val size = nVROverlay_GetOverlayKey(overlayHandle, value.adr, MaxKeyLength, pErr.adr)
- return MemoryUtil.memASCII(value, size - 1)
- }
+ fun getOverlayKey(overlayHandle: VROverlayHandle, pErr: VROverlayErrorBuffer = pError): String =
+ stak {
+ val value = it.malloc(1, MaxKeyLength)
+ val size = nVROverlay_GetOverlayKey(overlayHandle, value.adr, MaxKeyLength, pErr.adr)
+ memASCII(value, size - 1)
+ }
/**
* Fills the provided buffer with the friendly name of the overlay. Returns the size of buffer required to store the key, including the terminating null
@@ -272,11 +271,12 @@ object vrOverlay : vrInterface {
* @param overlayHandle
* @param error
*/
- fun getOverlayName(overlayHandle: VROverlayHandle, error: VROverlayErrorBuffer = pError): String {
- val value = stackGet().malloc(MaxNameLength)
- val size = nVROverlay_GetOverlayName(overlayHandle, value.adr, MaxKeyLength, error.adr)
- return MemoryUtil.memASCII(value, size - 1)
- }
+ fun getOverlayName(overlayHandle: VROverlayHandle, error: VROverlayErrorBuffer = pError): String =
+ stak {
+ val value = it.malloc(MaxNameLength)
+ val size = nVROverlay_GetOverlayName(overlayHandle, value.adr, MaxKeyLength, error.adr)
+ memASCII(value, size - 1)
+ }
/**
* Sets the name to use for this overlay.
@@ -285,7 +285,7 @@ object vrOverlay : vrInterface {
* @param name
*/
fun setOverlayName(overlayHandle: VROverlayHandle, name: String): Error =
- Error of nVROverlay_SetOverlayName(overlayHandle, addressOfAscii(name))
+ stak { Error of nVROverlay_SetOverlayName(overlayHandle, it.addressOfAscii(name)) }
/**
* Gets the raw image data from an overlay. Overlay image data is always returned as RGBA data, 4 bytes per pixel. If the buffer is not large enough,
@@ -296,13 +296,14 @@ object vrOverlay : vrInterface {
* @param punWidth
* @param punHeight
*/
- fun getOverlayImageData(overlayHandle: VROverlayHandle, buffer: ByteBuffer, size: Vec2i): Error {
- val width = stackGet().nmalloc(1, Vec2i.size)
- val height = width + Int.BYTES
- return Error of nVROverlay_GetOverlayImageData(overlayHandle, buffer.adr, buffer.rem, width, height).also {
- size(memGetInt(width), memGetInt(height))
- }
- }
+ fun getOverlayImageData(overlayHandle: VROverlayHandle, buffer: ByteBuffer, size: Vec2i): Error =
+ stak {
+ val width = it.nmalloc(1, Vec2i.size)
+ val height = width + Int.BYTES
+ Error of nVROverlay_GetOverlayImageData(overlayHandle, buffer.adr, buffer.rem, width, height).also {
+ size(memGetInt(width), memGetInt(height))
+ }
+ }
/**
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -378,14 +379,15 @@ object vrOverlay : vrInterface {
* @param overlayHandle
* @param color
*/
- fun getOverlayColor(overlayHandle: VROverlayHandle, color: Vec3): Error {
- val red = stackGet().nmalloc(1, Vec3.size)
- val green = red + Float.BYTES
- val blue = green + Float.BYTES
- return Error of nVROverlay_GetOverlayColor(overlayHandle, red, green, blue).also {
- color(memGetFloat(red), memGetFloat(green), memGetFloat(blue))
- }
- }
+ fun getOverlayColor(overlayHandle: VROverlayHandle, color: Vec3): Error =
+ stak {
+ val red = it.nmalloc(1, Vec3.size)
+ val green = red + Float.BYTES
+ val blue = green + Float.BYTES
+ Error of nVROverlay_GetOverlayColor(overlayHandle, red, green, blue).also {
+ color(memGetFloat(red), memGetFloat(green), memGetFloat(blue))
+ }
+ }
/**
* Sets the alpha of the overlay quad. Use 1.0 for 100 percent opacity to 0.0 for 0 percent opacity.
@@ -542,7 +544,7 @@ object vrOverlay : vrInterface {
nVROverlay_GetOverlayRenderModel(overlayHandle, value.adr, value.rem, color.adr, error.adr)
fun setOverlayRenderModel(overlayHandle: VROverlayHandle, renderModel: String, color: HmdColor): Error =
- Error of nVROverlay_SetOverlayRenderModel(overlayHandle, addressOfAscii(renderModel), color.adr)
+ stak { Error of nVROverlay_SetOverlayRenderModel(overlayHandle, it.addressOfAscii(renderModel), color.adr) }
/**
* Returns the transform type of this overlay.
@@ -610,7 +612,7 @@ object vrOverlay : vrInterface {
* @param componentName
*/
fun setOverlayTransformTrackedDeviceComponent(overlayHandle: VROverlayHandle, deviceIndex: TrackedDeviceIndex, componentName: String): Error =
- Error of nVROverlay_SetOverlayTransformTrackedDeviceComponent(overlayHandle, deviceIndex, addressOfAscii(componentName))
+ stak { Error of nVROverlay_SetOverlayTransformTrackedDeviceComponent(overlayHandle, deviceIndex, it.addressOfAscii(componentName)) }
/**
* Gets the transform information when the overlay is rendering on a component.
@@ -845,7 +847,7 @@ object vrOverlay : vrInterface {
* @param filePath
*/
fun setOverlayFromFile(overlayHandle: VROverlayHandle, filePath: String): Error =
- Error of nVROverlay_SetOverlayFromFile(overlayHandle, addressOfAscii(filePath))
+ stak { Error of nVROverlay_SetOverlayFromFile(overlayHandle, it.addressOfAscii(filePath)) }
/**
* Get the native texture handle/device for an overlay you have created.
@@ -903,7 +905,7 @@ object vrOverlay : vrInterface {
* @param thumbnailHandle ~ VROverlayHandle *
*/
fun createDashboardOverlay(overlayKey: String, overlayFriendlyName: String, mainHandle: LongBuffer, thumbnailHandle: LongBuffer): Error =
- Error of nVROverlay_CreateDashboardOverlay(addressOfAscii(overlayKey), addressOfAscii(overlayFriendlyName), mainHandle.adr, thumbnailHandle.adr)
+ stak { Error of nVROverlay_CreateDashboardOverlay(it.addressOfAscii(overlayKey), it.addressOfAscii(overlayFriendlyName), mainHandle.adr, thumbnailHandle.adr) }
/** Returns true if the dashboard is visible. */
val isDashboardVisible: Boolean
@@ -940,7 +942,7 @@ object vrOverlay : vrInterface {
*
* @param overlayToShow
*/
- fun showDashboard(overlayToShow: String) = nVROverlay_ShowDashboard(addressOfAscii(overlayToShow))
+ fun showDashboard(overlayToShow: String) = stak { nVROverlay_ShowDashboard(it.addressOfAscii(overlayToShow)) }
/** Returns the tracked device that has the laser pointer in the dashboard. */
val primaryDashboardDevice: TrackedDeviceIndex
@@ -959,7 +961,7 @@ object vrOverlay : vrInterface {
*/
fun showKeyboard(inputMode: GamepadTextInputMode, lineInputMode: GamepadTextInputLineMode, description: String, charMax: Int,
existingText: String, useMinimalMode: Boolean, userValue: Long): Error =
- Error of nVROverlay_ShowKeyboard(inputMode.i, lineInputMode.i, addressOfAscii(description), charMax, addressOfAscii(existingText), useMinimalMode, userValue)
+ stak { Error of nVROverlay_ShowKeyboard(inputMode.i, lineInputMode.i, it.addressOfAscii(description), charMax, it.addressOfAscii(existingText), useMinimalMode, userValue) }
/**
* @param overlayHandle
@@ -973,18 +975,19 @@ object vrOverlay : vrInterface {
*/
fun showKeyboardForOverlay(overlayHandle: VROverlayHandle, inputMode: GamepadTextInputMode, lineInputMode: GamepadTextInputLineMode,
description: String, charMax: Int, existingText: String, useMinimalMode: Boolean, userValue: Long): Error =
- Error of nVROverlay_ShowKeyboardForOverlay(overlayHandle, inputMode.i, lineInputMode.i, addressOfAscii(description), charMax, addressOfAscii(existingText), useMinimalMode, userValue)
+ stak { Error of nVROverlay_ShowKeyboardForOverlay(overlayHandle, inputMode.i, lineInputMode.i, it.addressOfAscii(description), charMax, it.addressOfAscii(existingText), useMinimalMode, userValue) }
/**
* Get the textSize that was entered into the textSize input.
*
* @param textSize
*/
- fun getKeyboardText(textSize: Int): String {
- val text = stackGet().malloc(textSize)
- val size = nVROverlay_GetKeyboardText(text.adr, textSize)
- return MemoryUtil.memASCII(text, size - 1)
- }
+ fun getKeyboardText(textSize: Int): String =
+ stak {
+ val text = it.malloc(textSize)
+ val size = nVROverlay_GetKeyboardText(text.adr, textSize)
+ memASCII(text, size - 1)
+ }
/** Hide the virtual keyboard. */
fun hideKeyboard() = VROverlay_HideKeyboard()
@@ -1031,15 +1034,16 @@ object vrOverlay : vrInterface {
* @param button2Text
* @param button3Text
*/
- fun showMessageOverlay(text: String, caption: String, button0Text: String, button1Text: String?, button2Text: String?, button3Text: String?): MessageResponse {
- val textEncoded = addressOfAscii(text)
- val captionEncoded = addressOfAscii(caption)
- val button0TextEncoded = addressOfAscii(button0Text)
- val button1TextEncoded = button1Text?.let { addressOfAscii(it) } ?: NULL
- val button2TextEncoded = button2Text?.let { addressOfAscii(it) } ?: NULL
- val button3TextEncoded = button3Text?.let { addressOfAscii(it) } ?: NULL
- return MessageResponse of nVROverlay_ShowMessageOverlay(textEncoded, captionEncoded, button0TextEncoded, button1TextEncoded, button2TextEncoded, button3TextEncoded)
- }
+ fun showMessageOverlay(text: String, caption: String, button0Text: String, button1Text: String?, button2Text: String?, button3Text: String?): MessageResponse =
+ stak {s ->
+ val textEncoded = s.addressOfAscii(text)
+ val captionEncoded = s.addressOfAscii(caption)
+ val button0TextEncoded = s.addressOfAscii(button0Text)
+ val button1TextEncoded = button1Text?.let { s.addressOfAscii(it) } ?: NULL
+ val button2TextEncoded = button2Text?.let { s.addressOfAscii(it) } ?: NULL
+ val button3TextEncoded = button3Text?.let { s.addressOfAscii(it) } ?: NULL
+ MessageResponse of nVROverlay_ShowMessageOverlay(textEncoded, captionEncoded, button0TextEncoded, button1TextEncoded, button2TextEncoded, button3TextEncoded)
+ }
/** If the calling process owns the overlay and it's open, this will close it. */
fun closeMessageOverlay() = VROverlay_CloseMessageOverlay()
diff --git a/src/main/kotlin/openvr/lib/ivrRenderModels.kt b/src/main/kotlin/openvr/lib/ivrRenderModels.kt
index d14bcd2..7c2d214 100644
--- a/src/main/kotlin/openvr/lib/ivrRenderModels.kt
+++ b/src/main/kotlin/openvr/lib/ivrRenderModels.kt
@@ -1,12 +1,11 @@
package openvr.lib
-import kool.set
import kool.adr
+import kool.set
import kool.stak
import org.lwjgl.PointerBuffer
import org.lwjgl.openvr.*
import org.lwjgl.openvr.VRRenderModels.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.*
import java.nio.IntBuffer
@@ -74,26 +73,25 @@ object vrRenderModels : vrInterface {
* Note: Multi-thread unsafe if not passing a pError and reading it from the class property.
*/
@JvmOverloads
- fun loadRenderModel(renderModelName: String, pErr: VRVRRenderModelsErrorBuffer = pError): RenderModel? {
-
- val stack = stackGet()
- val pModel = stack.mallocPointer(1)
- var err: Int
- while (true) {
- err = nVRRenderModels_LoadRenderModel_Async(stack.addressOfAscii(renderModelName), pModel.adr)
- if (err != vrRenderModels.Error.Loading.i)
- break
-
- Thread.sleep(1)
- }
-
- if (err != vrRenderModels.Error.None.i) {
- pErr[0] = err
- return null // move on to the next tracked device
- }
-
- return RenderModel.create(pModel[0])
- }
+ fun loadRenderModel(renderModelName: String, pErr: VRVRRenderModelsErrorBuffer = pError): RenderModel? =
+ stak {
+
+ val pModel = it.mallocPointer(1)
+ var err: Int
+ while (true) {
+ err = nVRRenderModels_LoadRenderModel_Async(it.addressOfAscii(renderModelName), pModel.adr)
+ if (err != vrRenderModels.Error.Loading.i)
+ break
+
+ Thread.sleep(1)
+ }
+
+ if (err != vrRenderModels.Error.None.i) {
+ pErr[0] = err
+ null // move on to the next tracked device
+ } else
+ RenderModel.create(pModel[0])
+ }
/**
* Loads and returns a render model for use in the application. {@code renderModelName} should be a render model name from the
@@ -103,7 +101,7 @@ object vrRenderModels : vrInterface {
* the render model it should call {@link #VRRenderModels_FreeRenderModel FreeRenderModel} to free the memory associated with the model.
*/
fun loadRenderModel_Async(renderModelName: String, renderModel: PointerBuffer): Error =
- Error of nVRRenderModels_LoadRenderModel_Async(addressOfAscii(renderModelName), renderModel.adr)
+ stak { Error of nVRRenderModels_LoadRenderModel_Async(it.addressOfAscii(renderModelName), renderModel.adr) }
/** Frees a previously returned render model It is safe to call this on a null ptr. */
fun RenderModel.freeNative() = nVRRenderModels_FreeRenderModel(adr)
@@ -114,26 +112,26 @@ object vrRenderModels : vrInterface {
*
* Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
- fun loadTexture(textureId: TextureId, pErr: VRVRRenderModelsErrorBuffer = pError): RenderModelTextureMap? {
+ fun loadTexture(textureId: TextureId, pErr: VRVRRenderModelsErrorBuffer = pError): RenderModelTextureMap? =
- val stack = stackGet()
- val pTexture = stack.mallocPointer(1)
- var err: Int
- while (true) {
- err = nVRRenderModels_LoadTexture_Async(textureId, pTexture.adr)
- if (err != vrRenderModels.Error.Loading.i)
- break
+ stak {
- Thread.sleep(1)
- }
+ val pTexture = it.mallocPointer(1)
+ var err: Int
+ while (true) {
+ err = nVRRenderModels_LoadTexture_Async(textureId, pTexture.adr)
+ if (err != vrRenderModels.Error.Loading.i)
+ break
- if (err != vrRenderModels.Error.None.i) {
- pErr[0] = err
- return null // move on to the next tracked device
- }
+ Thread.sleep(1)
+ }
- return RenderModelTextureMap.create(pTexture[0])
- }
+ if (err != vrRenderModels.Error.None.i) {
+ pErr[0] = err
+ null // move on to the next tracked device
+ } else
+ RenderModelTextureMap.create(pTexture[0])
+ }
/** Loads and returns a texture for use in the application. */
fun loadTexture_Async(textureId: TextureId, texture: PointerBuffer): Error =
@@ -158,12 +156,13 @@ object vrRenderModels : vrInterface {
* available render models. If the index is out of range, this function will return 0. Otherwise, it will return the size of the buffer required for the
* name.
*/
- infix fun getRenderModelName(renderModelIndex: Int): String {
- val renderModelNameLen = VRRenderModels.nVRRenderModels_GetRenderModelName(renderModelIndex, NULL, 0)
- val renderModelName = stackGet().malloc(renderModelNameLen)
- val result = nVRRenderModels_GetRenderModelName(renderModelIndex, renderModelName.adr, renderModelNameLen)
- return memASCII(renderModelName, result - 1)
- }
+ infix fun getRenderModelName(renderModelIndex: Int): String =
+ stak {
+ val renderModelNameLen = VRRenderModels.nVRRenderModels_GetRenderModelName(renderModelIndex, NULL, 0)
+ val renderModelName = it.malloc(renderModelNameLen)
+ val result = nVRRenderModels_GetRenderModelName(renderModelIndex, renderModelName.adr, renderModelNameLen)
+ memASCII(renderModelName, result - 1)
+ }
/** Returns the number of available render models. */
val renderModelCount: Int
@@ -175,7 +174,7 @@ object vrRenderModels : vrInterface {
* Components are useful when client application wish to draw, label, or otherwise interact with components of tracked objects.
*/
fun getComponentCount(renderModelName: String): Int =
- nVRRenderModels_GetComponentCount(addressOfAscii(renderModelName))
+ stak { nVRRenderModels_GetComponentCount(it.addressOfAscii(renderModelName)) }
/**
* Use this to get the names of available components. Index does not correlate to a tracked device index, but is only used for iterating over all
@@ -183,10 +182,10 @@ object vrRenderModels : vrInterface {
* name.
*/
fun getComponentName(renderModelName: String, componentIndex: Int): String =
- stackGet().run {
- val renderModelNameEncoded = addressOfAscii(renderModelName)
+ stak {
+ val renderModelNameEncoded = it.addressOfAscii(renderModelName)
val componentNameLen = nVRRenderModels_GetComponentName(renderModelNameEncoded, componentIndex, NULL, 0)
- val componentName = malloc(componentNameLen)
+ val componentName = it.malloc(componentNameLen)
val result = VRRenderModels.nVRRenderModels_GetComponentName(renderModelNameEncoded, componentIndex, componentName.adr, componentNameLen)
memASCII(componentName, result - 1)
}
@@ -205,18 +204,18 @@ object vrRenderModels : vrInterface {
* A single component may be associated with multiple buttons. Ex: A trackpad which also provides "D-pad" functionality
*/
fun getComponentButtonMask(renderModelName: String, componentName: String): Long =
- nVRRenderModels_GetComponentButtonMask(addressOfAscii(renderModelName), addressOfAscii(componentName))
+ stak { nVRRenderModels_GetComponentButtonMask(it.addressOfAscii(renderModelName), it.addressOfAscii(componentName)) }
/**
* Use this to get the render model name for the specified rendermode/component combination, to be passed to {@link #VRRenderModels_LoadRenderModel_Async LoadRenderModel_Async}. If the component
* name is out of range, this function will return 0. Otherwise, it will return the size of the buffer required for the name.
*/
fun getComponentRenderModelName(renderModelName: String, componentName: String): String =
- stackGet().run {
- val renderModelNameEncoded = addressOfAscii(renderModelName)
- val componentNameEncoded = addressOfAscii(componentName)
+ stak {
+ val renderModelNameEncoded = it.addressOfAscii(renderModelName)
+ val componentNameEncoded = it.addressOfAscii(componentName)
val componentRenderModelNameLen = nVRRenderModels_GetComponentRenderModelName(renderModelNameEncoded, componentNameEncoded, NULL, 0)
- val componentRenderModelName = malloc(componentRenderModelNameLen)
+ val componentRenderModelName = it.malloc(componentRenderModelNameLen)
val result = nVRRenderModels_GetComponentRenderModelName(renderModelNameEncoded, componentNameEncoded, componentRenderModelName.adr, componentRenderModelNameLen)
memASCII(componentRenderModelName, result - 1)
}
@@ -230,24 +229,24 @@ object vrRenderModels : vrInterface {
* Otherwise, return true
* Note: For dynamic objects, visibility may be dynamic. (I.e., true/false will be returned based on controller state and controller mode state ) */
fun getComponentStateForDevicePath(renderModelName: CharSequence, componentName: CharSequence, devicePath: VRInputValueHandle, state: RenderModelControllerModeState, componentState: RenderModelComponentState): Boolean =
- nVRRenderModels_GetComponentStateForDevicePath(addressOfAscii(renderModelName), addressOfAscii(componentName), devicePath, state.adr, componentState.adr)
+ stak { nVRRenderModels_GetComponentStateForDevicePath(it.addressOfAscii(renderModelName), it.addressOfAscii(componentName), devicePath, state.adr, componentState.adr) }
/** This version of GetComponentState takes a controller state block instead of an action origin. */
@Deprecated("You should use the new input system and GetComponentStateForDevicePath instead.", ReplaceWith("getComponentStateForDevicePath"))
fun getComponentState(renderModelName: String, componentName: String, controllerState: VRControllerState,
state: RenderModelControllerModeState, componentState: RenderModelComponentState): Boolean =
- nVRRenderModels_GetComponentState(addressOfAscii(renderModelName), addressOfAscii(componentName), controllerState.adr, state.adr, componentState.adr)
+ stak { nVRRenderModels_GetComponentState(it.addressOfAscii(renderModelName), it.addressOfAscii(componentName), controllerState.adr, state.adr, componentState.adr) }
/** Returns true if the render model has a component with the specified name. */
fun renderModelHasComponent(renderModelName: String, componentName: String): Boolean =
- nVRRenderModels_RenderModelHasComponent(addressOfAscii(renderModelName), addressOfAscii(componentName))
+ stak { nVRRenderModels_RenderModelHasComponent(it.addressOfAscii(renderModelName), it.addressOfAscii(componentName)) }
/** Returns the URL of the thumbnail image for this rendermodel. */
fun getRenderModelThumbnailURL(renderModelName: String, error: IntBuffer): String =
- stackGet().run {
- val renderModelNameEncoded = addressOfAscii(renderModelName)
+ stak {
+ val renderModelNameEncoded = it.addressOfAscii(renderModelName)
val thumbnailURLLen = nVRRenderModels_GetRenderModelThumbnailURL(renderModelNameEncoded, NULL, 0, error.adr)
- val thumbnailURL = malloc(thumbnailURLLen)
+ val thumbnailURL = it.malloc(thumbnailURLLen)
val result = nVRRenderModels_GetRenderModelThumbnailURL(renderModelNameEncoded, thumbnailURL.adr, thumbnailURLLen, error.adr)
memASCII(thumbnailURL, result - 1)
}
@@ -258,10 +257,10 @@ object vrRenderModels : vrInterface {
* @param error ~ Error *
*/
fun getRenderModelOriginalPath(renderModelName: String, error: IntBuffer): String =
- stackGet().run {
- val renderModelNameEncoded = addressOfAscii(renderModelName)
+ stak {
+ val renderModelNameEncoded = it.addressOfAscii(renderModelName)
val originalPathLen = nVRRenderModels_GetRenderModelOriginalPath(renderModelNameEncoded, NULL, 0, error.adr)
- val originalPath = malloc(originalPathLen)
+ val originalPath = it.malloc(originalPathLen)
val result = nVRRenderModels_GetRenderModelOriginalPath(renderModelNameEncoded, originalPath.adr, originalPathLen, error.adr)
memASCII(originalPath, result - 1)
}
diff --git a/src/main/kotlin/openvr/lib/ivrResources.kt b/src/main/kotlin/openvr/lib/ivrResources.kt
index aeea0f9..96d9550 100644
--- a/src/main/kotlin/openvr/lib/ivrResources.kt
+++ b/src/main/kotlin/openvr/lib/ivrResources.kt
@@ -1,9 +1,9 @@
package openvr.lib
import kool.adr
+import kool.stak
import org.lwjgl.openvr.VRResources.nVRResources_GetResourceFullPath
import org.lwjgl.openvr.VRResources.nVRResources_LoadSharedResource
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.NULL
import org.lwjgl.system.MemoryUtil.memASCII
@@ -16,10 +16,10 @@ object vrResources : vrInterface {
* @return the size in bytes of the buffer required to hold the specified resource
*/
infix fun loadSharedResource(resourceName: String): String =
- stackGet().run {
- val resourceNameEncoded = addressOfAscii(resourceName)
+ stak {
+ val resourceNameEncoded = it.addressOfAscii(resourceName)
val bufferLen = nVRResources_LoadSharedResource(resourceNameEncoded, NULL, 0)
- val buffer = malloc(bufferLen)
+ val buffer = it.malloc(bufferLen)
val result = nVRResources_LoadSharedResource(resourceNameEncoded, buffer.adr, bufferLen)
memASCII(buffer, result - 1)
}
@@ -29,11 +29,11 @@ object vrResources : vrInterface {
* those and returns the actual physical path. {@code resourceTypeDirectory} is the subdirectory of resources to look in.
*/
fun getResourceFullPath(resourceName: String, resourceTypeDirectory: String): String =
- stackGet().run {
- val resourceNameEncoded = addressOfAscii(resourceName)
- val resourceTypeDirectoryEncoded = addressOfAscii(resourceTypeDirectory)
+ stak {
+ val resourceNameEncoded = it.addressOfAscii(resourceName)
+ val resourceTypeDirectoryEncoded = it.addressOfAscii(resourceTypeDirectory)
val bufferLen = nVRResources_GetResourceFullPath(resourceNameEncoded, resourceTypeDirectoryEncoded, NULL, 0)
- val pathBuffer = malloc(bufferLen)
+ val pathBuffer = it.malloc(bufferLen)
val result = nVRResources_GetResourceFullPath(resourceNameEncoded, resourceTypeDirectoryEncoded, pathBuffer.adr, bufferLen)
memASCII(pathBuffer, result - 1)
}
diff --git a/src/main/kotlin/openvr/lib/ivrScreenshots.kt b/src/main/kotlin/openvr/lib/ivrScreenshots.kt
index 22ae06c..978827a 100644
--- a/src/main/kotlin/openvr/lib/ivrScreenshots.kt
+++ b/src/main/kotlin/openvr/lib/ivrScreenshots.kt
@@ -1,10 +1,10 @@
package openvr.lib
-import kool.set
import kool.adr
import kool.rem
+import kool.set
+import kool.stak
import org.lwjgl.openvr.VRScreenshots.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.*
import java.nio.IntBuffer
@@ -77,7 +77,7 @@ object vrScreenshots : vrInterface {
* @param outScreenshotHandle ~ScreenshotHandle *
*/
fun requestScreenshot(outScreenshotHandle: VRScreenshotHandleBuffer, type: Type, previewFilename: String, vrFilename: String): Error =
- Error of nVRScreenshots_RequestScreenshot(outScreenshotHandle.adr, type.i, addressOfAscii(previewFilename), addressOfAscii(vrFilename))
+ stak { Error of nVRScreenshots_RequestScreenshot(outScreenshotHandle.adr, type.i, it.addressOfAscii(previewFilename), it.addressOfAscii(vrFilename)) }
/**
* Called by the running VR application to indicate that it wishes to be in charge of screenshots. If the application does not call this, the Compositor
@@ -101,12 +101,13 @@ object vrScreenshots : vrInterface {
*
* @return the filename
*/
- fun getScreenshotPropertyFilename(screenshotHandle: ScreenshotHandle, filenameType: PropertyFilenames, error: IntBuffer): String {
- val filenameLen = nVRScreenshots_GetScreenshotPropertyFilename(screenshotHandle, filenameType.i, NULL, 0, error.adr)
- val filename = stackGet().malloc(filenameLen)
- val result = nVRScreenshots_GetScreenshotPropertyFilename(screenshotHandle, filenameType.i, filename.adr, filenameLen, error.adr)
- return memASCII(filename, result - 1)
- }
+ fun getScreenshotPropertyFilename(screenshotHandle: ScreenshotHandle, filenameType: PropertyFilenames, error: IntBuffer): String =
+ stak {
+ val filenameLen = nVRScreenshots_GetScreenshotPropertyFilename(screenshotHandle, filenameType.i, NULL, 0, error.adr)
+ val filename = it.malloc(filenameLen)
+ val result = nVRScreenshots_GetScreenshotPropertyFilename(screenshotHandle, filenameType.i, filename.adr, filenameLen, error.adr)
+ memASCII(filename, result - 1)
+ }
/**
* Call this if the application is taking the screen shot will take more than a few ms processing. This will result in an overlay being presented that
@@ -124,7 +125,7 @@ object vrScreenshots : vrInterface {
* @param outScreenshotHandle ~ScreenshotHandle *
*/
fun takeStereoScreenshot(outScreenshotHandle: IntBuffer, previewFilename: String, vrFilename: String): Error =
- Error of nVRScreenshots_TakeStereoScreenshot(outScreenshotHandle.adr, addressOfAscii(previewFilename), addressOfAscii(vrFilename))
+ stak { Error of nVRScreenshots_TakeStereoScreenshot(outScreenshotHandle.adr, it.addressOfAscii(previewFilename), it.addressOfAscii(vrFilename)) }
/**
* Submit the completed screenshot.
@@ -141,7 +142,7 @@ object vrScreenshots : vrInterface {
* @param type one of:
{@link VR#EVRScreenshotType_VRScreenshotType_None} |
{@link VR#EVRScreenshotType_VRScreenshotType_Mono} |
{@link VR#EVRScreenshotType_VRScreenshotType_Stereo} |
{@link VR#EVRScreenshotType_VRScreenshotType_Cubemap} |
{@link VR#EVRScreenshotType_VRScreenshotType_MonoPanorama} |
{@link VR#EVRScreenshotType_VRScreenshotType_StereoPanorama} |
*/
fun submitScreenshot(screenshotHandle: ScreenshotHandle, type: Type, sourcePreviewFilename: String, sourceVRFilename: String): Error =
- Error of nVRScreenshots_SubmitScreenshot(screenshotHandle, type.i, addressOfAscii(sourcePreviewFilename), addressOfAscii(sourceVRFilename))
+ stak { Error of nVRScreenshots_SubmitScreenshot(screenshotHandle, type.i, it.addressOfAscii(sourcePreviewFilename), it.addressOfAscii(sourceVRFilename)) }
override val version: String
get() = "IVRScreenshots_001"
diff --git a/src/main/kotlin/openvr/lib/ivrSettings.kt b/src/main/kotlin/openvr/lib/ivrSettings.kt
index bf9f733..593e1a9 100644
--- a/src/main/kotlin/openvr/lib/ivrSettings.kt
+++ b/src/main/kotlin/openvr/lib/ivrSettings.kt
@@ -1,10 +1,9 @@
package openvr.lib
-import kool.set
import kool.adr
+import kool.set
import kool.stak
import org.lwjgl.openvr.VRSettings.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.memASCII
import org.lwjgl.system.MemoryUtil.memCallocInt
@@ -729,51 +728,52 @@ object vrSettings : vrInterface {
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun setBool(section: String, settingsKey: String, value: Boolean, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_SetBool(addressOfAscii(section), addressOfAscii(settingsKey), value, pErr.adr)
+ stak { nVRSettings_SetBool(it.addressOfAscii(section), it.addressOfAscii(settingsKey), value, pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun setInt(section: String, settingsKey: String, value: Int, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_SetInt32(addressOfAscii(section), addressOfAscii(settingsKey), value, pErr.adr)
+ stak { nVRSettings_SetInt32(it.addressOfAscii(section), it.addressOfAscii(settingsKey), value, pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun setFloat(section: String, settingsKey: String, value: Float, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_SetFloat(addressOfAscii(section), addressOfAscii(settingsKey), value, pErr.adr)
+ stak { nVRSettings_SetFloat(it.addressOfAscii(section), it.addressOfAscii(settingsKey), value, pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun setString(section: String, settingsKey: String, value: String, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_SetString(addressOfAscii(section), addressOfAscii(settingsKey), addressOfAscii(value), pErr.adr)
+ stak { nVRSettings_SetString(it.addressOfAscii(section), it.addressOfAscii(settingsKey), it.addressOfAscii(value), pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun getBool(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError): Boolean =
- nVRSettings_GetBool(addressOfAscii(section), addressOfAscii(settingsKey), pErr.adr)
+ stak { nVRSettings_GetBool(it.addressOfAscii(section), it.addressOfAscii(settingsKey), pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
@JvmOverloads
fun getInt(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError): Int =
- nVRSettings_GetInt32(addressOfAscii(section), addressOfAscii(settingsKey), pErr.adr)
+ stak { nVRSettings_GetInt32(it.addressOfAscii(section), it.addressOfAscii(settingsKey), pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
fun getFloat(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError): Float =
- nVRSettings_GetFloat(addressOfAscii(section), addressOfAscii(settingsKey), pErr.adr)
+ stak { nVRSettings_GetFloat(it.addressOfAscii(section), it.addressOfAscii(settingsKey), pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
- fun getString(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError): String {
- val s = stackGet().nmalloc(1, maxKeyLength)
- nVRSettings_GetString(addressOfAscii(section), addressOfAscii(settingsKey), s, maxKeyLength, pErr.adr)
- return memASCII(s)
- }
+ fun getString(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError): String =
+ stak {
+ val s = it.nmalloc(1, maxKeyLength)
+ nVRSettings_GetString(it.addressOfAscii(section), it.addressOfAscii(settingsKey), s, maxKeyLength, pErr.adr)
+ memASCII(s)
+ }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
fun removeSection(section: String, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_RemoveSection(addressOfAscii(section), pErr.adr)
+ stak { nVRSettings_RemoveSection(it.addressOfAscii(section), pErr.adr) }
/** Note: Multi-thread unsafe if not passing a pError and reading it from the class property. */
fun removeKeyInSection(section: String, settingsKey: String, pErr: VRSettingsErrorBuffer = pError) =
- nVRSettings_RemoveKeyInSection(addressOfAscii(section), addressOfAscii(settingsKey), pErr.adr)
+ stak { nVRSettings_RemoveKeyInSection(it.addressOfAscii(section), it.addressOfAscii(settingsKey), pErr.adr) }
override val version: String
get() = "IVRSettings_002"
diff --git a/src/main/kotlin/openvr/lib/ivrSpatialAnchors.kt b/src/main/kotlin/openvr/lib/ivrSpatialAnchors.kt
index da298c7..2fe6f04 100644
--- a/src/main/kotlin/openvr/lib/ivrSpatialAnchors.kt
+++ b/src/main/kotlin/openvr/lib/ivrSpatialAnchors.kt
@@ -1,11 +1,11 @@
package openvr.lib
+import glm_.BYTES
import kool.set
+import kool.stak
import org.lwjgl.openvr.SpatialAnchorPose
import org.lwjgl.openvr.VRSpatialAnchors.*
-import org.lwjgl.system.MemoryStack.stackGet
-import org.lwjgl.system.MemoryUtil.memASCII
-import org.lwjgl.system.MemoryUtil.memCallocInt
+import org.lwjgl.system.MemoryUtil.*
object vrSpatialAnchors : vrInterface {
@@ -55,8 +55,10 @@ object vrSpatialAnchors : vrInterface {
*/
@JvmOverloads
fun createSpatialAnchorFromDescriptor(descriptor: CharSequence, pErr: VRSpatialAnchorErrorBuffer = pError): SpatialAnchorHandle =
- intAddress { pHandleOut ->
- pErr[0] = nVRSpatialAnchors_CreateSpatialAnchorFromDescriptor(addressOfAscii(descriptor), pHandleOut)
+ stak {
+ val pHandleOut = it.nmalloc(4, Int.BYTES)
+ pErr[0] = nVRSpatialAnchors_CreateSpatialAnchorFromDescriptor(it.addressOfAscii(descriptor), pHandleOut)
+ memGetInt(pHandleOut)
}
/**
@@ -79,8 +81,10 @@ object vrSpatialAnchors : vrInterface {
*/
@JvmOverloads
fun createSpatialAnchorFromPose(deviceIndex: TrackedDeviceIndex, origin: TrackingUniverseOrigin, pose: SpatialAnchorPose, pErr: VRSpatialAnchorErrorBuffer = pError): SpatialAnchorHandle =
- intAddress { pHandleOut ->
+ stak {
+ val pHandleOut = it.nmalloc(4, Int.BYTES)
pErr[0] = nVRSpatialAnchors_CreateSpatialAnchorFromPose(deviceIndex, origin.i, pose.adr, pHandleOut)
+ memGetInt(pHandleOut)
}
/**
@@ -104,12 +108,14 @@ object vrSpatialAnchors : vrInterface {
* Note: Multi-thread unsafe if not passing a pError and reading it from the class property.
*/
@JvmOverloads
- fun getSpatialAnchorDescriptor(handle: SpatialAnchorHandle, pErr: VRSpatialAnchorErrorBuffer = pError): String {
- val pDescr = stackGet().nmalloc(1, maxDescriptorSize)
- val pDescrSize = pIntOf(maxDescriptorSize)
- pErr[0] = nVRSpatialAnchors_GetSpatialAnchorDescriptor(handle, pDescr, pDescrSize)
- return memASCII(pDescr)
- }
+ fun getSpatialAnchorDescriptor(handle: SpatialAnchorHandle, pErr: VRSpatialAnchorErrorBuffer = pError): String =
+ stak {
+ val pDescr = it.nmalloc(1, maxDescriptorSize)
+ val pDescrSize = it.nmalloc(4, Int.BYTES)
+ memPutInt(pDescrSize, maxDescriptorSize)
+ pErr[0] = nVRSpatialAnchors_GetSpatialAnchorDescriptor(handle, pDescr, pDescrSize)
+ memASCII(pDescr)
+ }
override val version: String
get() = "IVRSpatialAnchors_001"
diff --git a/src/main/kotlin/openvr/lib/ivrSystem.kt b/src/main/kotlin/openvr/lib/ivrSystem.kt
index 4b5c29e..7482102 100644
--- a/src/main/kotlin/openvr/lib/ivrSystem.kt
+++ b/src/main/kotlin/openvr/lib/ivrSystem.kt
@@ -3,14 +3,14 @@ package openvr.lib
import glm_.BYTES
import glm_.mat4x4.Mat4
import glm_.s
-import kool.set
import glm_.vec2.Vec2i
import glm_.vec4.Vec4
import kool.adr
import kool.rem
+import kool.set
+import kool.stak
import org.lwjgl.openvr.*
import org.lwjgl.openvr.VRSystem.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.*
import org.lwjgl.vulkan.VkInstance
import java.nio.ByteBuffer
@@ -40,11 +40,11 @@ object vrSystem : vrInterface {
* @param pnHeight recommended height for the offscreen render target
*/
val recommendedRenderTargetSize: Vec2i
- get() {
- val width = stackGet().nmalloc(1, Vec2i.size)
+ get() = stak {
+ val width = it.nmalloc(1, Vec2i.size)
val height = width + Int.BYTES
nVRSystem_GetRecommendedRenderTargetSize(width, height)
- return Vec2i(memGetInt(width), memGetInt(height))
+ Vec2i(memGetInt(width), memGetInt(height))
}
/**
@@ -67,14 +67,15 @@ object vrSystem : vrInterface {
* @param eye determines which eye the function should return the projection for. One of:
{@link VR#EVREye_Eye_Left} | {@link VR#EVREye_Eye_Right} |
* @return [left, right, top, bottom] coordinate for the bottom clipping plane
*/
- infix fun getProjectionRaw(eye: VREye): FloatArray {
- val left = stackGet().nmalloc(1, Vec4.size)
- val right = left + Float.BYTES
- val top = right + Float.BYTES
- val bottom = top + Float.BYTES
- nVRSystem_GetProjectionRaw(eye.i, left, right, top, bottom)
- return floatArrayOf(memGetFloat(left), memGetFloat(right), memGetFloat(top), memGetFloat(bottom))
- }
+ infix fun getProjectionRaw(eye: VREye): FloatArray =
+ stak {
+ val left = it.nmalloc(1, Vec4.size)
+ val right = left + Float.BYTES
+ val top = right + Float.BYTES
+ val bottom = top + Float.BYTES
+ nVRSystem_GetProjectionRaw(eye.i, left, right, top, bottom)
+ floatArrayOf(memGetFloat(left), memGetFloat(right), memGetFloat(top), memGetFloat(bottom))
+ }
/**
* Gets the result of the distortion function for the specified eye and input UVs. UVs go from 0,0 in the upper left of that eye's viewport and 1,1 in the
@@ -439,22 +440,22 @@ object vrSystem : vrInterface {
* @param pError the error returned when attempting to fetch this property. This can be {@code NULL} if the caller doesn't care about the source of a property error.
*/
@JvmOverloads
- fun getStringTrackedDeviceProperty(deviceIndex: TrackedDeviceIndex, prop: TrackedDeviceProperty, pErr: TrackedPropertyErrorBuffer = pError): String = stackGet().run {
-
- val initialSize = 32
- val bytes = malloc(initialSize)
- val propLen = nVRSystem_GetStringTrackedDeviceProperty(deviceIndex, prop.i, bytes.adr, initialSize, pErr.adr)
-
- when (pErr[0]) {
- TrackedPropertyError.Success.i -> memASCII(bytes, propLen - 1)
- TrackedPropertyError.BufferTooSmall.i -> {
- val newBytes = malloc(propLen)
- nVRSystem_GetStringTrackedDeviceProperty(deviceIndex, prop.i, newBytes.adr, propLen, pErr.adr)
- memASCII(newBytes, propLen - 1)
+ fun getStringTrackedDeviceProperty(deviceIndex: TrackedDeviceIndex, prop: TrackedDeviceProperty, pErr: TrackedPropertyErrorBuffer = pError): String =
+ stak {
+ val initialSize = 32
+ val bytes = it.malloc(initialSize)
+ val propLen = nVRSystem_GetStringTrackedDeviceProperty(deviceIndex, prop.i, bytes.adr, initialSize, pErr.adr)
+
+ when (pErr[0]) {
+ TrackedPropertyError.Success.i -> memASCII(bytes, propLen - 1)
+ TrackedPropertyError.BufferTooSmall.i -> {
+ val newBytes = it.malloc(propLen)
+ nVRSystem_GetStringTrackedDeviceProperty(deviceIndex, prop.i, newBytes.adr, propLen, pErr.adr)
+ memASCII(newBytes, propLen - 1)
+ }
+ else -> throw Error(error.toString())
+ }
}
- else -> throw Error(error.toString())
- }
- }
/**
* Kind of useless on JVM, but it will be offered anyway on the enum itself
@@ -642,11 +643,13 @@ object vrSystem : vrInterface {
*
* @return the size of the response including its terminating null
*/
- fun driverDebugRequest(deviceIndex: TrackedDeviceIndex, request: String, responseBufferSize: Int = vr.maxDriverDebugResponseSize): String {
- val responseBuffer = stackGet().malloc(responseBufferSize)
- val size = VRSystem.nVRSystem_DriverDebugRequest(deviceIndex, addressOfAscii(request), responseBuffer.adr, responseBufferSize)
- return memASCII(responseBuffer, size - 1)
- }
+ fun driverDebugRequest(deviceIndex: TrackedDeviceIndex, request: String, responseBufferSize: Int = vr.maxDriverDebugResponseSize): String =
+ stak {
+ val responseBuffer = it.malloc(responseBufferSize)
+ val pRequest = it.addressOfAscii(request)
+ val size = VRSystem.nVRSystem_DriverDebugRequest(deviceIndex, pRequest, responseBuffer.adr, responseBufferSize)
+ memASCII(responseBuffer, size - 1)
+ }
// ------------------------------------
diff --git a/src/main/kotlin/openvr/lib/ivrTrackedCamera.kt b/src/main/kotlin/openvr/lib/ivrTrackedCamera.kt
index 0a47d77..f969ba1 100644
--- a/src/main/kotlin/openvr/lib/ivrTrackedCamera.kt
+++ b/src/main/kotlin/openvr/lib/ivrTrackedCamera.kt
@@ -2,17 +2,16 @@ package openvr.lib
import glm_.BYTES
import glm_.mat4x4.Mat4
-import kool.set
import glm_.vec2.Vec2i
import kool.adr
import kool.rem
+import kool.set
import kool.stak
import org.lwjgl.PointerBuffer
import org.lwjgl.openvr.CameraVideoStreamFrameHeader
import org.lwjgl.openvr.HmdVector2
import org.lwjgl.openvr.VRTextureBounds
import org.lwjgl.openvr.VRTrackedCamera.*
-import org.lwjgl.system.MemoryStack.stackGet
import org.lwjgl.system.MemoryUtil.*
import java.nio.ByteBuffer
import java.nio.IntBuffer
@@ -80,7 +79,7 @@ object vrTrackedCamera : vrInterface {
}
}
- enum class VRDistortionFunctionType{None, FTheta, Extended_FTheta, MAX_DISTORTION_FUNCTION_TYPES }
+ enum class VRDistortionFunctionType { None, FTheta, Extended_FTheta, MAX_DISTORTION_FUNCTION_TYPES }
const val maxDistortionFunctionParameters: Int = 8
@@ -103,14 +102,16 @@ object vrTrackedCamera : vrInterface {
* Gets size of the image frame.
*
* @param frameType one of:
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Distorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Undistorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_MaximumUndistorted} |
{@link VR#EVRTrackedCameraFrameType_MAX_CAMERA_FRAME_TYPES} |
+ *
+ * Note: Multi-thread unsafe if not passing a pError and reading it from the class property.
*/
- fun getCameraFrameSize(deviceIndex: TrackedDeviceIndex, frameType: FrameType, size: Vec2i, frameBufferSize: IntBuffer): Error {
- val width = stackGet().nmalloc(1, Vec2i.size)
- val height = width + Int.BYTES
- return Error of nVRTrackedCamera_GetCameraFrameSize(deviceIndex, frameType.i, width, height, frameBufferSize.adr).also {
- size.put(memGetInt(width), memGetInt(height))
- }
- }
+ fun getCameraFrameSize(deviceIndex: TrackedDeviceIndex, frameType: FrameType, frameBufferSize: IntBuffer, pErr: VRTrackedCameraErrorBuffer = pError): Vec2i =
+ stak {
+ val width = it.nmalloc(1, Vec2i.size)
+ val height = width + Int.BYTES
+ pErr[0] = nVRTrackedCamera_GetCameraFrameSize(deviceIndex, frameType.i, width, height, frameBufferSize.adr)
+ Vec2i(memGetInt(width), memGetInt(height))
+ }
/** @param frameType one of:
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Distorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Undistorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_MaximumUndistorted} |
{@link VR#EVRTrackedCameraFrameType_MAX_CAMERA_FRAME_TYPES} |
*/
fun getCameraIntrinsics(deviceIndex: TrackedDeviceIndex, cameraIndex: Int, frameType: FrameType,
@@ -135,7 +136,7 @@ object vrTrackedCamera : vrInterface {
* lack of active consumers or headset idleness.
*/
@JvmOverloads
- fun acquireVideoStreamingService(deviceIndex: TrackedDeviceIndex, pErr: TrackedCameraErrorBuffer = pError): TrackedCameraHandle =
+ fun acquireVideoStreamingService(deviceIndex: TrackedDeviceIndex, pErr: VRTrackedCameraErrorBuffer = pError): TrackedCameraHandle =
stak.longAddress {
pErr[0] = nVRTrackedCamera_AcquireVideoStreamingService(deviceIndex, it)
}
@@ -159,13 +160,13 @@ object vrTrackedCamera : vrInterface {
*
* @param frameType one of:
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Distorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_Undistorted} |
{@link VR#EVRTrackedCameraFrameType_VRTrackedCameraFrameType_MaximumUndistorted} |
{@link VR#EVRTrackedCameraFrameType_MAX_CAMERA_FRAME_TYPES} |
*/
- fun getVideoStreamTextureSize(deviceIndex: TrackedDeviceIndex, frameType: FrameType, textureBounds: VRTextureBounds, size: Vec2i): Error {
- val width = stackGet().nmalloc(1, Int.BYTES * 2)
- val height = width + Int.BYTES
- return Error of nVRTrackedCamera_GetVideoStreamTextureSize(deviceIndex, frameType.i, textureBounds.adr, width, height).also {
- size.put(memGetInt(width), memGetInt(height))
- }
- }
+ fun getVideoStreamTextureSize(deviceIndex: TrackedDeviceIndex, frameType: FrameType, textureBounds: VRTextureBounds, pErr: VRTrackedCameraErrorBuffer = pError): Vec2i =
+ stak {
+ val width = it.nmalloc(1, Int.BYTES * 2)
+ val height = width + Int.BYTES
+ pErr[0] = nVRTrackedCamera_GetVideoStreamTextureSize(deviceIndex, frameType.i, textureBounds.adr, width, height)
+ Vec2i(memGetInt(width), memGetInt(height))
+ }
/**
* Access a shared D3D11 texture for the specified tracked camera stream.
diff --git a/src/main/kotlin/openvr/lib/openvr.kt b/src/main/kotlin/openvr/lib/openvr.kt
index 403d9c5..49c2316 100644
--- a/src/main/kotlin/openvr/lib/openvr.kt
+++ b/src/main/kotlin/openvr/lib/openvr.kt
@@ -489,7 +489,7 @@ object vr {
/** Returns the interface of the specified version. This method must be called after VR_Init. The
* pointer returned is valid until VR_Shutdown is called. */
fun getGenericInterface(interfaceVersion: String, error: VRInitErrorBuffer): Ptr =
- nVR_GetGenericInterface(addressOfAscii(interfaceVersion), error.adr)
+ stak { nVR_GetGenericInterface(it.addressOfAscii(interfaceVersion), error.adr) }
/** Returns a token that represents whether the VR interface handles need to be reloaded */
val initToken: Int
diff --git a/src/main/kotlin/openvr/lib/temp.kt b/src/main/kotlin/openvr/lib/temp.kt
index f5ddbee..b438e4c 100644
--- a/src/main/kotlin/openvr/lib/temp.kt
+++ b/src/main/kotlin/openvr/lib/temp.kt
@@ -1,17 +1,14 @@
package openvr.lib
-import glm_.BYTES
import glm_.b
-import kool.set
import kool.Adr
import kool.Ptr
+import kool.stak
import org.lwjgl.openvr.VR.nVR_IsInterfaceVersionValid
import org.lwjgl.system.CustomBuffer
import org.lwjgl.system.MemoryStack
-import org.lwjgl.system.MemoryStack.stackGet
-import org.lwjgl.system.MemoryUtil.*
+import org.lwjgl.system.MemoryUtil.memPutByte
import org.lwjgl.system.Pointer
-import java.nio.ByteBuffer
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
@@ -21,20 +18,20 @@ interface vrInterface {
/** Returns whether the interface of the specified version exists. */
val isInterfaceVersionValid: Boolean
- get() = nVR_IsInterfaceVersionValid(addressOfAscii("FnTable:$version"))
+ get() = stak { nVR_IsInterfaceVersionValid(it.addressOfAscii("FnTable:$version")) }
}
inline val Pointer.adr: Ptr
get() = address()
-fun bufferOfAscii(string: String, nullTerminated: Boolean = true): ByteBuffer {
- val bytes = stackGet().malloc(string.length + if (nullTerminated) 1 else 0)
- for (i in string.indices)
- bytes[i] = string[i].b
- if (nullTerminated)
- bytes[string.length] = 0
- return bytes
-}
+//fun bufferOfAscii(string: String, nullTerminated: Boolean = true): ByteBuffer {
+// val bytes = stackGet().malloc(string.length + if (nullTerminated) 1 else 0)
+// for (i in string.indices)
+// bytes[i] = string[i].b
+// if (nullTerminated)
+// bytes[string.length] = 0
+// return bytes
+//}
// TODO change String's to CharSequence's
fun MemoryStack.addressOfAscii(chars: CharSequence, nullTerminated: Boolean = true): Adr {
@@ -46,33 +43,11 @@ fun MemoryStack.addressOfAscii(chars: CharSequence, nullTerminated: Boolean = tr
return adr
}
-fun addressOfAscii(chars: CharSequence, nullTerminated: Boolean = true): Adr = stackGet().addressOfAscii(chars, nullTerminated)
-
inline val >CustomBuffer.rem
get() = remaining()
-inline fun longAddress(block: (Adr) -> R): Long {
- val adr = stackGet().nmalloc(1, Long.BYTES)
- block(adr)
- return memGetLong(adr)
-}
-
-inline fun intAddress(block: (Adr) -> R): Int {
- val adr = stackGet().nmalloc(1, Int.BYTES)
- block(adr)
- return memGetInt(adr)
-}
-
// TODO -> uno
const val NUL = '\u0000'
-inline val pInt: Adr
- get() = stackGet().nmalloc(1, Int.BYTES)
-
-fun pIntOf(int: Int): Adr =
- pInt.also {
- memPutInt(it, int)
- }
-
operator fun KMutableProperty0.setValue(host: Any?, property: KProperty<*>, value: R) = set(value)
operator fun KMutableProperty0.getValue(host: Any?, property: KProperty<*>): R = get()
\ No newline at end of file
diff --git a/src/main/kotlin/openvr/lib/typealias.kt b/src/main/kotlin/openvr/lib/typealias.kt
index a14a7bb..2389bd2 100644
--- a/src/main/kotlin/openvr/lib/typealias.kt
+++ b/src/main/kotlin/openvr/lib/typealias.kt
@@ -125,7 +125,7 @@ typealias VRSpatialAnchorErrorBuffer = IntBuffer
typealias VRInitErrorBuffer = IntBuffer
typealias VRInputErrorBuffer = IntBuffer
typealias TrackedPropertyErrorBuffer = IntBuffer
-typealias TrackedCameraErrorBuffer = IntBuffer
+typealias VRTrackedCameraErrorBuffer = IntBuffer
typealias TextureTypeBuffer = IntBuffer
typealias ColorSpaceBuffer = IntBuffer
diff --git a/src/test/kotlin/openvr/helloVr_OpenGL/Application.kt b/src/test/kotlin/openvr/helloVr_OpenGL/Application.kt
index 2c2a8e3..4d247b6 100644
--- a/src/test/kotlin/openvr/helloVr_OpenGL/Application.kt
+++ b/src/test/kotlin/openvr/helloVr_OpenGL/Application.kt
@@ -10,9 +10,7 @@ import gln.debug.glDebugMessageCallback
import openvr.lib.*
import openvr.lib.VREventType
import openvr.lib.vrRenderModels.freeNative
-import org.lwjgl.glfw.GLFWErrorCallback
import org.lwjgl.opengl.GL11.*
-import org.lwjgl.opengl.GLUtil
import org.lwjgl.opengl.KHRDebug.GL_DEBUG_OUTPUT_SYNCHRONOUS
import org.lwjgl.opengl.KHRDebug.glDebugMessageControl
import org.lwjgl.openvr.TrackedDevicePose
@@ -28,7 +26,7 @@ import kotlin.reflect.KMutableProperty0
import openvr.lib.TrackedDeviceClass as TDC
import org.lwjgl.opengl.KHRDebug.glDebugMessageCallback as _
-fun main(args: Array) {
+fun main() {
if (System.getenv("TRAVIS") == "true") // for travis
return
diff --git a/src/test/kotlin/openvr/helloVr_OpenGL/CompanionWindow.kt b/src/test/kotlin/openvr/helloVr_OpenGL/CompanionWindow.kt
index e5805b5..977044c 100644
--- a/src/test/kotlin/openvr/helloVr_OpenGL/CompanionWindow.kt
+++ b/src/test/kotlin/openvr/helloVr_OpenGL/CompanionWindow.kt
@@ -8,7 +8,6 @@ import gln.glViewport
import gln.glf.glf
import gln.glf.semantic
import gln.program.glUseProgram
-import gln.program.usingProgram
import gln.vertexArray.glBindVertexArray
import gln.vertexArray.glEnableVertexAttribArray
import gln.vertexArray.glVertexAttribPointer
@@ -22,11 +21,15 @@ import openvr.lib.vr
import org.lwjgl.opengl.GL
import org.lwjgl.opengl.GL11.*
import org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE
-import org.lwjgl.opengl.GL15.glDeleteBuffers
-import org.lwjgl.opengl.GL15.glGenBuffers
+import org.lwjgl.opengl.GL15.*
+import org.lwjgl.opengl.GL15C.GL_ARRAY_BUFFER
+import org.lwjgl.opengl.GL15C.glBindBuffer
import org.lwjgl.opengl.GL20
-import org.lwjgl.opengl.GL30.glDeleteVertexArrays
-import org.lwjgl.opengl.GL30.glGenVertexArrays
+import org.lwjgl.opengl.GL20.glUniform1i
+import org.lwjgl.opengl.GL20C
+import org.lwjgl.opengl.GL20C.glGetUniformLocation
+import org.lwjgl.opengl.GL20C.glUseProgram
+import org.lwjgl.opengl.GL30.*
import org.lwjgl.opengl.GLUtil
import uno.glfw.GlfwWindow
import uno.glfw.VSync
@@ -88,11 +91,11 @@ class CompanionWindow {
glGenBuffers(bufferName)
- glBindArrayBuffer(bufferName[Buffer.VERTEX])
- glArrayBufferData(vertices, Usage.StaticDraw)
+ glBindBuffer(GL_ARRAY_BUFFER, bufferName[Buffer.VERTEX])
+ glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW)
- glBindElementBuffer(bufferName[Buffer.INDEX])
- glElementBufferData(indices, Usage.StaticDraw)
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.INDEX])
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW)
glEnableVertexAttribArray(glf.pos2_tc2)
glVertexAttribPointer(glf.pos2_tc2)
@@ -155,7 +158,8 @@ class CompanionWindow {
outColor = texture(myTexture, uv);
}""") {
init {
- usingProgram(name) { "myTexture".unit = semantic.sampler.DIFFUSE }
+ glUseProgram(name)
+ glUniform1i(glGetUniformLocation(name, "myTexture"), semantic.sampler.DIFFUSE)
}
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/openvr/helloVr_OpenGL/Scene.kt b/src/test/kotlin/openvr/helloVr_OpenGL/Scene.kt
index d9f2fd6..c4b4de3 100644
--- a/src/test/kotlin/openvr/helloVr_OpenGL/Scene.kt
+++ b/src/test/kotlin/openvr/helloVr_OpenGL/Scene.kt
@@ -6,13 +6,10 @@ import glm_.mat4x4.Mat4
import glm_.vec3.Vec3
import glm_.vec3.Vec3i
import glm_.vec4.Vec4
-import gln.buffer.Usage
-import gln.buffer.initArrayBuffer
import gln.clear.glClearColorBuffer
import gln.clear.glClearDepthBuffer
import gln.glf.glf
import gln.glf.semantic
-import gln.program.usingProgram
import gln.texture.glBindTexture2d
import gln.uniform.glUniform
import gln.vertexArray.glBindVertexArray
@@ -25,7 +22,9 @@ import org.lwjgl.opengl.EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EX
import org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE
import org.lwjgl.opengl.GL13.GL_TEXTURE0
import org.lwjgl.opengl.GL13.glActiveTexture
-import org.lwjgl.opengl.GL30.*
+import org.lwjgl.opengl.GL15C
+import org.lwjgl.opengl.GL20C
+import org.lwjgl.opengl.GL30C.*
import uno.kotlin.url
import java.awt.image.DataBufferByte
import javax.imageio.ImageIO
@@ -107,12 +106,10 @@ class Scene {
}
vertexCount = vertDataArray.size / 5
- initArrayBuffer(bufferName) {
-
- vertDataArray.toFloatArray().toBuffer().use { vertices ->
-
- data(vertices, Usage.StaticDraw)
- }
+ glGenBuffers(bufferName)
+ glBindBuffer(GL_ARRAY_BUFFER, bufferName[0])
+ vertDataArray.toFloatArray().toBuffer().use { vertices ->
+ GL15C.glBufferData(GL_ARRAY_BUFFER, vertices, GL15C.GL_STATIC_DRAW)
}
initVertexArray(vertexArrayName) {
@@ -268,7 +265,8 @@ class Scene {
}""") {
init {
- usingProgram(name) { "myTexture".unit = semantic.sampler.DIFFUSE }
+ glUseProgram(name)
+ glUniform1i(GL20C.glGetUniformLocation(name, "myTexture"), semantic.sampler.DIFFUSE)
}
}
@@ -293,7 +291,8 @@ class Scene {
}""") {
init {
- usingProgram(name) { "diffuse".unit = semantic.sampler.DIFFUSE }
+ glUseProgram(name)
+ glUniform1i(GL20C.glGetUniformLocation(name, "diffuse"), semantic.sampler.DIFFUSE)
}
}
diff --git a/src/test/kotlin/openvr/helloVr_OpenGL/helpers.kt b/src/test/kotlin/openvr/helloVr_OpenGL/helpers.kt
index df6fe22..94d8909 100644
--- a/src/test/kotlin/openvr/helloVr_OpenGL/helpers.kt
+++ b/src/test/kotlin/openvr/helloVr_OpenGL/helpers.kt
@@ -22,6 +22,7 @@ import org.lwjgl.opengl.EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EX
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL12.GL_CLAMP_TO_EDGE
import org.lwjgl.opengl.GL12.GL_TEXTURE_MAX_LEVEL
+import org.lwjgl.opengl.GL15
import org.lwjgl.opengl.GL20.glEnableVertexAttribArray
import org.lwjgl.opengl.GL30.*
import org.lwjgl.opengl.GL32.GL_TEXTURE_2D_MULTISAMPLE
@@ -126,8 +127,8 @@ class CGLRenderModel(val modelName: String, vrModel: RenderModel, vrDiffuseTextu
// Populate a vertex buffer
glGenBuffers(bufferName)
- glBindArrayBuffer(bufferName[Buffer.VERTEX])
- glArrayBufferData(vrModel.vertices, Usage.StaticDraw)
+ glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferName[Buffer.VERTEX])
+ glBufferData(GL_ARRAY_BUFFER, vrModel.vertices, GL15.GL_STATIC_DRAW)
// Identify the components in the vertex buffer
glEnableVertexAttribArray(semantic.attr.POSITION)
@@ -136,8 +137,8 @@ class CGLRenderModel(val modelName: String, vrModel: RenderModel, vrDiffuseTextu
glVertexAttribPointer(semantic.attr.TEX_COORD, Vec2.length, GL_FLOAT, false, RenderModelVertex.SIZEOF, RenderModelVertex.RFTEXTURECOORD)
// Create and populate the index buffer
- glBindElementBuffer(bufferName[Buffer.INDEX])
- glElementBufferData(vrModel.indices, Usage.StaticDraw)
+ glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, bufferName[Buffer.INDEX])
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, vrModel.indices, GL15.GL_STATIC_DRAW)
glBindVertexArray()