Skip to content

Commit

Permalink
fix(generator): struct-by-value parameters. Close LWJGL#496
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi authored and fayer3 committed Jul 14, 2023
1 parent 46b3375 commit c714981
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions modules/lwjgl/openvr/src/generated/c/org_lwjgl_openvr_VROverlay.c
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public class VRChaperone {

static { OpenVR.initialize(); }

protected VRChaperone() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
/** Overlay management methods. */
public class VROverlay {

static { OpenVR.initialize(); }

protected VROverlay() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c714981

Please sign in to comment.