From c7149817ac973827bc9eff49f1930b6179b77365 Mon Sep 17 00:00:00 2001 From: Ioannis Tsakpinis Date: Fri, 23 Aug 2019 14:49:18 +0300 Subject: [PATCH] fix(generator): struct-by-value parameters. Close #496 --- .../c/org_lwjgl_openvr_VRChaperone.c | 33 ++++++++++++++ .../generated/c/org_lwjgl_openvr_VROverlay.c | 45 +++++++++++++++++++ .../java/org/lwjgl/openvr/VRChaperone.java | 7 ++- .../java/org/lwjgl/openvr/VROverlay.java | 12 ++++- .../kotlin/openvr/templates/VRChaperone.kt | 14 ++++++ .../kotlin/openvr/templates/VROverlay.kt | 17 +++++++ 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c create mode 100644 modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c new file mode 100644 index 0000000000..d7959ea2dd --- /dev/null +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VRChaperone.c @@ -0,0 +1,33 @@ +/* + * Copyright LWJGL. All rights reserved. + * License terms: https://www.lwjgl.org/license + * MACHINE GENERATED FILE, DO NOT EDIT + */ +#include "common_tools.h" + +#ifdef LWJGL_WINDOWS + #define APIENTRY __stdcall +#else + #define APIENTRY +#endif + +typedef struct HmdColor_t +{ + float r; + float g; + float b; + float a; +} HmdColor_t; + +typedef void (APIENTRY *VRChaperone_SetSceneColorPROC) (HmdColor_t); + +EXTERN_C_ENTER + +JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VRChaperone_nVRChaperone_1SetSceneColor(JNIEnv *__env, jclass clazz, jlong colorAddress, jlong __functionAddress) { + VRChaperone_SetSceneColorPROC VRChaperone_SetSceneColor = (VRChaperone_SetSceneColorPROC)(intptr_t)__functionAddress; + HmdColor_t *color = (HmdColor_t *)(intptr_t)colorAddress; + UNUSED_PARAMS(__env, clazz) + VRChaperone_SetSceneColor(*color); +} + +EXTERN_C_EXIT diff --git a/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c new file mode 100644 index 0000000000..41e95c8332 --- /dev/null +++ b/modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c @@ -0,0 +1,45 @@ +/* + * Copyright LWJGL. All rights reserved. + * License terms: https://www.lwjgl.org/license + * MACHINE GENERATED FILE, DO NOT EDIT + */ +#include "common_tools.h" + +#ifdef LWJGL_WINDOWS + #define APIENTRY __stdcall +#else + #define APIENTRY +#endif + +typedef struct HmdVector2_t +{ + float v[2]; +} HmdVector2_t; + +typedef struct HmdRect2_t +{ + struct HmdVector2_t vTopLeft; + struct HmdVector2_t vBottomRight; +} HmdRect2_t; + +typedef jint (APIENTRY *VROverlay_GetTransformForOverlayCoordinatesPROC) (jlong, jint, HmdVector2_t, intptr_t); +typedef void (APIENTRY *VROverlay_SetKeyboardPositionForOverlayPROC) (jlong, HmdRect2_t); + +EXTERN_C_ENTER + +JNIEXPORT jint JNICALL Java_org_lwjgl_openvr_VROverlay_nVROverlay_1GetTransformForOverlayCoordinates(JNIEnv *__env, jclass clazz, jlong ulOverlayHandle, jint eTrackingOrigin, jlong coordinatesInOverlayAddress, jlong pmatTransformAddress, jlong __functionAddress) { + VROverlay_GetTransformForOverlayCoordinatesPROC VROverlay_GetTransformForOverlayCoordinates = (VROverlay_GetTransformForOverlayCoordinatesPROC)(intptr_t)__functionAddress; + HmdVector2_t *coordinatesInOverlay = (HmdVector2_t *)(intptr_t)coordinatesInOverlayAddress; + intptr_t pmatTransform = (intptr_t)pmatTransformAddress; + UNUSED_PARAMS(__env, clazz) + return (jint)VROverlay_GetTransformForOverlayCoordinates(ulOverlayHandle, eTrackingOrigin, *coordinatesInOverlay, pmatTransform); +} + +JNIEXPORT void JNICALL Java_org_lwjgl_openvr_VROverlay_nVROverlay_1SetKeyboardPositionForOverlay(JNIEnv *__env, jclass clazz, jlong ulOverlayHandle, jlong avoidRectAddress, jlong __functionAddress) { + VROverlay_SetKeyboardPositionForOverlayPROC VROverlay_SetKeyboardPositionForOverlay = (VROverlay_SetKeyboardPositionForOverlayPROC)(intptr_t)__functionAddress; + HmdRect2_t *avoidRect = (HmdRect2_t *)(intptr_t)avoidRectAddress; + UNUSED_PARAMS(__env, clazz) + VROverlay_SetKeyboardPositionForOverlay(ulOverlayHandle, *avoidRect); +} + +EXTERN_C_EXIT diff --git a/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VRChaperone.java b/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VRChaperone.java index 74600eaced..690db17303 100644 --- a/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VRChaperone.java +++ b/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VRChaperone.java @@ -24,6 +24,8 @@ */ public class VRChaperone { + static { OpenVR.initialize(); } + protected VRChaperone() { throw new UnsupportedOperationException(); } @@ -96,13 +98,16 @@ public static void VRChaperone_ReloadInfo() { // --- [ VRChaperone_SetSceneColor ] --- + /** Unsafe version of: {@link #VRChaperone_SetSceneColor SetSceneColor} */ + public static native void nVRChaperone_SetSceneColor(long color, long __functionAddress); + /** Unsafe version of: {@link #VRChaperone_SetSceneColor SetSceneColor} */ public static void nVRChaperone_SetSceneColor(long color) { long __functionAddress = OpenVR.VRChaperone.SetSceneColor; if (CHECKS) { check(__functionAddress); } - callPV(color, __functionAddress); + nVRChaperone_SetSceneColor(color, __functionAddress); } /** Optionally give the chaperone system a hit about the color and brightness in the scene. */ diff --git a/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VROverlay.java b/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VROverlay.java index d23d117311..17ce04fa60 100644 --- a/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VROverlay.java +++ b/modules/lwjgl/openvr/src/generated/java/org/lwjgl/openvr/VROverlay.java @@ -21,6 +21,8 @@ /** Overlay management methods. */ public class VROverlay { + static { OpenVR.initialize(); } + protected VROverlay() { throw new UnsupportedOperationException(); } @@ -945,13 +947,16 @@ public static boolean VROverlay_IsOverlayVisible(@NativeType("VROverlayHandle_t" // --- [ VROverlay_GetTransformForOverlayCoordinates ] --- + /** Unsafe version of: {@link #VROverlay_GetTransformForOverlayCoordinates GetTransformForOverlayCoordinates} */ + public static native int nVROverlay_GetTransformForOverlayCoordinates(long ulOverlayHandle, int eTrackingOrigin, long coordinatesInOverlay, long pmatTransform, long __functionAddress); + /** Unsafe version of: {@link #VROverlay_GetTransformForOverlayCoordinates GetTransformForOverlayCoordinates} */ public static int nVROverlay_GetTransformForOverlayCoordinates(long ulOverlayHandle, int eTrackingOrigin, long coordinatesInOverlay, long pmatTransform) { long __functionAddress = OpenVR.VROverlay.GetTransformForOverlayCoordinates; if (CHECKS) { check(__functionAddress); } - return callJPPI(ulOverlayHandle, eTrackingOrigin, coordinatesInOverlay, pmatTransform, __functionAddress); + return nVROverlay_GetTransformForOverlayCoordinates(ulOverlayHandle, eTrackingOrigin, coordinatesInOverlay, pmatTransform, __functionAddress); } /** @@ -1668,13 +1673,16 @@ public static void VROverlay_SetKeyboardTransformAbsolute(@NativeType("ETracking // --- [ VROverlay_SetKeyboardPositionForOverlay ] --- + /** Unsafe version of: {@link #VROverlay_SetKeyboardPositionForOverlay SetKeyboardPositionForOverlay} */ + public static native void nVROverlay_SetKeyboardPositionForOverlay(long ulOverlayHandle, long avoidRect, long __functionAddress); + /** Unsafe version of: {@link #VROverlay_SetKeyboardPositionForOverlay SetKeyboardPositionForOverlay} */ public static void nVROverlay_SetKeyboardPositionForOverlay(long ulOverlayHandle, long avoidRect) { long __functionAddress = OpenVR.VROverlay.SetKeyboardPositionForOverlay; if (CHECKS) { check(__functionAddress); } - callJPV(ulOverlayHandle, avoidRect, __functionAddress); + nVROverlay_SetKeyboardPositionForOverlay(ulOverlayHandle, avoidRect, __functionAddress); } /** Set the position of the keyboard in overlay space by telling it to avoid a rectangle in the overlay. Rectangle coords have (0,0) in the bottom left. */ diff --git a/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VRChaperone.kt b/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VRChaperone.kt index 4b4a744ffb..c313ab388e 100644 --- a/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VRChaperone.kt +++ b/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VRChaperone.kt @@ -21,6 +21,20 @@ val VRChaperone = "VRChaperone".nativeClass( "-Z is the preferred forward facing direction." )} """ + nativeDirective(""" +#ifdef LWJGL_WINDOWS + #define APIENTRY __stdcall +#else + #define APIENTRY +#endif + +typedef struct HmdColor_t +{ + float r; + float g; + float b; + float a; +} HmdColor_t;""") ChaperoneCalibrationState( "GetCalibrationState", diff --git a/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VROverlay.kt b/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VROverlay.kt index eb643f0776..6cabb20c23 100644 --- a/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VROverlay.kt +++ b/modules/lwjgl/openvr/src/templates/kotlin/openvr/templates/VROverlay.kt @@ -13,6 +13,23 @@ val VROverlay = "VROverlay".nativeClass( binding = OPENVR_FNTABLE_BINDING ) { documentation = "Overlay management methods." + nativeDirective(""" +#ifdef LWJGL_WINDOWS + #define APIENTRY __stdcall +#else + #define APIENTRY +#endif + +typedef struct HmdVector2_t +{ + float v[2]; +} HmdVector2_t; + +typedef struct HmdRect2_t +{ + struct HmdVector2_t vTopLeft; + struct HmdVector2_t vBottomRight; +} HmdRect2_t;""") EVROverlayError( "FindOverlay",