From b668b71c97b3276d541f2e1d47ccd8d06f3a730d Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Tue, 30 Jan 2024 15:38:09 +0800 Subject: [PATCH 1/4] [GLFW] Rewrite GLFW --- .../src/main/java/overrungl/Addressable.java | 1 + .../src/main/java/overrungl/ArrayPointer.java | 1 + .../src/main/java/overrungl/Callback.java | 1 + .../src/main/java/overrungl/Pointer.java | 1 + .../src/main/java/overrungl/Struct.java | 1 + .../main/java/overrungl/internal/Checks.java | 32 ----- .../java/overrungl/internal/Exceptions.java | 3 +- .../overrungl/internal/RuntimeHelper.java | 10 -- .../main/java/overrungl/util/MemoryStack.java | 3 +- .../src/main/java/overrungl/glfw/GLFW.java | 113 +++++++++--------- .../java/overrungl/glfw/GLFWCallbacks.java | 24 +++- .../{IGLFWCharFun.java => GLFWCharFun.java} | 31 ++--- ...rEnterFun.java => GLFWCursorEnterFun.java} | 38 +++--- ...ursorPosFun.java => GLFWCursorPosFun.java} | 31 ++--- .../{IGLFWDropFun.java => GLFWDropFun.java} | 44 +++---- .../overrungl/glfw/GLFWErrorCallback.java | 27 ++--- .../{IGLFWErrorFun.java => GLFWErrorFun.java} | 47 ++++---- ...zeFun.java => GLFWFramebufferSizeFun.java} | 31 ++--- ...WJoystickFun.java => GLFWJoystickFun.java} | 32 ++--- .../{IGLFWKeyFun.java => GLFWKeyFun.java} | 31 ++--- ...LFWMonitorFun.java => GLFWMonitorFun.java} | 31 ++--- ...ButtonFun.java => GLFWMouseButtonFun.java} | 31 ++--- ...IGLFWScrollFun.java => GLFWScrollFun.java} | 31 ++--- ...wCloseFun.java => GLFWWindowCloseFun.java} | 31 ++--- ...un.java => GLFWWindowContentScaleFun.java} | 31 ++--- ...wFocusFun.java => GLFWWindowFocusFun.java} | 38 +++--- ...nifyFun.java => GLFWWindowIconifyFun.java} | 38 +++--- ...izeFun.java => GLFWWindowMaximizeFun.java} | 38 +++--- ...indowPosFun.java => GLFWWindowPosFun.java} | 35 +++--- ...reshFun.java => GLFWWindowRefreshFun.java} | 31 ++--- ...dowSizeFun.java => GLFWWindowSizeFun.java} | 31 ++--- 31 files changed, 379 insertions(+), 489 deletions(-) delete mode 100644 modules/overrungl.core/src/main/java/overrungl/internal/Checks.java rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWCharFun.java => GLFWCharFun.java} (59%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWCursorEnterFun.java => GLFWCursorEnterFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWCursorPosFun.java => GLFWCursorPosFun.java} (63%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWDropFun.java => GLFWDropFun.java} (63%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWErrorFun.java => GLFWErrorFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWFramebufferSizeFun.java => GLFWFramebufferSizeFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWJoystickFun.java => GLFWJoystickFun.java} (60%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWKeyFun.java => GLFWKeyFun.java} (66%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWMonitorFun.java => GLFWMonitorFun.java} (60%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWMouseButtonFun.java => GLFWMouseButtonFun.java} (65%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWScrollFun.java => GLFWScrollFun.java} (61%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowCloseFun.java => GLFWWindowCloseFun.java} (58%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowContentScaleFun.java => GLFWWindowContentScaleFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowFocusFun.java => GLFWWindowFocusFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowIconifyFun.java => GLFWWindowIconifyFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowMaximizeFun.java => GLFWWindowMaximizeFun.java} (62%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowPosFun.java => GLFWWindowPosFun.java} (59%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowRefreshFun.java => GLFWWindowRefreshFun.java} (59%) rename modules/overrungl.glfw/src/main/java/overrungl/glfw/{IGLFWWindowSizeFun.java => GLFWWindowSizeFun.java} (62%) diff --git a/modules/overrungl.core/src/main/java/overrungl/Addressable.java b/modules/overrungl.core/src/main/java/overrungl/Addressable.java index 71a6e577..587fdd00 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Addressable.java +++ b/modules/overrungl.core/src/main/java/overrungl/Addressable.java @@ -24,6 +24,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") @FunctionalInterface public interface Addressable { /** diff --git a/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java b/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java index 256d9380..c51606f2 100644 --- a/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java +++ b/modules/overrungl.core/src/main/java/overrungl/ArrayPointer.java @@ -24,6 +24,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public interface ArrayPointer extends Addressable { /** * {@return the count of the elements in this array} diff --git a/modules/overrungl.core/src/main/java/overrungl/Callback.java b/modules/overrungl.core/src/main/java/overrungl/Callback.java index f2083fd1..3436429b 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Callback.java +++ b/modules/overrungl.core/src/main/java/overrungl/Callback.java @@ -32,6 +32,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public interface Callback { /** * Gets the address with the given arena. diff --git a/modules/overrungl.core/src/main/java/overrungl/Pointer.java b/modules/overrungl.core/src/main/java/overrungl/Pointer.java index ff25835d..96c74e1b 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Pointer.java +++ b/modules/overrungl.core/src/main/java/overrungl/Pointer.java @@ -25,6 +25,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public class Pointer implements Addressable { /** * The pointer address. diff --git a/modules/overrungl.core/src/main/java/overrungl/Struct.java b/modules/overrungl.core/src/main/java/overrungl/Struct.java index 3cc7769d..b7f1a27d 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Struct.java +++ b/modules/overrungl.core/src/main/java/overrungl/Struct.java @@ -25,6 +25,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public class Struct extends Pointer { /** * The memory layout of this struct. diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java b/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java deleted file mode 100644 index dbff6bfa..00000000 --- a/modules/overrungl.core/src/main/java/overrungl/internal/Checks.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2023 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.internal; - -/** - * @author squid233 - * @since 0.1.0 - */ -public final class Checks { - public static void arraySize(byte[] arr, int size) { - if (arr == null) { - throw new IllegalArgumentException("Expected size " + size + ", got null"); - } - if (arr.length != size) { - throw new IllegalArgumentException("Expected size " + size + ", got " + arr.length); - } - } -} diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java b/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java index 7bfd1fd7..09bc87fe 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/Exceptions.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Overrun Organization + * Copyright (c) 2023-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,6 +22,7 @@ * @author squid233 * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public final class Exceptions { /** * {@link IllegalStateException} diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java index ecff6979..a37ae62c 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java @@ -97,16 +97,6 @@ public static String unboundPointerString(MemorySegment segment, int index) { return reinterpreting(segment, index, str -> MemoryUtil.strlen(str) + 1).getString(0); } - /** - * Converts the segment into a string. - * - * @param segment the segment - * @return the string - */ - public static String getString(MemorySegment segment) { - return segment.reinterpret(MemoryUtil.strlen(segment) + 1).getString(0); - } - /** * Generates a string for unknown token. * diff --git a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java index c9fdb7c8..7d4a40fc 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,6 +39,7 @@ * @see Configurations#DEBUG_STACK * @since 0.1.0 */ +@Deprecated(since = "0.1.0") public sealed class MemoryStack extends Pointer implements Arena { private static final boolean DEBUG = Configurations.DEBUG.get(); private static final boolean DEBUG_STACK = Configurations.DEBUG_STACK.get(); diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java index 134a1ca2..cc542346 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -19,7 +19,6 @@ import org.jetbrains.annotations.Nullable; import overrungl.internal.RuntimeHelper; import overrungl.util.MemoryStack; -import overrungl.util.MemoryUtil; import overrungl.util.value.Pair; import overrungl.util.value.Quad; import overrungl.util.value.Triplet; @@ -1204,8 +1203,8 @@ public static MemorySegment nsetErrorCallback(MemorySegment callback) { * @return The previously set callback, or {@link MemorySegment#NULL NULL} if no callback was set. * @see #nsetErrorCallback(MemorySegment) nsetErrorCallback */ - public static MemorySegment setErrorCallback(@Nullable IGLFWErrorFun callback) { - return nsetErrorCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL); + public static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { + return nsetErrorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** @@ -1694,7 +1693,7 @@ public static MemorySegment getMonitorUserPointer(MemorySegment monitor) { * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWmonitor* monitor, int event)}
* For more information about the callback parameters, see the - * {@link IGLFWMonitorFun function pointer type}. + * {@link GLFWMonitorFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -1715,8 +1714,8 @@ public static MemorySegment nsetMonitorCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetMonitorCallback(MemorySegment) nsetMonitorCallback */ - public static MemorySegment setMonitorCallback(@Nullable IGLFWMonitorFun callback) { - return nsetMonitorCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL); + public static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { + return nsetMonitorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** @@ -3427,7 +3426,7 @@ public static MemorySegment getWindowUserPointer(MemorySegment window) { * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int xpos, int ypos)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowPosFun function pointer type}. + * {@link GLFWWindowPosFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.remark Wayland: This callback will never be called, as there is no way for * an application to know its global position. @@ -3451,8 +3450,8 @@ public static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySe * library had not been initialized. * @see #nsetWindowPosCallback(MemorySegment, MemorySegment) nsetWindowPosCallback */ - public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable IGLFWWindowPosFun callback) { - return nsetWindowPosCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { + return nsetWindowPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3469,7 +3468,7 @@ public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int width, int height)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowSizeFun function pointer type}. + * {@link GLFWWindowSizeFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -3491,8 +3490,8 @@ public static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemoryS * library had not been initialized. * @see #nsetWindowSizeCallback(MemorySegment, MemorySegment) nsetWindowSizeCallback */ - public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable IGLFWWindowSizeFun callback) { - return nsetWindowSizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { + return nsetWindowSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3514,7 +3513,7 @@ public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullabl * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowCloseFun function pointer type}. + * {@link GLFWWindowCloseFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.remark macOS: Selecting Quit from the application menu will trigger the * close callback for all windows. @@ -3538,8 +3537,8 @@ public static MemorySegment nsetWindowCloseCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetWindowCloseCallback(MemorySegment, MemorySegment) nsetWindowCloseCallback */ - public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable IGLFWWindowCloseFun callback) { - return nsetWindowCloseCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { + return nsetWindowCloseCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3560,7 +3559,7 @@ public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullab * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window);}
* For more information about the callback parameters, see the - * {@link IGLFWWindowRefreshFun function pointer type}. + * {@link GLFWWindowRefreshFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -3582,8 +3581,8 @@ public static MemorySegment nsetWindowRefreshCallback(MemorySegment window, Memo * library had not been initialized. * @see #nsetWindowRefreshCallback(MemorySegment, MemorySegment) nsetWindowRefreshCallback */ - public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable IGLFWWindowRefreshFun callback) { - return nsetWindowRefreshCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { + return nsetWindowRefreshCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3605,7 +3604,7 @@ public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Null * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int focused)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowFocusFun function pointer type}. + * {@link GLFWWindowFocusFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -3627,8 +3626,8 @@ public static MemorySegment nsetWindowFocusCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetWindowFocusCallback(MemorySegment, MemorySegment) nsetWindowFocusCallback */ - public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable IGLFWWindowFocusFun callback) { - return nsetWindowFocusCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { + return nsetWindowFocusCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3644,7 +3643,7 @@ public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullab * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int iconified)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowIconifyFun function pointer type}. + * {@link GLFWWindowIconifyFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.remark Wayland: The XDG-shell protocol has no event for iconification, so * this callback will never be called. @@ -3668,8 +3667,8 @@ public static MemorySegment nsetWindowIconifyCallback(MemorySegment window, Memo * library had not been initialized. * @see #nsetWindowIconifyCallback(MemorySegment, MemorySegment) nsetWindowIconifyCallback */ - public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable IGLFWWindowIconifyFun callback) { - return nsetWindowIconifyCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { + return nsetWindowIconifyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3685,7 +3684,7 @@ public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Null * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int maximized)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowMaximizeFun function pointer type}. + * {@link GLFWWindowMaximizeFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -3707,8 +3706,8 @@ public static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, Mem * library had not been initialized. * @see #nsetWindowMaximizeCallback(MemorySegment, MemorySegment) nsetWindowMaximizeCallback */ - public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable IGLFWWindowMaximizeFun callback) { - return nsetWindowMaximizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { + return nsetWindowMaximizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3724,7 +3723,7 @@ public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nul * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int width, int height)}
* For more information about the callback parameters, see the - * {@link IGLFWFramebufferSizeFun function pointer type}. + * {@link GLFWFramebufferSizeFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -3746,8 +3745,8 @@ public static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, Me * library had not been initialized. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) nsetFramebufferSizeCallback */ - public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable IGLFWFramebufferSizeFun callback) { - return nsetFramebufferSizeCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { + return nsetFramebufferSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3763,7 +3762,7 @@ public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nu * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, float xscale, float yscale)}
* For more information about the callback parameters, see the - * {@link IGLFWWindowContentScaleFun function pointer type}. + * {@link GLFWWindowContentScaleFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale @@ -3786,8 +3785,8 @@ public static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, * library had not been initialized. * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) nsetWindowContentScaleCallback */ - public static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable IGLFWWindowContentScaleFun callback) { - return nsetWindowContentScaleCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { + return nsetWindowContentScaleCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4512,7 +4511,7 @@ public static void setCursor(MemorySegment window, MemorySegment cursor) { * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int key, int scancode, int action, int mods)}
* For more information about the callback parameters, see the - * {@link IGLFWKeyFun function pointer type}. + * {@link GLFWKeyFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4534,8 +4533,8 @@ public static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetKeyCallback(MemorySegment, MemorySegment) nsetKeyCallback */ - public static MemorySegment setKeyCallback(MemorySegment window, @Nullable IGLFWKeyFun callback) { - return nsetKeyCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { + return nsetKeyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4563,7 +4562,7 @@ public static MemorySegment setKeyCallback(MemorySegment window, @Nullable IGLFW * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, unsigned int codepoint)}
* For more information about the callback parameters, see the - * {@link IGLFWCharFun function pointer type}. + * {@link GLFWCharFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4585,8 +4584,8 @@ public static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetCharCallback(MemorySegment, MemorySegment) nsetCharCallback */ - public static MemorySegment setCharCallback(MemorySegment window, @Nullable IGLFWCharFun callback) { - return nsetCharCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { + return nsetCharCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4608,7 +4607,7 @@ public static MemorySegment setCharCallback(MemorySegment window, @Nullable IGLF * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int button, int action, int mods)}
* For more information about the callback parameters, see the - * {@link IGLFWMouseButtonFun function pointer type}. + * {@link GLFWMouseButtonFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4630,8 +4629,8 @@ public static MemorySegment nsetMouseButtonCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetMouseButtonCallback(MemorySegment, MemorySegment) nsetMouseButtonCallback */ - public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable IGLFWMouseButtonFun callback) { - return nsetMouseButtonCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { + return nsetMouseButtonCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4649,7 +4648,7 @@ public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullab * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, double xpos, double ypos);}
* For more information about the callback parameters, see the - * {@link IGLFWCursorPosFun function pointer type}. + * {@link GLFWCursorPosFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4671,8 +4670,8 @@ public static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySe * library had not been initialized. * @see #nsetCursorPosCallback(MemorySegment, MemorySegment) nsetCursorPosCallback */ - public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable IGLFWCursorPosFun callback) { - return nsetCursorPosCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { + return nsetCursorPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4689,7 +4688,7 @@ public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int entered)}
* For more information about the callback parameters, see the - * {@link IGLFWCursorEnterFun function pointer type}. + * {@link GLFWCursorEnterFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4711,8 +4710,8 @@ public static MemorySegment nsetCursorEnterCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetCursorEnterCallback(MemorySegment, MemorySegment) nsetCursorEnterCallback */ - public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable IGLFWCursorEnterFun callback) { - return nsetCursorEnterCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { + return nsetCursorEnterCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4732,7 +4731,7 @@ public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullab * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, double xoffset, double yoffset)}
* For more information about the callback parameters, see the - * {@link IGLFWScrollFun function pointer type}. + * {@link GLFWScrollFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -4754,8 +4753,8 @@ public static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegme * library had not been initialized. * @see #nsetScrollCallback(MemorySegment, MemorySegment) nsetScrollCallback */ - public static MemorySegment setScrollCallback(MemorySegment window, @Nullable IGLFWScrollFun callback) { - return nsetScrollCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { + return nsetScrollCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4776,7 +4775,7 @@ public static MemorySegment setScrollCallback(MemorySegment window, @Nullable IG * library had not been initialized. * @glfw.callback_signature
{@code void function_name(GLFWwindow* window, int path_count, const char* paths[])}
* For more information about the callback parameters, see the - * {@link IGLFWDropFun function pointer type}. + * {@link GLFWDropFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.remark Wayland: File drop is currently unimplemented. * @glfw.thread_safety This function must only be called from the main thread. @@ -4799,8 +4798,8 @@ public static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetDropCallback(MemorySegment, MemorySegment) nsetDropCallback */ - public static MemorySegment setDropCallback(MemorySegment window, @Nullable IGLFWDropFun callback) { - return nsetDropCallback(window, callback != null ? callback.address(GLFWCallbacks.create(window)) : MemorySegment.NULL); + public static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { + return nsetDropCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -5215,7 +5214,7 @@ public static boolean joystickIsGamepad(int jid) { * library had not been initialized. * @glfw.callback_signature
{@code void function_name(int jid, int event)}
* For more information about the callback parameters, see the - * {@link IGLFWJoystickFun function pointer type}. + * {@link GLFWJoystickFun function pointer type}. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ @@ -5236,8 +5235,8 @@ public static MemorySegment nsetJoystickCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetJoystickCallback(MemorySegment) nsetJoystickCallback */ - public static MemorySegment setJoystickCallback(@Nullable IGLFWJoystickFun callback) { - return nsetJoystickCallback(callback != null ? callback.address(Arena.global()) : MemorySegment.NULL); + public static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { + return nsetJoystickCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java index 05e1b152..8aebde72 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -18,8 +18,8 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * The GLFW window callbacks. @@ -28,7 +28,7 @@ * @since 0.1.0 */ public final class GLFWCallbacks { - private static final Map ARENA_MAP = new HashMap<>(); + private static final Map ARENA_MAP = new ConcurrentHashMap<>(); private GLFWCallbacks() { //no instance @@ -42,7 +42,7 @@ private GLFWCallbacks() { * @return the arena. */ public static Arena create(MemorySegment window) { - return ARENA_MAP.computeIfAbsent(window, k -> Arena.ofConfined()); + return ARENA_MAP.computeIfAbsent(window, _ -> Arena.ofConfined()); } /** @@ -52,6 +52,22 @@ public static Arena create(MemorySegment window) { */ public static void free(MemorySegment window) { if (ARENA_MAP.containsKey(window)) { + GLFW.setCharCallback(window, null); + GLFW.setCursorEnterCallback(window, null); + GLFW.setCursorPosCallback(window, null); + GLFW.setDropCallback(window, null); + GLFW.setFramebufferSizeCallback(window, null); + GLFW.setKeyCallback(window, null); + GLFW.setMouseButtonCallback(window, null); + GLFW.setScrollCallback(window, null); + GLFW.setWindowCloseCallback(window, null); + GLFW.setWindowContentScaleCallback(window, null); + GLFW.setWindowFocusCallback(window, null); + GLFW.setWindowIconifyCallback(window, null); + GLFW.setWindowMaximizeCallback(window, null); + GLFW.setWindowPosCallback(window, null); + GLFW.setWindowRefreshCallback(window, null); + GLFW.setWindowSizeCallback(window, null); ARENA_MAP.remove(window).close(); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java index 63b9cb01..5b15487b 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for Unicode character callbacks. * A Unicode character callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCharFun::invoke) - * void functionName(MemorySegment window, int codepoint); + * void functionName(MemorySegment window, int codepoint); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCharFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCharFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for Unicode character callbacks. @@ -48,15 +45,11 @@ public interface IGLFWCharFun extends Callback { * @param window The window that received the event. * @param codepoint The Unicode code point of the character. */ + @Stub void invoke(MemorySegment window, int codepoint); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCharFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java index 69e7219a..169e6bce 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for cursor enter/leave callbacks. * A cursor enter/leave callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCursorEnterFun::invoke) - * void functionName(MemorySegment window, boolean entered); + * void functionName(MemorySegment window, boolean entered); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCursorEnterFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCursorEnterFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for cursor enter/leave callbacks. @@ -51,17 +48,20 @@ public interface IGLFWCursorEnterFun extends Callback { */ void invoke(MemorySegment window, boolean entered); + /** + * The function pointer type for cursor enter/leave callbacks. + * + * @param window The window that received the event. + * @param entered {@code true} if the cursor entered the window's content + * area, or {@code false} if it left it. + */ + @Stub default void ninvoke(MemorySegment window, int entered) { invoke(window, entered != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCursorEnterFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java similarity index 63% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java index 27dd7060..d8bba273 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for cursor position callbacks. A cursor * position callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCursorPosFun::invoke) - * void functionName(MemorySegment window, double xpos, double ypos); + * void functionName(MemorySegment window, double xpos, double ypos); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCursorPosFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCursorPosFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for cursor position callbacks. @@ -49,15 +46,11 @@ public interface IGLFWCursorPosFun extends Callback { * @param xpos The new cursor x-coordinate, relative to the left edge of the content area. * @param ypos The new cursor y-coordinate, relative to the top edge of the content area. */ + @Stub void invoke(MemorySegment window, double xpos, double ypos); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCursorPosFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java similarity index 63% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java index 6d26f956..2b13bc8c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,22 +16,17 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; import overrungl.internal.RuntimeHelper; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for path drop callbacks. A path drop * callback function has the following signature: - * {@snippet lang=java: - * @Invoker(IGLFWDropFun::invoke) - * void functionName(MemorySegment window, String[] paths); + * {@snippet lang = java: + * void functionName(MemorySegment window, String[] paths); // @link regex="functionName" target="#invoke" * } *

Pointer lifetime

* The path array and its strings are valid until the callback function returns. @@ -41,29 +36,34 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWDropFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWDropFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for path drop callbacks. * - * @param window The window that received the event. - * @param paths The UTF-8 encoded file and/or directory path names. + * @param window The window that received the event. + * @param paths The UTF-8 encoded file and/or directory path names. */ void invoke(MemorySegment window, String[] paths); + /** + * The function pointer type for path drop callbacks. + * + * @param window The window that received the event. + * @param pathCount The number of dropped paths. + * @param paths The UTF-8 encoded file and/or directory path names. + */ + @Stub default void ninvoke(MemorySegment window, int pathCount, MemorySegment paths) { invoke(window, RuntimeHelper.toUnboundedArray(paths, new String[pathCount])); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWDropFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java index a96b6c37..94794c3d 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorCallback.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -17,13 +17,12 @@ package overrungl.glfw; import overrungl.OverrunGL; -import overrungl.internal.Exceptions; import java.io.PrintStream; import java.util.function.Consumer; /** - * The {@linkplain IGLFWErrorFun GLFW error callback} creator. + * The {@linkplain GLFWErrorFun GLFW error callback} creator. * * @author squid233 * @since 0.1.0 @@ -34,48 +33,48 @@ private GLFWErrorCallback() { } /** - * {@return a {@link IGLFWErrorFun} instance that throws an {@link IllegalStateException} when an error occurs} + * {@return a {@link GLFWErrorFun } instance that throws an {@link IllegalStateException} when an error occurs} */ - public static IGLFWErrorFun createThrow() { + public static GLFWErrorFun createThrow() { return (errorCode, description) -> { - throw Exceptions.ISE. "GLFW error [0x\{ Integer.toHexString(errorCode) }]: \{ description }" ; + throw new IllegalStateException(STR."GLFW error [0x\{Integer.toHexString(errorCode)}]: \{description}"); }; } /** - * {@return a {@link IGLFWErrorFun} instance that logs a message when an error occurs} + * {@return a {@link GLFWErrorFun } instance that logs a message when an error occurs} * * @param logger the logger function. */ - public static IGLFWErrorFun createLog(Consumer logger) { + public static GLFWErrorFun createLog(Consumer logger) { return (errorCode, description) -> { var sb = new StringBuilder(512); - sb.append(STR. "[OverrunGL] GLFW \{ GLFW.getErrorString(errorCode) } error: \{ description }\n" ); + sb.append(STR."[OverrunGL] GLFW \{GLFW.getErrorString(errorCode)} error: \{description}\n"); var stack = Thread.currentThread().getStackTrace(); for (int i = 3; i < stack.length; i++) { - sb.append(STR. " at \{ stack[i] }\n" ); + sb.append(STR." at \{stack[i]}\n"); } logger.accept(sb.toString()); }; } /** - * {@return a {@link IGLFWErrorFun} instance that prints a message when an error occurs} + * {@return a {@link GLFWErrorFun } instance that prints a message when an error occurs} * * @param stream the logger stream. * @see #createPrint() */ - public static IGLFWErrorFun createPrint(PrintStream stream) { + public static GLFWErrorFun createPrint(PrintStream stream) { return createLog(stream::println); } /** - * {@return a {@link IGLFWErrorFun} instance that prints a message to + * {@return a {@link GLFWErrorFun } instance that prints a message to * {@link OverrunGL#apiLogger() default library logger} when an error occurs} * * @see #createPrint(PrintStream) */ - public static IGLFWErrorFun createPrint() { + public static GLFWErrorFun createPrint() { return createLog(OverrunGL.apiLogger()); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java index b7932e54..93a333ed 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWErrorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,23 +16,19 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Unmarshal; +import overrun.marshal.Upcall; +import overrun.marshal.gen.SizedSeg; import overrungl.NativeType; -import overrungl.internal.RuntimeHelper; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for error callbacks. An error callback * function has the following signature: - * {@snippet lang=java: - * @Invoker(IGLFWErrorFun::invoke) - * void callbackName(int errorCode, String description); + * {@snippet lang = java: + * void callbackName(int errorCode, String description); // @link regex="functionName" target="#invoke" * } *

Pointer lifetime

* The error description string is valid until the callback @@ -43,9 +39,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWErrorFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWErrorFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for error callbacks. @@ -55,8 +53,16 @@ public interface IGLFWErrorFun extends Callback { */ void invoke(int errorCode, String description); - default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) { - invoke(errorCode, RuntimeHelper.getString(description)); + /** + * The function pointer type for error callbacks. + * + * @param errorCode An error code. + * Future releases may add more error codes. + * @param description A UTF-8 encoded string describing the error. + */ + @Stub + default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarshal.STR_SIZE) MemorySegment description) { + invoke(errorCode, Unmarshal.unmarshalAsString(description)); } /** @@ -69,12 +75,7 @@ default MemorySegment set() { } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWErrorFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java index 5078dbd8..2dffce53 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for framebuffer size callbacks. * A framebuffer size callback function has the following signature: * {@snippet : - * @Invoker(IGLFWFramebufferSizeFun::invoke) - * void functionName(MemorySegment window, int width, int height); + * void functionName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWFramebufferSizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWFramebufferSizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for framebuffer size callbacks. @@ -49,15 +46,11 @@ public interface IGLFWFramebufferSizeFun extends Callback { * @param width The new width, in pixels, of the framebuffer. * @param height The new height, in pixels, of the framebuffer. */ + @Stub void invoke(MemorySegment window, int width, int height); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWFramebufferSizeFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java similarity index 60% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java index 169c97b7..fdfc0b20 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,20 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; /** * This is the function pointer type for joystick configuration callbacks. * A joystick configuration callback function has the following signature: * {@snippet : - * @Invoker(IGLFWJoystickFun::invoke) - * void functionName(int jid, int event); + * void functionName(int jid, int event); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -37,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWJoystickFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWJoystickFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for joystick configuration callbacks. @@ -48,15 +46,11 @@ public interface IGLFWJoystickFun extends Callback { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ + @Stub void invoke(int jid, int event); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWJoystickFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java similarity index 66% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java index 06b27857..bd87b937 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for keyboard key callbacks. A keyboard * key callback function has the following signature: * {@snippet : - * @Invoker(IGLFWKeyFun::invoke) - * void functionName(MemorySegment window, int key, int scancode, int action, int mods); + * void functionName(MemorySegment window, int key, int scancode, int action, int mods); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWKeyFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWKeyFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for keyboard key callbacks. @@ -53,15 +50,11 @@ public interface IGLFWKeyFun extends Callback { * @param mods Bit field describing which modifier keys * were held down. */ + @Stub void invoke(MemorySegment window, int key, int scancode, int action, int mods); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWKeyFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java similarity index 60% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java index f4302297..d8e36873 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for monitor configuration callbacks. * A monitor callback function has the following signature: * {@snippet : - * @Invoker(IGLFWMonitorFun::invoke) - * void functionName(MemorySegment monitor, int event); + * void functionName(MemorySegment monitor, int event); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWMonitorFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWMonitorFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for monitor configuration callbacks. @@ -49,15 +46,11 @@ public interface IGLFWMonitorFun extends Callback { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ + @Stub void invoke(MemorySegment monitor, int event); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWMonitorFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java similarity index 65% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java index e9349481..970d5a83 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for mouse button callback functions. * A mouse button callback function has the following signature: * {@snippet : - * @Invoker(IGLFWMouseButtonFun::invoke) - * void functionName(MemorySegment window, int button, int action, int mods); + * void functionName(MemorySegment window, int button, int action, int mods); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWMouseButtonFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWMouseButtonFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for mouse button callbacks. @@ -50,15 +47,11 @@ public interface IGLFWMouseButtonFun extends Callback { * @param action One of {@code PRESS} or {@code RELEASE}. Future releases may add more actions. * @param mods Bit field describing which modifier keys were held down. */ + @Stub void invoke(MemorySegment window, int button, int action, int mods); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWMouseButtonFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java similarity index 61% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java index 2d8a4564..ee483d7e 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for scroll callbacks. A scroll callback * function has the following signature: * {@snippet : - * @Invoker(IGLFWScrollFun::invoke) - * void functionName(MemorySegment window, double xoffset, double yoffset); + * void functionName(MemorySegment window, double xoffset, double yoffset); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWScrollFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWScrollFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for scroll callbacks. @@ -49,15 +46,11 @@ public interface IGLFWScrollFun extends Callback { * @param xoffset The scroll offset along the x-axis. * @param yoffset The scroll offset along the y-axis. */ + @Stub void invoke(MemorySegment window, double xoffset, double yoffset); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWScrollFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java similarity index 58% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java index e4747f44..128d295c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window close callbacks. A window * close callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowCloseFun::invoke) - * void functionName(MemorySegment window); + * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,24 +33,22 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowCloseFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowCloseFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window close callbacks. * * @param window The window that the user attempted to close. */ + @Stub void invoke(MemorySegment window); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowCloseFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java index f640da18..b82ca1a3 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window content scale callbacks. * A window content scale callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowContentScaleFun::invoke) - * void functionName(MemorySegment window, float xscale, float yscale); + * void functionName(MemorySegment window, float xscale, float yscale); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowContentScaleFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowContentScaleFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window content scale callbacks. @@ -49,15 +46,11 @@ public interface IGLFWWindowContentScaleFun extends Callback { * @param xscale The new x-axis content scale of the window. * @param yscale The new y-axis content scale of the window. */ + @Stub void invoke(MemorySegment window, float xscale, float yscale); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowContentScaleFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java index 3b782ba2..be237d00 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window focus callbacks. A window * focus callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowFocusFun::invoke) - * void functionName(MemorySegment window, boolean focused); + * void functionName(MemorySegment window, boolean focused); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowFocusFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowFocusFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window focus callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowFocusFun extends Callback { */ void invoke(MemorySegment window, boolean focused); + /** + * The function pointer type for window focus callbacks. + * + * @param window The window that gained or lost input focus. + * @param focused {@code true} if the window was given input focus, or + * {@code false} if it lost it. + */ + @Stub default void ninvoke(MemorySegment window, int focused) { invoke(window, focused != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowFocusFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java index 2baa6750..34837046 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window iconify callbacks. A window * iconify callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowIconifyFun::invoke) - * void functionName(MemorySegment window, boolean iconified); + * void functionName(MemorySegment window, boolean iconified); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowIconifyFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowIconifyFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window iconify callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowIconifyFun extends Callback { */ void invoke(MemorySegment window, boolean iconified); + /** + * The function pointer type for window iconify callbacks. + * + * @param window The window that was iconified or restored. + * @param iconified {@code true} if the window was iconified, or + * {@code false} if it was restored. + */ + @Stub default void ninvoke(MemorySegment window, int iconified) { invoke(window, iconified != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowIconifyFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java index 8896c448..2d7f5b40 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window maximize callbacks. A window * maximize callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowMaximizeFun::invoke) - * void functionName(MemorySegment window, boolean maximized); + * void functionName(MemorySegment window, boolean maximized); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowMaximizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowMaximizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window maximize callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowMaximizeFun extends Callback { */ void invoke(MemorySegment window, boolean maximized); + /** + * The function pointer type for window maximize callbacks. + * + * @param window The window that was maximized or restored. + * @param maximized {@code true} if the window was maximized, or + * {@code false} if it was restored. + */ + @Stub default void ninvoke(MemorySegment window, int maximized) { invoke(window, maximized != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowMaximizeFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java index 3dd23e53..2d6c82c9 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** - * This is the function pointer type for window position callbacks.A window - * position callback function has the following signature: + * This is the function pointer type for window position callbacks. + * A window position callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowPosFun::invoke) - * void callbackName(MemorySegment window, int xpos, int ypos); + * void callbackName(MemorySegment window, int xpos, int ypos); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowPosFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowPosFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window position callbacks. @@ -51,15 +48,11 @@ public interface IGLFWWindowPosFun extends Callback { * @param ypos The new y-coordinate, in screen coordinates, of the * upper-left corner of the content area of the window. */ + @Stub void invoke(MemorySegment window, int xpos, int ypos); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowPosFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java index ab966963..f4c3776f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window content refresh callbacks. * A window content refresh callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowRefreshFun::invoke) - * void functionName(MemorySegment window); + * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,24 +33,22 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowRefreshFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowRefreshFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window content refresh callbacks. * * @param window The window whose content needs to be refreshed. */ + @Stub void invoke(MemorySegment window); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowRefreshFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java index 9bbb49c6..05b88a99 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window size callbacks. A window size * callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowSizeFun::invoke) - * void callbackName(MemorySegment window, int width, int height); + * void callbackName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowSizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowSizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window size callbacks. @@ -49,15 +46,11 @@ public interface IGLFWWindowSizeFun extends Callback { * @param width The new width, in screen coordinates, of the window. * @param height The new height, in screen coordinates, of the window. */ + @Stub void invoke(MemorySegment window, int width, int height); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowSizeFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } From acbd0bc2bc0f94c465e18fca63ddf1ada1d0193e Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:09:03 +0800 Subject: [PATCH 2/4] [GLFW] Rewrite GLFW structures, GLFWNative, GLFWVulkan --- gradle.properties | 4 +- .../overrungl/internal/RuntimeHelper.java | 3 + .../java/overrungl/util/DebugAllocator.java | 5 +- .../src/main/java/overrungl/glfw/GLFW.java | 26 +- .../java/overrungl/glfw/GLFWGamepadState.java | 93 ++--- .../java/overrungl/glfw/GLFWGammaRamp.java | 199 ++-------- .../main/java/overrungl/glfw/GLFWImage.java | 251 ++----------- .../main/java/overrungl/glfw/GLFWNative.java | 341 ++++++------------ .../main/java/overrungl/glfw/GLFWVidMode.java | 234 +++--------- .../main/java/overrungl/glfw/GLFWVulkan.java | 76 ++-- .../src/main/java/overrungl/glfw/Handles.java | 9 +- .../glfw/StructHandleSizedByteArray.java | 87 +++++ .../glfw/StructHandleSizedFloatArray.java | 87 +++++ .../overrungl/demo/glfw/GLFWJoystickTest.java | 4 +- .../demo/glfw/GLFWWindowIconTest.java | 9 +- 15 files changed, 479 insertions(+), 949 deletions(-) create mode 100644 modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java create mode 100644 modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java diff --git a/gradle.properties b/gradle.properties index ecfbe7ee..f0013a91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,5 @@ jdkEnablePreview=true jdkEarlyAccessDoc=jdk22 kotlinTargetJdkVersion=21 -overrunMarshalVersion=0.1.0-alpha.9-jdk22 +overrunMarshalVersion=0.1.0-alpha.10-jdk22 overrunPlatformVersion=1.0.0 - -cLibraryVersion=0.1.0.0 diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java index a37ae62c..3eb0dc38 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java @@ -60,6 +60,9 @@ public final class RuntimeHelper { public static final boolean CHECKS = Configurations.CHECKS.get(); private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); private static final Map CANONICAL_LAYOUTS = LINKER.canonicalLayouts(); + /** + * Some canonical layouts + */ public static final MemoryLayout LONG = CANONICAL_LAYOUTS.get("long"), SIZE_T = CANONICAL_LAYOUTS.get("size_t"), WCHAR_T = CANONICAL_LAYOUTS.get("wchar_t"); diff --git a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java index 62d44085..1fe6bf5c 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java @@ -20,7 +20,6 @@ import org.jetbrains.annotations.Nullable; import overrungl.Configurations; import overrungl.OverrunGL; -import overrungl.internal.Exceptions; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -99,7 +98,7 @@ private static void trackAbort(long address, Allocation allocationOld, Allocatio trackAbortPrint(allocationOld, "Old", addressHex); trackAbortPrint(allocationNew, "New", addressHex); - throw Exceptions.ISE."The memory address specified is already being tracked: 0x\{addressHex}"; + throw new IllegalStateException(STR."The memory address specified is already being tracked: 0x\{addressHex}"); } private static void trackAbortPrint(Allocation allocation, String name, String address) { @@ -138,7 +137,7 @@ static long untrack(long address) { private static void untrackAbort(long address) { String addressHex = Long.toHexString(address).toUpperCase(); - throw Exceptions.ISE."The memory address specified is not being tracked: 0x\{addressHex}"; + throw new IllegalStateException(STR."The memory address specified is not being tracked: 0x\{addressHex}"); } private record Allocation(long address, long size, long threadId, @Nullable Object[] stacktrace) { diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java index cc542346..f3647013 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -1757,7 +1757,7 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment * error occurred. * @see #ngetVideoModes(MemorySegment, MemorySegment) ngetVideoModes */ - public static @Nullable GLFWVidMode.Buffer getVideoModes(MemorySegment monitor) { + public static @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1765,7 +1765,7 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment var pModes = ngetVideoModes(monitor, pCount); return RuntimeHelper.isNullptr(pModes) ? null : - new GLFWVidMode.Buffer(pModes, pCount.get(JAVA_INT, 0)); + new GLFWVidMode(pModes, pCount.get(JAVA_INT, 0)); } finally { stack.setPointer(stackPointer); } @@ -1931,7 +1931,7 @@ public static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { * @see #nsetGammaRamp(MemorySegment, MemorySegment) nsetGammaRamp */ public static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { - nsetGammaRamp(monitor, ramp.address()); + nsetGammaRamp(monitor, ramp.segment()); } /** @@ -2395,11 +2395,11 @@ public static void nsetWindowIcon(MemorySegment window, int count, MemorySegment * count is zero. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, int count, GLFWImage.Buffer images) { + public static void setWindowIcon(MemorySegment window, int count, GLFWImage images) { if (images == null || count == 0) { nsetWindowIcon(window, 0, MemorySegment.NULL); } else { - nsetWindowIcon(window, count, images.address()); + nsetWindowIcon(window, count, images.segment()); } } @@ -2411,12 +2411,8 @@ public static void setWindowIcon(MemorySegment window, int count, GLFWImage.Buff * revert to the default window icon. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage.Buffer images) { - if (images == null) { - nsetWindowIcon(window, 0, MemorySegment.NULL); - } else { - setWindowIcon(window, (int) Math.min(images.elementCount(), Integer.MAX_VALUE), images); - } + public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { + setWindowIcon(window, images == null ? 0 : Math.toIntExact(images.elementCount()), images); } /** @@ -4401,7 +4397,7 @@ public static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yho * @see #ncreateCursor(MemorySegment, int, int) ncreateCursor */ public static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { - return ncreateCursor(image.address(), xhot, yhot); + return ncreateCursor(image.segment(), xhot, yhot); } /** @@ -5384,7 +5380,7 @@ public static boolean ngetGamepadState(int jid, MemorySegment state) { * @see #ngetGamepadState(int, MemorySegment) ngetGamepadState */ public static boolean getGamepadState(int jid, GLFWGamepadState state) { - return ngetGamepadState(jid, state.address()); + return ngetGamepadState(jid, state.segment()); } /** @@ -5767,7 +5763,7 @@ public static boolean extensionSupported(String extension) { * without a current context will cause a {@link #NO_CURRENT_CONTEXT} error. *

* This function does not apply to Vulkan. If you are rendering with Vulkan, - * see {@link GLFWVulkan#nglfwGetInstanceProcAddress(MemorySegment, MemorySegment) glfwGetInstanceProcAddress}, + * see {@link GLFWVulkan#ngetInstanceProcAddress(MemorySegment, MemorySegment) glfwGetInstanceProcAddress}, * {@code vkGetInstanceProcAddr} and {@code vkGetDeviceProcAddr} instead. * * @param procName The ASCII encoded name of the function. @@ -5823,7 +5819,7 @@ public static MemorySegment getProcAddress(String procName) { * surface creation or even instance creation is possible. Call * {@link #ngetRequiredInstanceExtensions getRequiredInstanceExtensions} to check whether the * extensions necessary for Vulkan surface creation are available and - * {@link GLFWVulkan#glfwGetPhysicalDevicePresentationSupport glfwGetPhysicalDevicePresentationSupport} + * {@link GLFWVulkan#getPhysicalDevicePresentationSupport glfwGetPhysicalDevicePresentationSupport} * to check whether a queue family of a physical device supports image presentation. * * @return {@code true} if Vulkan is minimally available, or {@code false} diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java index 0ff1095a..a7133d8b 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,81 +16,78 @@ package overrungl.glfw; -import overrungl.Struct; +import overrun.marshal.struct.Struct; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; /** * This describes the input state of a gamepad. *

Layout

*

  * struct GLFWgamepadstate {
- *     unsigned char {@link #buttons() buttons}[15];
- *     float {@link #axes() axes}[6];
+ *     unsigned char {@link #buttons}[15];
+ *     float {@link #axes}[6];
  * }
* * @author squid233 * @since 0.1.0 */ public final class GLFWGamepadState extends Struct { - /** - * The struct member layout. - */ - public static final SequenceLayout - BUTTONS_LAYOUT = MemoryLayout.sequenceLayout(15, ValueLayout.JAVA_BYTE).withName("buttons"), - AXES_LAYOUT = MemoryLayout.sequenceLayout(6, ValueLayout.JAVA_FLOAT).withName("axes"); /** * The struct layout. */ public static final StructLayout LAYOUT = MemoryLayout.structLayout( - BUTTONS_LAYOUT, - MemoryLayout.paddingLayout(8), // padding needed. will FFM API adds padding automatically in the future? - AXES_LAYOUT + MemoryLayout.sequenceLayout(15, ValueLayout.JAVA_BYTE).withName("buttons"), + MemoryLayout.paddingLayout(1L), + MemoryLayout.sequenceLayout(6, ValueLayout.JAVA_FLOAT).withName("axes") ); - private static final VarHandle - pButtons = LAYOUT.varHandle(PathElement.groupElement("buttons"), PathElement.sequenceElement()), - pAxes = LAYOUT.varHandle(PathElement.groupElement("axes"), PathElement.sequenceElement()); + /** + * The states of each gamepad button, + * {@link GLFW#PRESS} or {@link GLFW#RELEASE}. + */ + public final StructHandleSizedByteArray buttons = StructHandleSizedByteArray.of(this, "buttons"); + /** + * The states of each gamepad axis, + * in the range -1.0 to 1.0 inclusive. + */ + public final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(this, "axes"); /** - * Create a {@code GLFWgamepadstate} instance. + * Creates a struct with the given layout. * - * @param address the address. + * @param segment the segment + * @param elementCount the element count */ - public GLFWGamepadState(MemorySegment address) { - super(address, LAYOUT); + public GLFWGamepadState(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * {@return the elements size of this struct in bytes} + * Allocates a struct with the given layout. + * + * @param allocator the allocator + * @param elementCount the element count */ - public static long sizeof() { - return LAYOUT.byteSize(); + public GLFWGamepadState(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Creates a {@code GLFWgamepadstate} instance with the given allocator. + * Creates a struct with the given layout. * - * @param allocator the allocator - * @return the instance + * @param segment the segment */ - public static GLFWGamepadState create(SegmentAllocator allocator) { - return new GLFWGamepadState(allocator.allocate(LAYOUT)); + public GLFWGamepadState(MemorySegment segment) { + super(segment, LAYOUT); } /** - * Gets the button state array. + * Allocates a struct with the given layout. * - * @return The states of each gamepad button, - * {@code PRESS} or {@code RELEASE}. + * @param allocator the allocator */ - public byte[] buttons() { - byte[] arr = new byte[15]; - for (int i = 0; i < arr.length; i++) { - arr[i] = (byte) pButtons.get(segment(), (long) i); - } - return arr; + public GLFWGamepadState(SegmentAllocator allocator) { + super(allocator, LAYOUT); } /** @@ -100,21 +97,7 @@ public byte[] buttons() { * @return the state, {@code PRESS} or {@code RELEASE} */ public boolean button(int index) { - return (byte) pButtons.get(segment(), (long) index) == GLFW.PRESS; - } - - /** - * Gets the axe state array. - * - * @return The states of each gamepad axis, - * in the range -1.0 to 1.0 inclusive. - */ - public float[] axes() { - float[] arr = new float[6]; - for (int i = 0; i < arr.length; i++) { - arr[i] = (float) pAxes.get(segment(), (long) i); - } - return arr; + return buttons.get(index) == GLFW.PRESS; } /** @@ -124,6 +107,6 @@ public float[] axes() { * @return the state, in the range -1.0 to 1.0 inclusive */ public float axe(int index) { - return (float) pAxes.get(segment(), (long) index); + return axes.get(index); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java index 75d7eb81..85d8aae2 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java @@ -16,11 +16,12 @@ package overrungl.glfw; -import overrungl.internal.RuntimeHelper; -import overrungl.Struct; +import overrun.marshal.Marshal; +import overrun.marshal.Unmarshal; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; import java.lang.foreign.*; -import java.lang.invoke.VarHandle; import static java.lang.foreign.ValueLayout.*; @@ -29,9 +30,9 @@ *

Layout

*

  * struct GLFWgammaramp {
- *     unsigned short* {@link #red() red};
- *     unsigned short* {@link #green() green};
- *     unsigned short* {@link #blue() blue};
+ *     unsigned short* {@link #red};
+ *     unsigned short* {@link #green};
+ *     unsigned short* {@link #blue};
  *     unsigned int {@link #size};
  * }
* @@ -41,7 +42,7 @@ * @since 0.1.0 */ public final class GLFWGammaRamp extends Struct { - private static final AddressLayout SHORT_ARRAY = ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Long.MAX_VALUE / JAVA_SHORT.byteSize(), JAVA_SHORT)); + private static final AddressLayout SHORT_ARRAY = ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, JAVA_SHORT)); /** * The struct layout. */ @@ -51,190 +52,58 @@ public final class GLFWGammaRamp extends Struct { SHORT_ARRAY.withName("blue"), JAVA_INT.withName("size") ); - private static final VarHandle - ppRed = LAYOUT.varHandle(PathElement.groupElement("red")), - ppGreen = LAYOUT.varHandle(PathElement.groupElement("green")), - ppBlue = LAYOUT.varHandle(PathElement.groupElement("blue")), - pRed = LAYOUT.varHandle(PathElement.groupElement("red"), PathElement.dereferenceElement(), PathElement.sequenceElement()), - pGreen = LAYOUT.varHandle(PathElement.groupElement("green"), PathElement.dereferenceElement(), PathElement.sequenceElement()), - pBlue = LAYOUT.varHandle(PathElement.groupElement("blue"), PathElement.dereferenceElement(), PathElement.sequenceElement()), - pSize = LAYOUT.varHandle(PathElement.groupElement("size")); - - /** - * Create a {@code GLFWgammaramp const} instance. - * - * @param address the address. - */ - public GLFWGammaRamp(MemorySegment address) { - super(address, LAYOUT); - } - - /** - * {@return the elements size of this struct in bytes} - */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - - /** - * Creates a {@code GLFWgammaramp} instance with the given allocator. - * - * @param allocator the allocator - * @return the instance - */ - public static GLFWGammaRamp create(SegmentAllocator allocator) { - return new GLFWGammaRamp(allocator.allocate(LAYOUT)); - } - - /** - * Sets the red value array. - * - * @param allocator the allocator of the array. - * @param reds the array - * @return this - */ - public GLFWGammaRamp red(SegmentAllocator allocator, short[] reds) { - ppRed.set(segment(), allocator.allocateFrom(JAVA_SHORT, reds)); - return this; - } - - /** - * Sets the green value array. - * - * @param allocator the allocator of the array. - * @param greens the array - * @return this - */ - public GLFWGammaRamp green(SegmentAllocator allocator, short[] greens) { - ppGreen.set(segment(), allocator.allocateFrom(JAVA_SHORT, greens)); - return this; - } - - /** - * Sets the blue value array. - * - * @param allocator the allocator of the array. - * @param blues the array - * @return this - */ - public GLFWGammaRamp blue(SegmentAllocator allocator, short[] blues) { - ppBlue.set(segment(), allocator.allocateFrom(JAVA_SHORT, blues)); - return this; - } - - /** - * Sets the size of arrays. - * - * @param size The number of elements in each array. - * @return this - */ - public GLFWGammaRamp size(int size) { - pSize.set(segment(), size); - return this; - } - - /** - * Gets a red value at the given index. - * - * @param index the index - * @return the red value - */ - public short red(int index) { - return (short) pRed.get(segment(), (long) index); - } - - /** - * Gets a green value at the given index. - * - * @param index the index - * @return the green value - */ - public short green(int index) { - return (short) pGreen.get(segment(), (long) index); - } - /** - * Gets a blue value at the given index. - * - * @param index the index - * @return the blue value + * An array of value describing the response of the red channel. */ - public short blue(int index) { - return (short) pBlue.get(segment(), (long) index); - } - + public final StructHandle.Array red = StructHandle.ofArray(this, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** - * {@return the red value array} - * - * @param size the array size + * An array of value describing the response of the green channel. */ - public short[] reds(int size) { - return RuntimeHelper.toArray(nred(), new short[size]); - } - + public final StructHandle.Array green = StructHandle.ofArray(this, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** - * {@return the green value array} - * - * @param size the array size + * An array of value describing the response of the blue channel. */ - public short[] greens(int size) { - return RuntimeHelper.toArray(ngreen(), new short[size]); - } - + public final StructHandle.Array blue = StructHandle.ofArray(this, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** - * {@return the blue value array} - * - * @param size the array size + * The number of elements in each array. */ - public short[] blues(int size) { - return RuntimeHelper.toArray(nblue(), new short[size]); - } + public final StructHandle.Int size = StructHandle.ofInt(this, "size"); /** - * Gets the red value array. + * Creates a struct with the given layout. * - * @return An array of value describing the response of the red channel. + * @param segment the segment + * @param elementCount the element count */ - public short[] red() { - return reds(size()); + public GLFWGammaRamp(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * Gets the green value array. + * Allocates a struct with the given layout. * - * @return An array of value describing the response of the green channel. + * @param allocator the allocator + * @param elementCount the element count */ - public short[] green() { - return greens(size()); + public GLFWGammaRamp(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Gets the blue value array. + * Creates a struct with the given layout. * - * @return An array of value describing the response of the blue channel. + * @param segment the segment */ - public short[] blue() { - return blues(size()); + public GLFWGammaRamp(MemorySegment segment) { + super(segment, LAYOUT); } /** - * Gets the arrays size. + * Allocates a struct with the given layout. * - * @return The number of elements in each array. + * @param allocator the allocator */ - public int size() { - return (int) pSize.get(segment()); - } - - public MemorySegment nred() { - return (MemorySegment) ppRed.get(segment()); - } - - public MemorySegment ngreen() { - return (MemorySegment) ppGreen.get(segment()); - } - - public MemorySegment nblue() { - return (MemorySegment) ppBlue.get(segment()); + public GLFWGammaRamp(SegmentAllocator allocator) { + super(allocator, LAYOUT); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java index 3fc1ad19..b9136a8f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java @@ -16,15 +16,10 @@ package overrungl.glfw; -import overrungl.ArrayPointer; -import overrungl.Struct; -import overrungl.internal.RuntimeHelper; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; - -import static java.lang.foreign.ValueLayout.*; /** * This describes a single 2D image. See the documentation for each related @@ -32,251 +27,71 @@ *

Layout

*

  * struct GLFWimage {
- *     int {@link #width() width};
- *     int {@link #height() height};
- *     unsigned char* {@link #pixels() pixels};
+ *     int {@link #width};
+ *     int {@link #height};
+ *     unsigned char* {@link #pixels};
  * }
* * @author squid233 * @since 0.1.0 */ -public sealed class GLFWImage extends Struct { +public final class GLFWImage extends Struct { /** * The struct layout. */ public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_INT.withName("width"), - JAVA_INT.withName("height"), - ADDRESS.withTargetLayout(RuntimeHelper.ADDRESS_UNBOUNDED).withName("pixels") + ValueLayout.JAVA_INT.withName("width"), + ValueLayout.JAVA_INT.withName("height"), + ValueLayout.ADDRESS.withName("pixels") ); - private static final VarHandle - pWidth = LAYOUT.varHandle(PathElement.groupElement("width")), - pHeight = LAYOUT.varHandle(PathElement.groupElement("height")), - pPixels = LAYOUT.varHandle(PathElement.groupElement("pixels")); - - /** - * Create a {@code GLFWImage} instance. - * - * @param address the address. - */ - public GLFWImage(MemorySegment address) { - super(address, LAYOUT); - } - - /** - * Creates a struct instance with the given memory layout. - * - * @param address the address. - * @param layout the memory layout of this struct. - */ - protected GLFWImage(MemorySegment address, MemoryLayout layout) { - super(address, layout); - } - - /** - * {@return the elements size of this struct in bytes} - */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - - /** - * Creates a {@code GLFWImage} instance with the given allocator. - * - * @param allocator the allocator - * @return the instance - */ - public static GLFWImage create(SegmentAllocator allocator) { - return new GLFWImage(allocator.allocate(LAYOUT)); - } - - /** - * Creates a {@code GLFWImage.Buffer} instance with the given allocator and count. - * - * @param allocator the allocator - * @param count the count - * @return the instance - */ - public static Buffer create(SegmentAllocator allocator, long count) { - return new Buffer(allocator.allocate(LAYOUT, count), count); - } - /** - * Sets the image width. - * - * @param width The width, in pixels, of this image. - * @return this + * The width, in pixels, of this image. */ - public GLFWImage width(int width) { - pWidth.set(segment(), width); - return this; - } - + public final StructHandle.Int width = StructHandle.ofInt(this, "width"); /** - * Sets the image height. - * - * @param height The height, in pixels, of this image. - * @return this + * The height, in pixels, of this image. */ - public GLFWImage height(int height) { - pHeight.set(segment(), height); - return this; - } - + public final StructHandle.Int height = StructHandle.ofInt(this, "height"); /** - * Sets the image pixels address. - * - * @param pixels The pixel data address of this image, arranged left-to-right, top-to-bottom. - * @return this + * The pixel data address of this image, arranged left-to-right, top-to-bottom. */ - public GLFWImage pixels(MemorySegment pixels) { - pPixels.set(segment(), pixels); - return this; - } + public final StructHandle.Address pixels = StructHandle.ofAddress(this, "pixels"); /** - * Gets the image width. + * Creates a struct with the given layout. * - * @return The width, in pixels, of this image. + * @param segment the segment + * @param elementCount the element count */ - public int width() { - return (int) pWidth.get(segment()); + public GLFWImage(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * Gets the image height. + * Allocates a struct with the given layout. * - * @return The height, in pixels, of this image. + * @param allocator the allocator + * @param elementCount the element count */ - public int height() { - return (int) pHeight.get(segment()); + public GLFWImage(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Gets the image pixels address. + * Creates a struct with the given layout. * - * @return The pixel data address of this image, arranged left-to-right, top-to-bottom. + * @param segment the segment */ - public MemorySegment pixels() { - return (MemorySegment) pPixels.get(segment()); + public GLFWImage(MemorySegment segment) { + super(segment, LAYOUT); } /** - * This describes 2D images. + * Allocates a struct with the given layout. * - * @author squid233 - * @since 0.1.0 + * @param allocator the allocator */ - public static final class Buffer extends GLFWImage implements ArrayPointer { - private final VarHandle pWidth, pHeight, pPixels; - - /** - * Create a {@code GLFWImage.Buffer} instance. - * - * @param address the address. - * @param elementCount the element count - */ - public Buffer(MemorySegment address, long elementCount) { - super(address, MemoryLayout.sequenceLayout(elementCount, LAYOUT)); - pWidth = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("width")); - pHeight = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("height")); - pPixels = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("pixels")); - } - - /** - * Sets the image width at the given index. - * - * @param index the index - * @param width The width, in pixels, of this image. - * @return this - */ - public Buffer width(long index, int width) { - pWidth.set(segment(), index, width); - return this; - } - - /** - * Sets the image height at the given index. - * - * @param index the index - * @param height The height, in pixels, of this image. - * @return this - */ - public Buffer height(long index, int height) { - pHeight.set(segment(), index, height); - return this; - } - - /** - * Sets the image pixels address at the given index. - * - * @param index the index - * @param pixels The pixel data address of this image, arranged left-to-right, top-to-bottom. - * @return this - */ - public Buffer pixels(long index, MemorySegment pixels) { - pPixels.set(segment(), index, pixels); - return this; - } - - @Override - public Buffer width(int width) { - return width(0, width); - } - - @Override - public Buffer height(int height) { - return height(0, height); - } - - @Override - public Buffer pixels(MemorySegment pixels) { - return pixels(0, pixels); - } - - /** - * Gets the image width at the given index. - * - * @param index the index - * @return The width, in pixels, of this image. - */ - public int widthAt(long index) { - return (int) pWidth.get(segment(), index); - } - - /** - * Gets the image height at the given index. - * - * @param index the index - * @return The height, in pixels, of this image. - */ - public int heightAt(long index) { - return (int) pHeight.get(segment(), index); - } - - /** - * Gets the image pixels address at the given index. - * - * @param index the index - * @return The pixel data address of this image, arranged left-to-right, top-to-bottom. - */ - public MemorySegment pixelsAt(long index) { - return (MemorySegment) pPixels.get(segment(), index); - } - - @Override - public int width() { - return widthAt(0); - } - - @Override - public int height() { - return heightAt(0); - } - - @Override - public MemorySegment pixels() { - return pixelsAt(0); - } + public GLFWImage(SegmentAllocator allocator) { + super(allocator, LAYOUT); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java index 970053c2..18f3cf01 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java @@ -17,12 +17,13 @@ package overrungl.glfw; import org.jetbrains.annotations.Nullable; -import overrungl.util.MemoryStack; +import overrun.marshal.Downcall; +import overrun.marshal.gen.Convert; +import overrun.marshal.gen.Entrypoint; +import overrun.marshal.gen.Ref; +import overrun.marshal.gen.Type; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; - -import static overrungl.glfw.Handles.*; /** * This is the header file of the native access functions. @@ -34,10 +35,11 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFWNative { - private GLFWNative() { - //no instance - } +public interface GLFWNative { + /** + * The instance of GLFWNative. + */ + GLFWNative INSTANCE = Downcall.load(Handles.lookup); /** * Returns the adapter device name of the specified monitor. @@ -49,12 +51,9 @@ private GLFWNative() { * @glfw.errors Possible errors include {@link GLFW#NOT_INITIALIZED}. * @glfw.thread_safety This function may be called from any thread. Access is not synchronized. */ - public static MemorySegment ngetWin32Adapter(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetWin32Adapter.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWin32Adapter") + default MemorySegment ngetWin32Adapter(MemorySegment monitor) { + return MemorySegment.NULL; } /** @@ -66,8 +65,9 @@ public static MemorySegment ngetWin32Adapter(MemorySegment monitor) { * occurred. * @see #ngetWin32Adapter(MemorySegment) ngetWin32Adapter */ - public static String getWin32Adapter(MemorySegment monitor) { - return ngetWin32Adapter(monitor).getString(0); + @Entrypoint("glfwGetWin32Adapter") + default String getWin32Adapter(MemorySegment monitor) { + return null; } /** @@ -81,12 +81,9 @@ public static String getWin32Adapter(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment ngetWin32Monitor(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetWin32Monitor.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWin32Monitor") + default MemorySegment ngetWin32Monitor(MemorySegment monitor) { + return MemorySegment.NULL; } /** @@ -98,8 +95,9 @@ public static MemorySegment ngetWin32Monitor(MemorySegment monitor) { * error occurred. * @see #ngetWin32Monitor(MemorySegment) ngetWin32Monitor */ - public static String getWin32Monitor(MemorySegment monitor) { - return ngetWin32Monitor(monitor).getString(0); + @Entrypoint("glfwGetWin32Monitor") + default String getWin32Monitor(MemorySegment monitor) { + return null; } /** @@ -117,12 +115,9 @@ public static String getWin32Monitor(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getWin32Window(MemorySegment window) { - try { - return (MemorySegment) glfwGetWin32Window.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWin32Window") + default MemorySegment getWin32Window(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -140,12 +135,9 @@ public static MemorySegment getWin32Window(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getWGLContext(MemorySegment window) { - try { - return (MemorySegment) glfwGetWGLContext.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWGLContext") + default MemorySegment getWGLContext(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -158,12 +150,9 @@ public static MemorySegment getWGLContext(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static int getCocoaMonitor(MemorySegment monitor) { - try { - return (int) glfwGetCocoaMonitor.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetCocoaMonitor") + default int getCocoaMonitor(MemorySegment monitor) { + return 0; } /** @@ -176,12 +165,9 @@ public static int getCocoaMonitor(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getCocoaWindow(MemorySegment window) { - try { - return (MemorySegment) glfwGetCocoaWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetCocoaWindow") + default MemorySegment getCocoaWindow(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -194,12 +180,9 @@ public static MemorySegment getCocoaWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getNSGLContext(MemorySegment window) { - try { - return (MemorySegment) glfwGetNSGLContext.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetNSGLContext") + default MemorySegment getNSGLContext(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -211,12 +194,9 @@ public static MemorySegment getNSGLContext(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getX11Display() { - try { - return (MemorySegment) glfwGetX11Display.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetX11Display") + default MemorySegment getX11Display() { + return MemorySegment.NULL; } /** @@ -229,12 +209,9 @@ public static MemorySegment getX11Display() { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static long getX11Adapter(MemorySegment monitor) { - try { - return (long) glfwGetX11Adapter.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetX11Adapter") + default long getX11Adapter(MemorySegment monitor) { + return 0L; } /** @@ -247,12 +224,9 @@ public static long getX11Adapter(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static long getX11Monitor(MemorySegment monitor) { - try { - return (long) glfwGetX11Monitor.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetX11Monitor") + default long getX11Monitor(MemorySegment monitor) { + return 0L; } /** @@ -265,12 +239,9 @@ public static long getX11Monitor(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static long getX11Window(MemorySegment window) { - try { - return (long) glfwGetX11Window.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetX11Window") + default long getX11Window(MemorySegment window) { + return 0L; } /** @@ -284,12 +255,8 @@ public static long getX11Window(MemorySegment window) { * @see #ngetX11SelectionString() getX11SelectionString * @see GLFW#nsetClipboardString(MemorySegment) setClipboardString */ - public static void nsetX11SelectionString(MemorySegment string) { - try { - glfwSetX11SelectionString.invokeExact(string); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwSetX11SelectionString") + default void nsetX11SelectionString(MemorySegment string) { } /** @@ -298,14 +265,8 @@ public static void nsetX11SelectionString(MemorySegment string) { * @param string A UTF-8 encoded string. * @see #nsetX11SelectionString(MemorySegment) nsetX11SelectionString */ - public static void setX11SelectionString(String string) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - nsetX11SelectionString(stack.allocateFrom(string)); - } finally { - stack.setPointer(stackPointer); - } + @Entrypoint("glfwSetX11SelectionString") + default void setX11SelectionString(String string) { } /** @@ -325,12 +286,9 @@ public static void setX11SelectionString(String string) { * @see #nsetX11SelectionString(MemorySegment) setX11SelectionString * @see GLFW#ngetClipboardString() getClipboardString */ - public static MemorySegment ngetX11SelectionString() { - try { - return (MemorySegment) glfwGetX11SelectionString.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetX11SelectionString") + default MemorySegment ngetX11SelectionString() { + return MemorySegment.NULL; } /** @@ -340,9 +298,9 @@ public static MemorySegment ngetX11SelectionString() { * if an error occurred. * @see #ngetX11SelectionString() ngetX11SelectionString */ - public static String getX11SelectionString() { - final MemorySegment seg = ngetX11SelectionString(); - return seg != null ? seg.getString(0) : null; + @Entrypoint("glfwGetX11SelectionString") + default String getX11SelectionString() { + return null; } /** @@ -355,12 +313,9 @@ public static String getX11SelectionString() { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getGLXContext(MemorySegment window) { - try { - return (MemorySegment) glfwGetGLXContext.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetGLXContext") + default MemorySegment getGLXContext(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -373,12 +328,9 @@ public static MemorySegment getGLXContext(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static long getGLXWindow(MemorySegment window) { - try { - return (long) glfwGetGLXWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetGLXWindow") + default long getGLXWindow(MemorySegment window) { + return 0L; } /** @@ -390,12 +342,9 @@ public static long getGLXWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getWaylandDisplay() { - try { - return (MemorySegment) glfwGetWaylandDisplay.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWaylandDisplay") + default MemorySegment getWaylandDisplay() { + return MemorySegment.NULL; } /** @@ -408,12 +357,9 @@ public static MemorySegment getWaylandDisplay() { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getWaylandMonitor(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetWaylandMonitor.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWaylandMonitor") + default MemorySegment getWaylandMonitor(MemorySegment monitor) { + return MemorySegment.NULL; } /** @@ -426,12 +372,9 @@ public static MemorySegment getWaylandMonitor(MemorySegment monitor) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getWaylandWindow(MemorySegment window) { - try { - return (MemorySegment) glfwGetWaylandWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetWaylandWindow") + default MemorySegment getWaylandWindow(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -445,12 +388,9 @@ public static MemorySegment getWaylandWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getEGLDisplay() { - try { - return (MemorySegment) glfwGetEGLDisplay.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetEGLDisplay") + default MemorySegment getEGLDisplay() { + return MemorySegment.NULL; } /** @@ -463,12 +403,9 @@ public static MemorySegment getEGLDisplay() { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getEGLContext(MemorySegment window) { - try { - return (MemorySegment) glfwGetEGLContext.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetEGLContext") + default MemorySegment getEGLContext(MemorySegment window) { + return MemorySegment.NULL; } /** @@ -481,23 +418,20 @@ public static MemorySegment getEGLContext(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getEGLSurface(MemorySegment window) { - try { - return (MemorySegment) glfwGetEGLSurface.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetEGLSurface") + default MemorySegment getEGLSurface(MemorySegment window) { + return MemorySegment.NULL; } /** * Retrieves the color buffer associated with the specified window. * - * @param window window The window whose color buffer to retrieve. - * @param width width Where to store the width of the color buffer, or {@link MemorySegment#NULL NULL}. - * @param height height Where to store the height of the color buffer, or {@link MemorySegment#NULL NULL}. - * @param format format Where to store the OSMesa pixel format of the color + * @param window The window whose color buffer to retrieve. + * @param width Where to store the width of the color buffer, or {@link MemorySegment#NULL NULL}. + * @param height Where to store the height of the color buffer, or {@link MemorySegment#NULL NULL}. + * @param format Where to store the OSMesa pixel format of the color * buffer, or {@link MemorySegment#NULL NULL}. - * @param buffer buffer Where to store the address of the color buffer, or + * @param buffer Where to store the address of the color buffer, or * {@link MemorySegment#NULL NULL}. * @return {@code true} if successful, or {@code false} if an * error occurred. @@ -505,53 +439,30 @@ public static MemorySegment getEGLSurface(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static boolean ngetOSMesaColorBuffer(MemorySegment window, MemorySegment width, MemorySegment height, MemorySegment format, MemorySegment buffer) { - try { - return (int) glfwGetOSMesaColorBuffer.invokeExact(window, width, height, format, buffer) != GLFW.FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Convert(Type.INT) + @Entrypoint("glfwGetOSMesaColorBuffer") + default boolean ngetOSMesaColorBuffer(MemorySegment window, MemorySegment width, MemorySegment height, MemorySegment format, MemorySegment buffer) { + return false; } /** * Retrieves the color buffer associated with the specified window. * - * @param window window The window whose color buffer to retrieve. - * @param width width Where to store the width of the color buffer, or {@code null}. - * @param height height Where to store the height of the color buffer, or {@code null}. - * @param format format Where to store the OSMesa pixel format of the color + * @param window The window whose color buffer to retrieve. + * @param width Where to store the width of the color buffer, or {@code null}. + * @param height Where to store the height of the color buffer, or {@code null}. + * @param format Where to store the OSMesa pixel format of the color * buffer, or {@code null}. - * @param buffer buffer Where to store the address of the color buffer, or - * {@code null}. + * @param buffer Where to store the address of the color buffer, or + * {@code NULL}. * @return {@code true} if successful, or {@code false} if an * error occurred. * @see #ngetOSMesaColorBuffer(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetOSMesaColorBuffer */ - public static boolean getOSMesaColorBuffer(MemorySegment window, int @Nullable [] width, int @Nullable [] height, int @Nullable [] format, MemorySegment @Nullable [] buffer) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment pWidth = width != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pHeight = height != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pFormat = format != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pBuffer = buffer != null ? stack.callocPointer() : MemorySegment.NULL; - final boolean success = ngetOSMesaColorBuffer(window, pWidth, pHeight, pFormat, pBuffer); - if (width != null && width.length > 0) { - width[0] = pWidth.get(ValueLayout.JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = pHeight.get(ValueLayout.JAVA_INT, 0); - } - if (format != null && format.length > 0) { - format[0] = pFormat.get(ValueLayout.JAVA_INT, 0); - } - if (buffer != null && buffer.length > 0) { - buffer[0] = pBuffer.get(ValueLayout.ADDRESS, 0); - } - return success; - } finally { - stack.setPointer(stackPointer); - } + @Convert(Type.INT) + @Entrypoint("glfwGetOSMesaColorBuffer") + default boolean getOSMesaColorBuffer(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height, @Ref int @Nullable [] format, MemorySegment buffer) { + return false; } /** @@ -570,12 +481,10 @@ public static boolean getOSMesaColorBuffer(MemorySegment window, int @Nullable [ * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static boolean ngetOSMesaDepthBuffer(MemorySegment window, MemorySegment width, MemorySegment height, MemorySegment bytesPerValue, MemorySegment buffer) { - try { - return (int) glfwGetOSMesaDepthBuffer.invokeExact(window, width, height, bytesPerValue, buffer) != GLFW.FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Convert(Type.INT) + @Entrypoint("glfwGetOSMesaDepthBuffer") + default boolean ngetOSMesaDepthBuffer(MemorySegment window, MemorySegment width, MemorySegment height, MemorySegment bytesPerValue, MemorySegment buffer) { + return false; } /** @@ -592,31 +501,10 @@ public static boolean ngetOSMesaDepthBuffer(MemorySegment window, MemorySegment * error occurred. * @see #ngetOSMesaDepthBuffer(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetOSMesaDepthBuffer */ - public static boolean getOSMesaDepthBuffer(MemorySegment window, int @Nullable [] width, int @Nullable [] height, int @Nullable [] bytesPerValue, MemorySegment @Nullable [] buffer) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment pWidth = width != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pHeight = height != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pBPV = bytesPerValue != null ? stack.callocInt() : MemorySegment.NULL; - final MemorySegment pBuffer = buffer != null ? stack.callocPointer() : MemorySegment.NULL; - final boolean success = ngetOSMesaDepthBuffer(window, pWidth, pHeight, pBPV, pBuffer); - if (width != null && width.length > 0) { - width[0] = pWidth.get(ValueLayout.JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = pHeight.get(ValueLayout.JAVA_INT, 0); - } - if (bytesPerValue != null && bytesPerValue.length > 0) { - bytesPerValue[0] = pBPV.get(ValueLayout.JAVA_INT, 0); - } - if (buffer != null && buffer.length > 0) { - buffer[0] = pBuffer.get(ValueLayout.ADDRESS, 0); - } - return success; - } finally { - stack.setPointer(stackPointer); - } + @Convert(Type.INT) + @Entrypoint("glfwGetOSMesaDepthBuffer") + default boolean getOSMesaDepthBuffer(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height, @Ref int @Nullable [] bytesPerValue, MemorySegment buffer) { + return false; } /** @@ -629,11 +517,8 @@ public static boolean getOSMesaDepthBuffer(MemorySegment window, int @Nullable [ * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static MemorySegment getOSMesaContext(MemorySegment window) { - try { - return (MemorySegment) glfwGetOSMesaContext.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetOSMesaContext") + default MemorySegment getOSMesaContext(MemorySegment window) { + return MemorySegment.NULL; } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java index 41758b48..3f341976 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,12 +16,10 @@ package overrungl.glfw; -import overrungl.ArrayPointer; -import overrungl.Struct; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; /** * This describes a single video mode. @@ -41,7 +39,7 @@ * @see GLFW#getVideoModes * @since 0.1.0 */ -public sealed class GLFWVidMode extends Struct { +public final class GLFWVidMode extends Struct { /** * The struct layout. */ @@ -53,108 +51,74 @@ public sealed class GLFWVidMode extends Struct { ValueLayout.JAVA_INT.withName("blueBits"), ValueLayout.JAVA_INT.withName("refreshRate") ); - private static final VarHandle - pWidth = LAYOUT.varHandle(PathElement.groupElement("width")), - pHeight = LAYOUT.varHandle(PathElement.groupElement("height")), - pRedBits = LAYOUT.varHandle(PathElement.groupElement("redBits")), - pGreenBits = LAYOUT.varHandle(PathElement.groupElement("greenBits")), - pBlueBits = LAYOUT.varHandle(PathElement.groupElement("blueBits")), - pRefreshRate = LAYOUT.varHandle(PathElement.groupElement("refreshRate")); - /** - * Create a {@code GLFWvidmode} instance. - * - * @param address the address. + * the width, in screen coordinates, of the video mode */ - public GLFWVidMode(MemorySegment address) { - super(address, LAYOUT); - } - + public final StructHandle.Int width = StructHandle.ofInt(this, "width"); /** - * Creates a struct instance with the given memory layout. - * - * @param address the address. - * @param layout the memory layout of this struct. + * the height, in screen coordinates, of the video mode */ - protected GLFWVidMode(MemorySegment address, MemoryLayout layout) { - super(address, layout); - } - + public final StructHandle.Int height = StructHandle.ofInt(this, "height"); /** - * {@return the elements size of this struct in bytes} - */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - - /** - * Creates a {@code GLFWVidMode} instance with the given allocator. - * - * @param allocator the allocator - * @return the instance + * the bit depth of the red channel of the video mode */ - public static GLFWVidMode create(SegmentAllocator allocator) { - return new GLFWVidMode(allocator.allocate(LAYOUT)); - } - + public final StructHandle.Int redBits = StructHandle.ofInt(this, "redBits"); /** - * Creates a {@code GLFWVidMode.Buffer} instance with the given allocator and count. - * - * @param allocator the allocator - * @param count the count - * @return the instance + * the bit depth of the green channel of the video mode */ - public static Buffer create(SegmentAllocator allocator, long count) { - return new Buffer(allocator.allocate(LAYOUT, count), count); - } - + public final StructHandle.Int greenBits = StructHandle.ofInt(this, "greenBits"); /** - * {@return an immutable state of this struct} + * the bit depth of the blue channel of the video mode */ - public Value value() { - return new Value(width(), height(), redBits(), greenBits(), blueBits(), refreshRate()); - } - + public final StructHandle.Int blueBits = StructHandle.ofInt(this, "blueBits"); /** - * {@return the width, in screen coordinates, of the video mode} + * the refresh rate, in Hz, of the video mode */ - public int width() { - return (int) pWidth.get(segment(), 0L); - } + public final StructHandle.Int refreshRate = StructHandle.ofInt(this, "refreshRate"); /** - * {@return the height, in screen coordinates, of the video mode} + * Creates a struct with the given layout. + * + * @param segment the segment + * @param elementCount the element count */ - public int height() { - return (int) pHeight.get(segment(), 0L); + public GLFWVidMode(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * {@return the bit depth of the red channel of the video mode} + * Allocates a struct with the given layout. + * + * @param allocator the allocator + * @param elementCount the element count */ - public int redBits() { - return (int) pRedBits.get(segment(), 0L); + public GLFWVidMode(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * {@return the bit depth of the green channel of the video mode} + * Creates a struct with the given layout. + * + * @param segment the segment */ - public int greenBits() { - return (int) pGreenBits.get(segment(), 0L); + public GLFWVidMode(MemorySegment segment) { + super(segment, LAYOUT); } /** - * {@return the bit depth of the blue channel of the video mode} + * Allocates a struct with the given layout. + * + * @param allocator the allocator */ - public int blueBits() { - return (int) pBlueBits.get(segment(), 0L); + public GLFWVidMode(SegmentAllocator allocator) { + super(allocator, LAYOUT); } /** - * {@return the refresh rate, in Hz, of the video mode} + * {@return an immutable state of this struct} */ - public int refreshRate() { - return (int) pRefreshRate.get(segment(), 0L); + public Value value() { + return new Value(width.get(), height.get(), redBits.get(), greenBits.get(), blueBits.get(), refreshRate.get()); } /** @@ -178,120 +142,4 @@ public int refreshRate() { int refreshRate ) { } - - /** - * This describes video modes. - * - * @author squid233 - * @since 0.1.0 - */ - public static final class Buffer extends GLFWVidMode implements ArrayPointer { - private final VarHandle pWidth, pHeight, pRedBits, pGreenBits, pBlueBits, pRefreshRate; - - /** - * Create a {@code GLFWvidmode.Buffer} instance. - * - * @param address the address. - * @param elementCount the element count - */ - public Buffer(MemorySegment address, long elementCount) { - super(address, MemoryLayout.sequenceLayout(elementCount, LAYOUT)); - pWidth = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("width")); - pHeight = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("height")); - pRedBits = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("redBits")); - pGreenBits = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("greenBits")); - pBlueBits = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("blueBits")); - pRefreshRate = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("refreshRate")); - } - - /** - * Gets the width at the given index. - * - * @param index the index - * @return The width, in screen coordinates, of the video mode. - */ - public int widthAt(long index) { - return (int) pWidth.get(segment(), index); - } - - /** - * Gets the height at the given index. - * - * @param index the index - * @return The height, in screen coordinates, of the video mode. - */ - public int heightAt(long index) { - return (int) pHeight.get(segment(), index); - } - - /** - * Gets the red bits at the given index. - * - * @param index the index - * @return The bit depth of the red channel, of the video mode. - */ - public int redBitsAt(long index) { - return (int) pRedBits.get(segment(), index); - } - - /** - * Gets the green bits at the given index. - * - * @param index the index - * @return The bit depth of the green channel, of the video mode. - */ - public int greenBitsAt(long index) { - return (int) pGreenBits.get(segment(), index); - } - - /** - * Gets the blue bits at the given index. - * - * @param index the index - * @return The bit depth of the blue channel, of the video mode. - */ - public int blueBitsAt(long index) { - return (int) pBlueBits.get(segment(), index); - } - - /** - * Gets the refresh rate at the given index. - * - * @param index the index - * @return The refresh rate, in Hz, of the video mode. - */ - public int refreshRateAt(long index) { - return (int) pRefreshRate.get(segment(), index); - } - - @Override - public int width() { - return widthAt(0); - } - - @Override - public int height() { - return heightAt(0); - } - - @Override - public int redBits() { - return redBitsAt(0); - } - - @Override - public int greenBits() { - return greenBitsAt(0); - } - - @Override - public int blueBits() { - return blueBitsAt(0); - } - - @Override - public int refreshRate() { - return refreshRateAt(0); - } - } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java index 5ac28dc3..b537c585 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,12 +16,13 @@ package overrungl.glfw; -import overrungl.util.MemoryStack; +import overrun.marshal.Downcall; +import overrun.marshal.gen.Convert; +import overrun.marshal.gen.Entrypoint; +import overrun.marshal.gen.Ref; +import overrun.marshal.gen.Type; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; - -import static overrungl.glfw.Handles.*; /** * The GLFW Vulkan binding. @@ -29,13 +30,11 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFWVulkan { +public interface GLFWVulkan { /** - * constructor + * The instance of GLFWVulkan. */ - private GLFWVulkan() { - throw new IllegalStateException("Do not construct instance"); - } + GLFWVulkan INSTANCE = Downcall.load(Handles.lookup); /** * Returns the address of the specified Vulkan instance function. @@ -70,13 +69,8 @@ private GLFWVulkan() { * is terminated. * @glfw.thread_safety This function may be called from any thread. */ - public static MemorySegment nglfwGetInstanceProcAddress(MemorySegment instance, MemorySegment procName) { - try { - return (MemorySegment) glfwGetInstanceProcAddress.invokeExact(instance, procName); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetInstanceProcAddress") + MemorySegment ngetInstanceProcAddress(MemorySegment instance, MemorySegment procName); /** * Returns the address of the specified Vulkan instance function. @@ -86,17 +80,10 @@ public static MemorySegment nglfwGetInstanceProcAddress(MemorySegment instance, * @param procName The ASCII encoded name of the function. * @return The address of the function, or {@link MemorySegment#NULL NULL} if an * error occurred. - * @see #nglfwGetInstanceProcAddress(MemorySegment, MemorySegment) nglfwGetInstanceProcAddress + * @see #ngetInstanceProcAddress(MemorySegment, MemorySegment) nglfwGetInstanceProcAddress */ - public static MemorySegment glfwGetInstanceProcAddress(MemorySegment instance, String procName) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return nglfwGetInstanceProcAddress(instance, stack.allocateFrom(procName)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetInstanceProcAddress") + MemorySegment getInstanceProcAddress(MemorySegment instance, String procName); /** * Returns whether the specified queue family can present images. @@ -125,13 +112,9 @@ public static MemorySegment glfwGetInstanceProcAddress(MemorySegment instance, S * @glfw.thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. */ - public static boolean glfwGetPhysicalDevicePresentationSupport(MemorySegment instance, MemorySegment device, int queueFamily) { - try { - return (int) glfwGetPhysicalDevicePresentationSupport.invokeExact(instance, device, queueFamily) != GLFW.FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwGetPhysicalDevicePresentationSupport") + boolean getPhysicalDevicePresentationSupport(MemorySegment instance, MemorySegment device, int queueFamily); /** * Creates a Vulkan surface for the specified window. @@ -188,13 +171,8 @@ public static boolean glfwGetPhysicalDevicePresentationSupport(MemorySegment ins * synchronization details of Vulkan objects, see the Vulkan specification. * @see GLFW#ngetRequiredInstanceExtensions(MemorySegment) getRequiredInstanceExtensions */ - public static int nglfwCreateWindowSurface(MemorySegment instance, MemorySegment window, MemorySegment allocator, MemorySegment surface) { - try { - return (int) glfwCreateWindowSurface.invokeExact(instance, window, allocator, surface); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateWindowSurface") + int ncreateWindowSurface(MemorySegment instance, MemorySegment window, MemorySegment allocator, MemorySegment surface); /** * Creates a Vulkan surface for the specified window. @@ -207,18 +185,8 @@ public static int nglfwCreateWindowSurface(MemorySegment instance, MemorySegment * to {@code VK_NULL_HANDLE} if an error occurred. * @return {@code VK_SUCCESS} if successful, or a Vulkan error code if an * error occurred. - * @see #nglfwCreateWindowSurface(MemorySegment, MemorySegment, MemorySegment, MemorySegment) nglfwCreateWindowSurface + * @see #ncreateWindowSurface(MemorySegment, MemorySegment, MemorySegment, MemorySegment) nglfwCreateWindowSurface */ - public static int glfwCreateWindowSurface(MemorySegment instance, MemorySegment window, MemorySegment allocator, long[] surface) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pSurface = stack.callocLong(); - int result = nglfwCreateWindowSurface(instance, window, allocator, pSurface); - surface[0] = pSurface.get(ValueLayout.JAVA_LONG, 0); - return result; - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwCreateWindowSurface") + int createWindowSurface(MemorySegment instance, MemorySegment window, MemorySegment allocator, @Ref long[] surface); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java index c3ff845f..d2da6127 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java @@ -38,7 +38,7 @@ * @since 0.1.0 */ final class Handles { - private static final SymbolLookup lookup; + static final SymbolLookup lookup; static { final Supplier lib = () -> RuntimeHelper.load("glfw", "glfw3", OverrunGL.GLFW_VERSION); @@ -162,13 +162,6 @@ final class Handles { glfwGetProcAddress = downcall("glfwGetProcAddress", PP), glfwVulkanSupported = downcall("glfwVulkanSupported", I), glfwGetRequiredInstanceExtensions = downcall("glfwGetRequiredInstanceExtensions", Pp); - - // GLFW Vulkan - static final MethodHandle - glfwGetInstanceProcAddress = downcall("glfwGetInstanceProcAddress", PPP), - glfwGetPhysicalDevicePresentationSupport = downcall("glfwGetPhysicalDevicePresentationSupport", PPII), - glfwCreateWindowSurface = downcall("glfwCreateWindowSurface", PPPPI); - // GLFW Native static final MethodHandle glfwGetWin32Adapter = downcallNative("glfwGetWin32Adapter", Pp), diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java new file mode 100644 index 00000000..96eef129 --- /dev/null +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.glfw; + +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; + +import java.lang.invoke.VarHandle; + +/** + * Sized array struct handle + * + * @author squid233 + * @since 0.1.0 + */ +public final class StructHandleSizedByteArray extends StructHandle { + private StructHandleSizedByteArray(VarHandle varHandle) { + super(varHandle); + } + + /** + * Creates it + * + * @param struct struct + * @param name name + * @return handle + */ + static StructHandleSizedByteArray of(Struct struct, String name) { + return new StructHandleSizedByteArray(StructHandle.ofSizedArray(struct, name)); + } + + /** + * Sets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @param value the value + */ + public void set(long index, long arrayIndex, byte value) { + varHandle.set(0L, index, arrayIndex, value); + } + + /** + * Sets the value. + * + * @param arrayIndex the array index + * @param value the value + */ + public void set(long arrayIndex, byte value) { + set(0L, arrayIndex, value); + } + + /** + * Gets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @return the value + */ + public byte get(long index, long arrayIndex) { + return (byte) varHandle.get(0L, index, arrayIndex); + } + + /** + * Gets the value. + * + * @param arrayIndex the array index + * @return the value + */ + public byte get(long arrayIndex) { + return get(0L, arrayIndex); + } +} diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java new file mode 100644 index 00000000..9424cdcc --- /dev/null +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.glfw; + +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; + +import java.lang.invoke.VarHandle; + +/** + * Sized array struct handle + * + * @author squid233 + * @since 0.1.0 + */ +public final class StructHandleSizedFloatArray extends StructHandle { + private StructHandleSizedFloatArray(VarHandle varHandle) { + super(varHandle); + } + + /** + * Creates it + * + * @param struct struct + * @param name name + * @return handle + */ + static StructHandleSizedFloatArray of(Struct struct, String name) { + return new StructHandleSizedFloatArray(StructHandle.ofSizedArray(struct, name)); + } + + /** + * Sets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @param value the value + */ + public void set(long index, long arrayIndex, float value) { + varHandle.set(0L, index, arrayIndex, value); + } + + /** + * Sets the value. + * + * @param arrayIndex the array index + * @param value the value + */ + public void set(long arrayIndex, float value) { + set(0L, arrayIndex, value); + } + + /** + * Gets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @return the value + */ + public float get(long index, long arrayIndex) { + return (short) varHandle.get(0L, index, arrayIndex); + } + + /** + * Gets the value. + * + * @param arrayIndex the array index + * @return the value + */ + public float get(long arrayIndex) { + return get(0L, arrayIndex); + } +} diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java index 4292a3a4..535eb9fe 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java @@ -76,10 +76,9 @@ private void init() { private void loop() { var states = new GLFWGamepadState[GLFW.JOYSTICK_LAST + 1]; for (int i = 0; i < states.length; i++) { - states[i] = GLFWGamepadState.create(Arena.global()); + states[i] = new GLFWGamepadState(Arena.ofAuto()); } while (!GLFW.windowShouldClose(window)) { -// try (var arena = Arena.openShared()) { for (int i = 0; i <= GLFW.JOYSTICK_LAST; i++) { if (GLFW.joystickPresent(i)) { if (GLFW.joystickIsGamepad(i)) { @@ -97,7 +96,6 @@ private void loop() { } } } -// } GLFW.waitEventsTimeout(3); } } diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java index adb97763..cacff5c4 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -74,10 +74,11 @@ private void init(Arena arena) { IOUtil.ioResourceToSegment(arena, "image.png", 256), px, py, pc, STBImage.RGB_ALPHA ); - GLFW.setWindowIcon(window, GLFWImage.create(arena, 1) - .width(px.get(JAVA_INT, 0)) - .height(py.get(JAVA_INT, 0)) - .pixels(data)); + final GLFWImage image = new GLFWImage(arena); + image.width.set(px.get(JAVA_INT, 0)); + image.height.set(py.get(JAVA_INT, 0)); + image.pixels.set(data); + GLFW.setWindowIcon(window, image); stbImage.free(data); } catch (IOException e) { throw new RuntimeException(e); From 12b5a6d2d15872559fae70c2eedc68662c7257cf Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:17:19 +0800 Subject: [PATCH 3/4] [GLFW] Clean up code as GLFW.java is turned into interface --- .../src/main/java/overrungl/glfw/GLFW.java | 528 +++++++++--------- .../src/main/java/overrungl/glfw/Handles.java | 32 -- 2 files changed, 265 insertions(+), 295 deletions(-) diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java index f3647013..3dde3290 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -17,6 +17,7 @@ package overrungl.glfw; import org.jetbrains.annotations.Nullable; +import overrun.marshal.Downcall; import overrungl.internal.RuntimeHelper; import overrungl.util.MemoryStack; import overrungl.util.value.Pair; @@ -36,25 +37,30 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFW { +public interface GLFW { + /** + * The instance of GLFW. + */ + GLFW INSTANCE = Downcall.load(Handles.lookup); + /** * The major version number of the GLFW header. *

* This is incremented when the API is changed in non-compatible ways. */ - public static final int VERSION_MAJOR = 3; + int VERSION_MAJOR = 3; /** * The minor version number of the GLFW header. *

* This is incremented when features are added to the API, but it remains backward-compatible. */ - public static final int VERSION_MINOR = 3; + int VERSION_MINOR = 3; /** * The revision number of the GLFW header. *

* This is incremented when a bug fix release is made that does not contain any API changes. */ - public static final int VERSION_REVISION = 9; + int VERSION_REVISION = 9; /** * One. @@ -63,7 +69,7 @@ public final class GLFW { * {@code true} or {@code _True} or {@code GL_TRUE} or {@code VK_TRUE} or anything else that is equal * to one. */ - public static final int TRUE = 1; + int TRUE = 1; /** * Zero. *

@@ -71,25 +77,25 @@ public final class GLFW { * {@code false} or {@code _False} or {@code GL_FALSE} or {@code VK_FALSE} or anything else that is * equal to zero. */ - public static final int FALSE = 0; + int FALSE = 0; /** * The key or mouse button was released. */ - public static final int RELEASE = 0; + int RELEASE = 0; /** * The key or mouse button was pressed. */ - public static final int PRESS = 1; + int PRESS = 1; /** * The key was held down until it repeated. */ - public static final int REPEAT = 2; + int REPEAT = 2; /** * Joystick hat states. */ - public static final int HAT_CENTERED = 0, + int HAT_CENTERED = 0, HAT_UP = 1, HAT_RIGHT = 2, HAT_DOWN = 4, @@ -103,12 +109,12 @@ public final class GLFW { /** * The unknown key */ - public static final int KEY_UNKNOWN = -1; + int KEY_UNKNOWN = -1; /** * Printable keys */ - public static final int KEY_SPACE = 32, + int KEY_SPACE = 32, KEY_APOSTROPHE = 39, /* ' */ KEY_COMMA = 44, /* , */ KEY_MINUS = 45, /* - */ @@ -162,7 +168,7 @@ public final class GLFW { /** * Function keys */ - public static final int KEY_ESCAPE = 256, + int KEY_ESCAPE = 256, KEY_ENTER = 257, KEY_TAB = 258, KEY_BACKSPACE = 259, @@ -233,39 +239,39 @@ public final class GLFW { KEY_RIGHT_SUPER = 347, KEY_MENU = 348; - public static final int KEY_LAST = KEY_MENU; + int KEY_LAST = KEY_MENU; /** * If this bit is set one or more Shift keys were held down. */ - public static final int MOD_SHIFT = 0x0001; + int MOD_SHIFT = 0x0001; /** * If this bit is set one or more Control keys were held down. */ - public static final int MOD_CONTROL = 0x0002; + int MOD_CONTROL = 0x0002; /** * If this bit is set one or more Alt keys were held down. */ - public static final int MOD_ALT = 0x0004; + int MOD_ALT = 0x0004; /** * If this bit is set one or more Super keys were held down. */ - public static final int MOD_SUPER = 0x0008; + int MOD_SUPER = 0x0008; /** * If this bit is set the Caps Lock key is enabled and the * {@link #LOCK_KEY_MODS} input mode is set. */ - public static final int MOD_CAPS_LOCK = 0x0010; + int MOD_CAPS_LOCK = 0x0010; /** * If this bit is set the Num Lock key is enabled and the * {@link #LOCK_KEY_MODS} input mode is set. */ - public static final int MOD_NUM_LOCK = 0x0020; + int MOD_NUM_LOCK = 0x0020; /** * Mouse button IDs. */ - public static final int MOUSE_BUTTON_1 = 0, + int MOUSE_BUTTON_1 = 0, MOUSE_BUTTON_2 = 1, MOUSE_BUTTON_3 = 2, MOUSE_BUTTON_4 = 3, @@ -281,7 +287,7 @@ public final class GLFW { /** * Joystick IDs. **/ - public static final int JOYSTICK_1 = 0, + int JOYSTICK_1 = 0, JOYSTICK_2 = 1, JOYSTICK_3 = 2, JOYSTICK_4 = 3, @@ -302,7 +308,7 @@ public final class GLFW { /** * Gamepad buttons. */ - public static final int GAMEPAD_BUTTON_A = 0, + int GAMEPAD_BUTTON_A = 0, GAMEPAD_BUTTON_B = 1, GAMEPAD_BUTTON_X = 2, GAMEPAD_BUTTON_Y = 3, @@ -327,7 +333,7 @@ public final class GLFW { /** * Gamepad axes. **/ - public static final int GAMEPAD_AXIS_LEFT_X = 0, + int GAMEPAD_AXIS_LEFT_X = 0, GAMEPAD_AXIS_LEFT_Y = 1, GAMEPAD_AXIS_RIGHT_X = 2, GAMEPAD_AXIS_RIGHT_Y = 3, @@ -341,7 +347,7 @@ public final class GLFW { *

Analysis

* Yay. */ - public static final int NO_ERROR = 0; + int NO_ERROR = 0; /** * GLFW has not been initialized. *

@@ -352,7 +358,7 @@ public final class GLFW { * Application programmer error. Initialize GLFW before calling any * function that requires initialization. */ - public static final int NOT_INITIALIZED = 0x00010001; + int NOT_INITIALIZED = 0x00010001; /** * No context is current for this thread. *

@@ -364,7 +370,7 @@ public final class GLFW { * Application programmer error. Ensure a context is current before * calling functions that require a current context. */ - public static final int NO_CURRENT_CONTEXT = 0x00010002; + int NO_CURRENT_CONTEXT = 0x00010002; /** * One of the arguments to the function was an invalid enum value, for example * requesting {@link #RED_BITS} with {@link #getWindowAttrib}. @@ -372,7 +378,7 @@ public final class GLFW { *

Analysis

* Application programmer error. Fix the offending call. */ - public static final int INVALID_ENUM = 0x00010003; + int INVALID_ENUM = 0x00010003; /** * One of the arguments to the function was an invalid value, for example * requesting a non-existent OpenGL or OpenGL ES version like 2.7. @@ -383,7 +389,7 @@ public final class GLFW { *

Analysis

* Application programmer error. Fix the offending call. */ - public static final int INVALID_VALUE = 0x00010004; + int INVALID_VALUE = 0x00010004; /** * A memory allocation failed. * @@ -391,7 +397,7 @@ public final class GLFW { * A bug in GLFW or the underlying operating system. Report the bug * to the issue tracker. */ - public static final int OUT_OF_MEMORY = 0x00010005; + int OUT_OF_MEMORY = 0x00010005; /** * GLFW could not find support for the requested API on the system. * @@ -406,7 +412,7 @@ public final class GLFW { * EGL, OpenGL and OpenGL ES libraries do not interface with the Nvidia binary * driver. Older graphics drivers do not support Vulkan. */ - public static final int API_UNAVAILABLE = 0x00010006; + int API_UNAVAILABLE = 0x00010006; /** * The requested OpenGL or OpenGL ES version (including any requested context * or framebuffer hints) is not available on this machine. @@ -422,7 +428,7 @@ public final class GLFW { * not {@link #INVALID_VALUE}, because GLFW cannot know what future versions * will exist. */ - public static final int VERSION_UNAVAILABLE = 0x00010007; + int VERSION_UNAVAILABLE = 0x00010007; /** * A platform-specific error occurred that does not match any of the more * specific categories. @@ -432,7 +438,7 @@ public final class GLFW { * system or its drivers, or a lack of required resources. Report the issue to * the issue tracker. */ - public static final int PLATFORM_ERROR = 0x00010008; + int PLATFORM_ERROR = 0x00010008; /** * The requested format is not supported or available. *

@@ -452,7 +458,7 @@ public final class GLFW { * If emitted when querying the clipboard, ignore the error or report it to * the user, as appropriate. */ - public static final int FORMAT_UNAVAILABLE = 0x00010009; + int FORMAT_UNAVAILABLE = 0x00010009; /** * The specified window does not have an OpenGL or OpenGL ES context. *

@@ -462,7 +468,7 @@ public final class GLFW { *

Analysis

* Application programmer error. Fix the offending call. */ - public static final int NO_WINDOW_CONTEXT = 0x0001000A; + int NO_WINDOW_CONTEXT = 0x0001000A; /** *

Window related hints

@@ -506,7 +512,7 @@ public final class GLFW { * On platforms like macOS the resolution of the framebuffer is changed independently of the window size. * */ - public static final int FOCUSED = 0x00020001, + int FOCUSED = 0x00020001, ICONIFIED = 0x00020002, RESIZABLE = 0x00020003, VISIBLE = 0x00020004, @@ -523,7 +529,7 @@ public final class GLFW { * HOVERED indicates whether the cursor is currently directly over the content area of the window, with no other windows between. * See Cursor enter/leave events for details. */ - public static final int HOVERED = 0x0002000B; + int HOVERED = 0x0002000B; /** *

Framebuffer related hints

@@ -558,7 +564,7 @@ public final class GLFW { * Possible values are {@link #TRUE} and {@link #FALSE}. * */ - public static final int RED_BITS = 0x00021001, + int RED_BITS = 0x00021001, GREEN_BITS = 0x00021002, BLUE_BITS = 0x00021003, ALPHA_BITS = 0x00021004, @@ -579,7 +585,7 @@ public final class GLFW { * A value of {@link #DONT_CARE} means the highest available refresh rate will be used. * This hint is ignored for windowed mode windows. */ - public static final int REFRESH_RATE = 0x0002100F; + int REFRESH_RATE = 0x0002100F; /** *

Context related hints

@@ -667,7 +673,7 @@ public final class GLFW { * * */ - public static final int CLIENT_API = 0x00022001, + int CLIENT_API = 0x00022001, CONTEXT_VERSION_MAJOR = 0x00022002, CONTEXT_VERSION_MINOR = 0x00022003, CONTEXT_ROBUSTNESS = 0x00022005, @@ -681,7 +687,7 @@ public final class GLFW { /** * {@link #CONTEXT_VERSION_MAJOR}, {@link #CONTEXT_VERSION_MINOR} and {@code CONTEXT_REVISION} indicate the client API version of the window's context. */ - public static final int CONTEXT_REVISION = 0x00022004; + int CONTEXT_REVISION = 0x00022004; /** *

macOS specific window hints

@@ -705,7 +711,7 @@ public final class GLFW { * * */ - public static final int COCOA_RETINA_FRAMEBUFFER = 0x00023001, + int COCOA_RETINA_FRAMEBUFFER = 0x00023001, COCOA_FRAME_NAME = 0x00023002, COCOA_GRAPHICS_SWITCHING = 0x00023003; @@ -714,7 +720,7 @@ public final class GLFW { * {@link #X11_CLASS_NAME} and {@link #X11_INSTANCE_NAME} specifies the desired ASCII encoded class and instance parts * of the ICCCM {@code WM_CLASS} window property. These are set with {@link #windowHintString}. */ - public static final int X11_CLASS_NAME = 0x00024001, + int X11_CLASS_NAME = 0x00024001, X11_INSTANCE_NAME = 0x00024002; /** @@ -722,7 +728,7 @@ public final class GLFW { * * @see #CLIENT_API */ - public static final int NO_API = 0, + int NO_API = 0, OPENGL_API = 0x00030001, OPENGL_ES_API = 0x00030002; @@ -731,7 +737,7 @@ public final class GLFW { * * @see #CONTEXT_ROBUSTNESS */ - public static final int NO_ROBUSTNESS = 0, + int NO_ROBUSTNESS = 0, NO_RESET_NOTIFICATION = 0x00031001, LOSE_CONTEXT_ON_RESET = 0x00031002; @@ -740,15 +746,15 @@ public final class GLFW { * * @see #OPENGL_PROFILE */ - public static final int OPENGL_ANY_PROFILE = 0, + int OPENGL_ANY_PROFILE = 0, OPENGL_CORE_PROFILE = 0x00032001, OPENGL_COMPAT_PROFILE = 0x00032002; - public static final int CURSOR = 0x00033001; - public static final int STICKY_KEYS = 0x00033002; - public static final int STICKY_MOUSE_BUTTONS = 0x00033003; - public static final int LOCK_KEY_MODS = 0x00033004; - public static final int RAW_MOUSE_MOTION = 0x00033005; + int CURSOR = 0x00033001; + int STICKY_KEYS = 0x00033002; + int STICKY_MOUSE_BUTTONS = 0x00033003; + int LOCK_KEY_MODS = 0x00033004; + int RAW_MOUSE_MOTION = 0x00033005; /** *

Cursor mode

@@ -781,55 +787,55 @@ public final class GLFW { * GLFW.setInputMode(window, GLFW.CURSOR, GLFW.CURSOR_NORMAL); * } */ - public static final int CURSOR_NORMAL = 0x00034001, + int CURSOR_NORMAL = 0x00034001, CURSOR_HIDDEN = 0x00034002, CURSOR_DISABLED = 0x00034003; - public static final int ANY_RELEASE_BEHAVIOR = 0; - public static final int RELEASE_BEHAVIOR_FLUSH = 0x00035001; - public static final int RELEASE_BEHAVIOR_NONE = 0x00035002; + int ANY_RELEASE_BEHAVIOR = 0; + int RELEASE_BEHAVIOR_FLUSH = 0x00035001; + int RELEASE_BEHAVIOR_NONE = 0x00035002; - public static final int NATIVE_CONTEXT_API = 0x00036001; - public static final int EGL_CONTEXT_API = 0x00036002; - public static final int OSMESA_CONTEXT_API = 0x00036003; + int NATIVE_CONTEXT_API = 0x00036001; + int EGL_CONTEXT_API = 0x00036002; + int OSMESA_CONTEXT_API = 0x00036003; - public static final int WAYLAND_PREFER_LIBDECOR = 0x00038001; - public static final int WAYLAND_DISABLE_LIBDECOR = 0x00038002; + int WAYLAND_PREFER_LIBDECOR = 0x00038001; + int WAYLAND_DISABLE_LIBDECOR = 0x00038002; /** * The regular arrow cursor. */ - public static final int ARROW_CURSOR = 0x00036001; + int ARROW_CURSOR = 0x00036001; /** * The text input I-beam cursor shape. */ - public static final int IBEAM_CURSOR = 0x00036002; + int IBEAM_CURSOR = 0x00036002; /** * The crosshair shape. */ - public static final int CROSSHAIR_CURSOR = 0x00036003; + int CROSSHAIR_CURSOR = 0x00036003; /** * The hand shape. */ - public static final int HAND_CURSOR = 0x00036004; + int HAND_CURSOR = 0x00036004; /** * The horizontal resize arrow shape. */ - public static final int HRESIZE_CURSOR = 0x00036005; + int HRESIZE_CURSOR = 0x00036005; /** * The vertical resize arrow shape. */ - public static final int VRESIZE_CURSOR = 0x00036006; + int VRESIZE_CURSOR = 0x00036006; - public static final int CONNECTED = 0x00040001; - public static final int DISCONNECTED = 0x00040002; + int CONNECTED = 0x00040001; + int DISCONNECTED = 0x00040002; /** * {@code JOYSTICK_HAT_BUTTONS} specifies whether to also expose joystick hats as buttons, * for compatibility with earlier versions of GLFW that did not have {@link #getJoystickHats}. * Possible values are {@link #TRUE} and {@link #FALSE}. */ - public static final int JOYSTICK_HAT_BUTTONS = 0x00050001; + int JOYSTICK_HAT_BUTTONS = 0x00050001; /** *

macOS specific init hints

*
    @@ -839,7 +845,7 @@ public final class GLFW { * when the first window is created, which is when AppKit is initialized. Set this with {@link #initHint}. *
*/ - public static final int COCOA_CHDIR_RESOURCES = 0x00051001, + int COCOA_CHDIR_RESOURCES = 0x00051001, COCOA_MENUBAR = 0x00051002; /** * Wayland specific init hint. @@ -848,16 +854,12 @@ public final class GLFW { * Possible values are {@link #WAYLAND_PREFER_LIBDECOR} and {@link #WAYLAND_DISABLE_LIBDECOR}. * This is ignored on other platforms. */ - public static final int WAYLAND_LIBDECOR = 0x00053001; + int WAYLAND_LIBDECOR = 0x00053001; /** * Don't care value. */ - public static final int DONT_CARE = -1; - - private GLFW() { - throw new IllegalStateException("Do not construct instance"); - } + int DONT_CARE = -1; /** * Converts the given error code to a readable string. @@ -867,7 +869,7 @@ private GLFW() { * @param errorCode the error code. * @return the error string. */ - public static String getErrorString(int errorCode) { + static String getErrorString(int errorCode) { return switch (errorCode) { case NO_ERROR -> "NO_ERROR"; case NOT_INITIALIZED -> "NOT_INITIALIZED"; @@ -912,7 +914,7 @@ public static String getErrorString(int errorCode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #terminate */ - public static boolean init() { + static boolean init() { try { return (int) glfwInit.invokeExact() != FALSE; } catch (Throwable e) { @@ -943,7 +945,7 @@ public static boolean init() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init */ - public static void terminate() { + static void terminate() { try { glfwTerminate.invokeExact(); } catch (Throwable e) { @@ -971,7 +973,7 @@ public static void terminate() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init() init */ - public static void initHint(int hint, int value) { + static void initHint(int hint, int value) { try { glfwInitHint.invokeExact(hint, value); } catch (Throwable e) { @@ -996,7 +998,7 @@ public static void initHint(int hint, int value) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersionString() getVersionString */ - public static void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev) { + static void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev) { try { glfwGetVersion.invokeExact(major, minor, rev); } catch (Throwable e) { @@ -1012,7 +1014,7 @@ public static void ngetVersion(MemorySegment major, MemorySegment minor, MemoryS * @param rev Where to store the revision number, or {@code null}. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - public static void getVersion(int @Nullable [] major, int @Nullable [] minor, int @Nullable [] rev) { + static void getVersion(int @Nullable [] major, int @Nullable [] minor, int @Nullable [] rev) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1040,7 +1042,7 @@ public static void getVersion(int @Nullable [] major, int @Nullable [] minor, in * @return the major, minor and revision version number * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - public static Triplet.OfInt getVersion() { + static Triplet.OfInt getVersion() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1075,7 +1077,7 @@ public static Triplet.OfInt getVersion() { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) getVersion */ - public static MemorySegment ngetVersionString() { + static MemorySegment ngetVersionString() { try { return (MemorySegment) glfwGetVersionString.invokeExact(); } catch (Throwable e) { @@ -1089,7 +1091,7 @@ public static MemorySegment ngetVersionString() { * @return The ASCII encoded GLFW version string. * @see #ngetVersionString() ngetVersionString */ - public static String getVersionString() { + static String getVersionString() { return ngetVersionString().getString(0); } @@ -1112,7 +1114,7 @@ public static String getVersionString() { * @glfw.thread_safety This function may be called from any thread. * @see #nsetErrorCallback(MemorySegment) setErrorCallback */ - public static int ngetError(MemorySegment description) { + static int ngetError(MemorySegment description) { try { return (int) glfwGetError.invokeExact(description); } catch (Throwable e) { @@ -1127,7 +1129,7 @@ public static int ngetError(MemorySegment description) { * @return The last error code for the calling thread, or {@link #NO_ERROR} (zero). * @see #ngetError(MemorySegment) ngetError */ - public static int getError(String @Nullable [] description) { + static int getError(String @Nullable [] description) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -1148,7 +1150,7 @@ public static int getError(String @Nullable [] description) { * @return the error description pointer. and the last error code for the calling thread, or {@link #NO_ERROR} (zero) * @see #ngetError(MemorySegment) ngetError */ - public static Tuple2.OfObjInt getError() { + static Tuple2.OfObjInt getError() { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -1188,7 +1190,7 @@ public static Tuple2.OfObjInt getError() { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetError(MemorySegment) getError */ - public static MemorySegment nsetErrorCallback(MemorySegment callback) { + static MemorySegment nsetErrorCallback(MemorySegment callback) { try { return (MemorySegment) glfwSetErrorCallback.invokeExact(callback); } catch (Throwable e) { @@ -1203,7 +1205,7 @@ public static MemorySegment nsetErrorCallback(MemorySegment callback) { * @return The previously set callback, or {@link MemorySegment#NULL NULL} if no callback was set. * @see #nsetErrorCallback(MemorySegment) nsetErrorCallback */ - public static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { + static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { return nsetErrorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -1225,7 +1227,7 @@ public static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getPrimaryMonitor() getPrimaryMonitor */ - public static MemorySegment ngetMonitors(MemorySegment count) { + static MemorySegment ngetMonitors(MemorySegment count) { try { return (MemorySegment) glfwGetMonitors.invokeExact(count); } catch (Throwable e) { @@ -1240,7 +1242,7 @@ public static MemorySegment ngetMonitors(MemorySegment count) { * if an error occurred. * @see #ngetMonitors(MemorySegment) ngetMonitors */ - public static MemorySegment @Nullable [] getMonitors() { + static MemorySegment @Nullable [] getMonitors() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1268,7 +1270,7 @@ public static MemorySegment ngetMonitors(MemorySegment count) { * {@link #ngetMonitors(MemorySegment) getMonitors}. * @see #ngetMonitors(MemorySegment) getMonitors */ - public static MemorySegment getPrimaryMonitor() { + static MemorySegment getPrimaryMonitor() { try { return (MemorySegment) glfwGetPrimaryMonitor.invokeExact(); } catch (Throwable e) { @@ -1292,7 +1294,7 @@ public static MemorySegment getPrimaryMonitor() { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos) { + static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos) { try { glfwGetMonitorPos.invokeExact(monitor, xpos, ypos); } catch (Throwable e) { @@ -1308,7 +1310,7 @@ public static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, Mem * @param ypos Where to store the monitor y-coordinate, or {@code null}. * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - public static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos) { + static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1333,7 +1335,7 @@ public static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, i * @return the monitor xy-coordinate * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - public static Pair.OfInt getMonitorPos(MemorySegment monitor) { + static Pair.OfInt getMonitorPos(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1368,7 +1370,7 @@ public static Pair.OfInt getMonitorPos(MemorySegment monitor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height) { + static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height) { try { glfwGetMonitorWorkarea.invokeExact(monitor, xpos, ypos, width, height); } catch (Throwable e) { @@ -1386,7 +1388,7 @@ public static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos * @param height Where to store the monitor height, or {@code null}. * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - public static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos, int @Nullable [] width, int @Nullable [] height) { + static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos, int @Nullable [] width, int @Nullable [] height) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1419,7 +1421,7 @@ public static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xp * @return the monitor xy-coordinate, the monitor width and the monitor height * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - public static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { + static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1461,7 +1463,7 @@ public static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { * the current resolution and system DPI instead of querying the monitor EDID data. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM) { + static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM) { try { glfwGetMonitorPhysicalSize.invokeExact(monitor, widthMM, heightMM); } catch (Throwable e) { @@ -1479,7 +1481,7 @@ public static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment * monitor's display area, or {@code null}. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - public static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [] widthMM, int @Nullable [] heightMM) { + static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [] widthMM, int @Nullable [] heightMM) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1504,7 +1506,7 @@ public static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [ * @return the width and height, in millimetres, of the monitor's display area. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - public static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { + static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1540,7 +1542,7 @@ public static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale */ - public static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale) { + static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale) { try { glfwGetMonitorContentScale.invokeExact(monitor, xscale, yscale); } catch (Throwable e) { @@ -1556,7 +1558,7 @@ public static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - public static void getMonitorContentScale(MemorySegment monitor, float @Nullable [] xscale, float @Nullable [] yscale) { + static void getMonitorContentScale(MemorySegment monitor, float @Nullable [] xscale, float @Nullable [] yscale) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1581,7 +1583,7 @@ public static void getMonitorContentScale(MemorySegment monitor, float @Nullable * @return the xy-axis content scale * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - public static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { + static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1610,7 +1612,7 @@ public static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetMonitorName(MemorySegment monitor) { + static MemorySegment ngetMonitorName(MemorySegment monitor) { try { return (MemorySegment) glfwGetMonitorName.invokeExact(monitor); } catch (Throwable e) { @@ -1627,7 +1629,7 @@ public static MemorySegment ngetMonitorName(MemorySegment monitor) { * @see #ngetMonitorName(MemorySegment) ngetMonitorName */ @Nullable - public static String getMonitorName(MemorySegment monitor) { + static String getMonitorName(MemorySegment monitor) { var pName = ngetMonitorName(monitor); return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); } @@ -1649,7 +1651,7 @@ public static String getMonitorName(MemorySegment monitor) { * synchronized. * @see #getMonitorUserPointer(MemorySegment) getMonitorUserPointer */ - public static void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer) { + static void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer) { try { glfwSetMonitorUserPointer.invokeExact(monitor, pointer); } catch (Throwable e) { @@ -1672,7 +1674,7 @@ public static void setMonitorUserPointer(MemorySegment monitor, MemorySegment po * synchronized. * @see #setMonitorUserPointer(MemorySegment, MemorySegment) setMonitorUserPointer */ - public static MemorySegment getMonitorUserPointer(MemorySegment monitor) { + static MemorySegment getMonitorUserPointer(MemorySegment monitor) { try { return (MemorySegment) glfwGetMonitorUserPointer.invokeExact(monitor); } catch (Throwable e) { @@ -1697,7 +1699,7 @@ public static MemorySegment getMonitorUserPointer(MemorySegment monitor) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetMonitorCallback(MemorySegment callback) { + static MemorySegment nsetMonitorCallback(MemorySegment callback) { try { return (MemorySegment) glfwSetMonitorCallback.invokeExact(callback); } catch (Throwable e) { @@ -1714,7 +1716,7 @@ public static MemorySegment nsetMonitorCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetMonitorCallback(MemorySegment) nsetMonitorCallback */ - public static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { + static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { return nsetMonitorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -1741,7 +1743,7 @@ public static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoMode(MemorySegment) getVideoMode */ - public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) { + static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) { try { return (MemorySegment) glfwGetVideoModes.invokeExact(monitor, count); } catch (Throwable e) { @@ -1757,7 +1759,7 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment * error occurred. * @see #ngetVideoModes(MemorySegment, MemorySegment) ngetVideoModes */ - public static @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { + static @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -1789,7 +1791,7 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoModes(MemorySegment, MemorySegment) getVideoModes */ - public static MemorySegment ngetVideoMode(MemorySegment monitor) { + static MemorySegment ngetVideoMode(MemorySegment monitor) { try { return (MemorySegment) glfwGetVideoMode.invokeExact(monitor); } catch (Throwable e) { @@ -1806,7 +1808,7 @@ public static MemorySegment ngetVideoMode(MemorySegment monitor) { * @see #ngetVideoMode(MemorySegment) ngetVideoMode */ @Nullable - public static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { + static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { var pMode = ngetVideoMode(monitor); if (RuntimeHelper.isNullptr(pMode)) return null; return new GLFWVidMode(pMode).value(); @@ -1835,7 +1837,7 @@ public static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { * will thus never be implemented and emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void setGamma(MemorySegment monitor, float gamma) { + static void setGamma(MemorySegment monitor, float gamma) { try { glfwSetGamma.invokeExact(monitor, gamma); } catch (Throwable e) { @@ -1862,7 +1864,7 @@ public static void setGamma(MemorySegment monitor, float gamma) { * monitor or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetGammaRamp(MemorySegment monitor) { + static MemorySegment ngetGammaRamp(MemorySegment monitor) { try { return (MemorySegment) glfwGetGammaRamp.invokeExact(monitor); } catch (Throwable e) { @@ -1879,7 +1881,7 @@ public static MemorySegment ngetGammaRamp(MemorySegment monitor) { * @see #ngetGammaRamp(MemorySegment) ngetGammaRamp */ @Nullable - public static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { + static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { var pRamp = ngetGammaRamp(monitor); if (RuntimeHelper.isNullptr(pRamp)) return null; return new GLFWGammaRamp(pRamp); @@ -1915,7 +1917,7 @@ public static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { * returns. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { + static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { try { glfwSetGammaRamp.invokeExact(monitor, ramp); } catch (Throwable e) { @@ -1930,7 +1932,7 @@ public static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { * @param ramp The gamma ramp to use. * @see #nsetGammaRamp(MemorySegment, MemorySegment) nsetGammaRamp */ - public static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { + static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { nsetGammaRamp(monitor, ramp.segment()); } @@ -1945,7 +1947,7 @@ public static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { * @see #windowHint(int, int) windowHint * @see #nwindowHintString(int, MemorySegment) windowHintString */ - public static void defaultWindowHints() { + static void defaultWindowHints() { try { glfwDefaultWindowHints.invokeExact(); } catch (Throwable e) { @@ -1979,7 +1981,7 @@ public static void defaultWindowHints() { * @see #nwindowHintString(int, MemorySegment) windowHintString * @see #defaultWindowHints */ - public static void windowHint(int hint, int value) { + static void windowHint(int hint, int value) { try { glfwWindowHint.invokeExact(hint, value); } catch (Throwable e) { @@ -1994,7 +1996,7 @@ public static void windowHint(int hint, int value) { * @param value The new value of the window hint. * @see #windowHint(int, int) */ - public static void windowHint(int hint, boolean value) { + static void windowHint(int hint, boolean value) { windowHint(hint, value ? TRUE : FALSE); } @@ -2026,7 +2028,7 @@ public static void windowHint(int hint, boolean value) { * @see #windowHint(int, int) windowHint * @see #defaultWindowHints */ - public static void nwindowHintString(int hint, MemorySegment value) { + static void nwindowHintString(int hint, MemorySegment value) { try { glfwWindowHintString.invokeExact(hint, value); } catch (Throwable e) { @@ -2041,7 +2043,7 @@ public static void nwindowHintString(int hint, MemorySegment value) { * @param value The new value of the window hint. * @see #nwindowHintString(int, MemorySegment) nwindowHintString */ - public static void windowHintString(int hint, String value) { + static void windowHintString(int hint, String value) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -2202,7 +2204,7 @@ public static void windowHintString(int hint, String value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #destroyWindow */ - public static MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share) { + static MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share) { try { return (MemorySegment) glfwCreateWindow.invokeExact(width, height, title, monitor, share); } catch (Throwable e) { @@ -2226,7 +2228,7 @@ public static MemorySegment ncreateWindow(int width, int height, MemorySegment t * error occurred. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) ncreateWindow */ - public static MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share) { + static MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -2254,7 +2256,7 @@ public static MemorySegment createWindow(int width, int height, String title, Me * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) createWindow */ - public static void destroyWindow(MemorySegment window) { + static void destroyWindow(MemorySegment window) { try { glfwDestroyWindow.invokeExact(window); } catch (Throwable e) { @@ -2273,7 +2275,7 @@ public static void destroyWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static boolean windowShouldClose(MemorySegment window) { + static boolean windowShouldClose(MemorySegment window) { try { return (int) glfwWindowShouldClose.invokeExact(window) != FALSE; } catch (Throwable e) { @@ -2294,7 +2296,7 @@ public static boolean windowShouldClose(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static void setWindowShouldClose(MemorySegment window, boolean value) { + static void setWindowShouldClose(MemorySegment window, boolean value) { try { glfwSetWindowShouldClose.invokeExact(window, value ? TRUE : FALSE); } catch (Throwable e) { @@ -2316,7 +2318,7 @@ public static void setWindowShouldClose(MemorySegment window, boolean value) { * process events. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetWindowTitle(MemorySegment window, MemorySegment title) { + static void nsetWindowTitle(MemorySegment window, MemorySegment title) { try { glfwSetWindowTitle.invokeExact(window, title); } catch (Throwable e) { @@ -2331,7 +2333,7 @@ public static void nsetWindowTitle(MemorySegment window, MemorySegment title) { * @param title The UTF-8 encoded window title. * @see #nsetWindowTitle(MemorySegment, MemorySegment) nsetWindowTitle */ - public static void setWindowTitle(MemorySegment window, String title) { + static void setWindowTitle(MemorySegment window, String title) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -2377,7 +2379,7 @@ public static void setWindowTitle(MemorySegment window, String title) { * This function always emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetWindowIcon(MemorySegment window, int count, MemorySegment images) { + static void nsetWindowIcon(MemorySegment window, int count, MemorySegment images) { try { glfwSetWindowIcon.invokeExact(window, count, images); } catch (Throwable e) { @@ -2395,7 +2397,7 @@ public static void nsetWindowIcon(MemorySegment window, int count, MemorySegment * count is zero. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, int count, GLFWImage images) { + static void setWindowIcon(MemorySegment window, int count, GLFWImage images) { if (images == null || count == 0) { nsetWindowIcon(window, 0, MemorySegment.NULL); } else { @@ -2411,7 +2413,7 @@ public static void setWindowIcon(MemorySegment window, int count, GLFWImage imag * revert to the default window icon. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { + static void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { setWindowIcon(window, images == null ? 0 : Math.toIntExact(images.elementCount()), images); } @@ -2437,7 +2439,7 @@ public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage image * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowPos(MemorySegment, int, int) setWindowPos */ - public static void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { + static void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { try { glfwGetWindowPos.invokeExact(window, xpos, ypos); } catch (Throwable e) { @@ -2454,7 +2456,7 @@ public static void ngetWindowPos(MemorySegment window, MemorySegment xpos, Memor * @param ypos Where to store the y-coordinate of the upper-left corner of * the content area, or {@code null}. */ - public static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int @Nullable [] ypos) { + static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int @Nullable [] ypos) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2478,7 +2480,7 @@ public static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int * @param window The window to query. * @return the xy-coordinate of the upper-left corner of the content area. */ - public static Pair.OfInt getWindowPos(MemorySegment window) { + static Pair.OfInt getWindowPos(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2515,7 +2517,7 @@ public static Pair.OfInt getWindowPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowPos(MemorySegment, MemorySegment, MemorySegment) getWindowPos */ - public static void setWindowPos(MemorySegment window, int xpos, int ypos) { + static void setWindowPos(MemorySegment window, int xpos, int ypos) { try { glfwSetWindowPos.invokeExact(window, xpos, ypos); } catch (Throwable e) { @@ -2544,7 +2546,7 @@ public static void setWindowPos(MemorySegment window, int xpos, int ypos) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - public static void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height) { + static void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height) { try { glfwGetWindowSize.invokeExact(window, width, height); } catch (Throwable e) { @@ -2562,7 +2564,7 @@ public static void ngetWindowSize(MemorySegment window, MemorySegment width, Mem * content area, or {@code null}. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - public static void getWindowSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { + static void getWindowSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2587,7 +2589,7 @@ public static void getWindowSize(MemorySegment window, int @Nullable [] width, i * @return the width and height, in screen coordinates, of the content area. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - public static Pair.OfInt getWindowSize(MemorySegment window) { + static Pair.OfInt getWindowSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2633,7 +2635,7 @@ public static Pair.OfInt getWindowSize(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAspectRatio(MemorySegment, int, int) setWindowAspectRatio */ - public static void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight) { + static void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight) { try { glfwSetWindowSizeLimits.invokeExact(window, minWidth, minHeight, maxWidth, maxHeight); } catch (Throwable e) { @@ -2674,7 +2676,7 @@ public static void setWindowSizeLimits(MemorySegment window, int minWidth, int m * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSizeLimits(MemorySegment, int, int, int, int) setWindowSizeLimits */ - public static void setWindowAspectRatio(MemorySegment window, int numer, int denom) { + static void setWindowAspectRatio(MemorySegment window, int numer, int denom) { try { glfwSetWindowAspectRatio.invokeExact(window, numer, denom); } catch (Throwable e) { @@ -2713,7 +2715,7 @@ public static void setWindowAspectRatio(MemorySegment window, int numer, int den * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) getWindowSize * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - public static void setWindowSize(MemorySegment window, int width, int height) { + static void setWindowSize(MemorySegment window, int width, int height) { try { glfwSetWindowSize.invokeExact(window, width, height); } catch (Throwable e) { @@ -2741,7 +2743,7 @@ public static void setWindowSize(MemorySegment window, int width, int height) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) setFramebufferSizeCallback */ - public static void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height) { + static void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height) { try { glfwGetFramebufferSize.invokeExact(window, width, height); } catch (Throwable e) { @@ -2759,7 +2761,7 @@ public static void ngetFramebufferSize(MemorySegment window, MemorySegment width * or {@code null}. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - public static void getFramebufferSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { + static void getFramebufferSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2784,7 +2786,7 @@ public static void getFramebufferSize(MemorySegment window, int @Nullable [] wid * @return the width and height, in pixels, of the framebuffer. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - public static Pair.OfInt getFramebufferSize(MemorySegment window) { + static Pair.OfInt getFramebufferSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2826,7 +2828,7 @@ public static Pair.OfInt getFramebufferSize(MemorySegment window) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom) { + static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom) { try { glfwGetWindowFrameSize.invokeExact(window, left, top, right, bottom); } catch (Throwable e) { @@ -2848,7 +2850,7 @@ public static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, * bottom edge of the window frame, or {@code null}. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - public static void getWindowFrameSize(MemorySegment window, int @Nullable [] left, int @Nullable [] top, int @Nullable [] right, int @Nullable [] bottom) { + static void getWindowFrameSize(MemorySegment window, int @Nullable [] left, int @Nullable [] top, int @Nullable [] right, int @Nullable [] bottom) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2882,7 +2884,7 @@ public static void getWindowFrameSize(MemorySegment window, int @Nullable [] lef * edge of the window frame. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - public static Quad.OfInt getWindowFrameSize(MemorySegment window) { + static Quad.OfInt getWindowFrameSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2924,7 +2926,7 @@ public static Quad.OfInt getWindowFrameSize(MemorySegment window) { * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) setWindowContentScaleCallback * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) getMonitorContentScale */ - public static void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale) { + static void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale) { try { glfwGetWindowContentScale.invokeExact(window, xscale, yscale); } catch (Throwable e) { @@ -2940,7 +2942,7 @@ public static void ngetWindowContentScale(MemorySegment window, MemorySegment xs * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - public static void getWindowContentScale(MemorySegment window, float @Nullable [] xscale, float @Nullable [] yscale) { + static void getWindowContentScale(MemorySegment window, float @Nullable [] xscale, float @Nullable [] yscale) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2965,7 +2967,7 @@ public static void getWindowContentScale(MemorySegment window, float @Nullable [ * @return the xy-axis content scale. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - public static Pair.OfFloat getWindowContentScale(MemorySegment window) { + static Pair.OfFloat getWindowContentScale(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -2996,7 +2998,7 @@ public static Pair.OfFloat getWindowContentScale(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowOpacity(MemorySegment, float) setWindowOpacity */ - public static float getWindowOpacity(MemorySegment window) { + static float getWindowOpacity(MemorySegment window) { try { return (float) glfwGetWindowOpacity.invokeExact(window); } catch (Throwable e) { @@ -3024,7 +3026,7 @@ public static float getWindowOpacity(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowOpacity(MemorySegment) getWindowOpacity */ - public static void setWindowOpacity(MemorySegment window, float opacity) { + static void setWindowOpacity(MemorySegment window, float opacity) { try { glfwSetWindowOpacity.invokeExact(window, opacity); } catch (Throwable e) { @@ -3050,7 +3052,7 @@ public static void setWindowOpacity(MemorySegment window, float opacity) { * @see #restoreWindow(MemorySegment) restoreWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - public static void iconifyWindow(MemorySegment window) { + static void iconifyWindow(MemorySegment window) { try { glfwIconifyWindow.invokeExact(window); } catch (Throwable e) { @@ -3075,7 +3077,7 @@ public static void iconifyWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - public static void restoreWindow(MemorySegment window) { + static void restoreWindow(MemorySegment window) { try { glfwRestoreWindow.invokeExact(window); } catch (Throwable e) { @@ -3098,7 +3100,7 @@ public static void restoreWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #restoreWindow(MemorySegment) restoreWindow */ - public static void maximizeWindow(MemorySegment window) { + static void maximizeWindow(MemorySegment window) { try { glfwMaximizeWindow.invokeExact(window); } catch (Throwable e) { @@ -3128,7 +3130,7 @@ public static void maximizeWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #hideWindow(MemorySegment) hideWindow */ - public static void showWindow(MemorySegment window) { + static void showWindow(MemorySegment window) { try { glfwShowWindow.invokeExact(window); } catch (Throwable e) { @@ -3149,7 +3151,7 @@ public static void showWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #showWindow(MemorySegment) showWindow */ - public static void hideWindow(MemorySegment window) { + static void hideWindow(MemorySegment window) { try { glfwHideWindow.invokeExact(window); } catch (Throwable e) { @@ -3185,7 +3187,7 @@ public static void hideWindow(MemorySegment window) { * to front, this function will always emit {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void focusWindow(MemorySegment window) { + static void focusWindow(MemorySegment window) { try { glfwFocusWindow.invokeExact(window); } catch (Throwable e) { @@ -3210,7 +3212,7 @@ public static void focusWindow(MemorySegment window) { * specific window. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void requestWindowAttention(MemorySegment window) { + static void requestWindowAttention(MemorySegment window) { try { glfwRequestWindowAttention.invokeExact(window); } catch (Throwable e) { @@ -3231,7 +3233,7 @@ public static void requestWindowAttention(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - public static MemorySegment getWindowMonitor(MemorySegment window) { + static MemorySegment getWindowMonitor(MemorySegment window) { try { return (MemorySegment) glfwGetWindowMonitor.invokeExact(window); } catch (Throwable e) { @@ -3287,7 +3289,7 @@ public static MemorySegment getWindowMonitor(MemorySegment window) { * @see #getWindowMonitor(MemorySegment) getWindowMonitor * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - public static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate) { + static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate) { try { glfwSetWindowMonitor.invokeExact(window, monitor, xpos, ypos, width, height, refreshRate); } catch (Throwable e) { @@ -3322,7 +3324,7 @@ public static void setWindowMonitor(MemorySegment window, MemorySegment monitor, * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAttrib(MemorySegment, int, boolean) setWindowAttrib */ - public static int getWindowAttrib(MemorySegment window, int attrib) { + static int getWindowAttrib(MemorySegment window, int attrib) { try { return (int) glfwGetWindowAttrib.invokeExact(window, attrib); } catch (Throwable e) { @@ -3357,7 +3359,7 @@ public static int getWindowAttrib(MemorySegment window, int attrib) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowAttrib(MemorySegment, int) getWindowAttrib */ - public static void setWindowAttrib(MemorySegment window, int attrib, boolean value) { + static void setWindowAttrib(MemorySegment window, int attrib, boolean value) { try { glfwSetWindowAttrib.invokeExact(window, attrib, value ? TRUE : FALSE); } catch (Throwable e) { @@ -3379,7 +3381,7 @@ public static void setWindowAttrib(MemorySegment window, int attrib, boolean val * synchronized. * @see #getWindowUserPointer(MemorySegment) getWindowUserPointer */ - public static void setWindowUserPointer(MemorySegment window, MemorySegment pointer) { + static void setWindowUserPointer(MemorySegment window, MemorySegment pointer) { try { glfwSetWindowUserPointer.invokeExact(window, pointer); } catch (Throwable e) { @@ -3399,7 +3401,7 @@ public static void setWindowUserPointer(MemorySegment window, MemorySegment poin * synchronized. * @see #setWindowUserPointer(MemorySegment, MemorySegment) setWindowUserPointer */ - public static MemorySegment getWindowUserPointer(MemorySegment window) { + static MemorySegment getWindowUserPointer(MemorySegment window) { try { return (MemorySegment) glfwGetWindowUserPointer.invokeExact(window); } catch (Throwable e) { @@ -3428,7 +3430,7 @@ public static MemorySegment getWindowUserPointer(MemorySegment window) { * an application to know its global position. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowPosCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3446,7 +3448,7 @@ public static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySe * library had not been initialized. * @see #nsetWindowPosCallback(MemorySegment, MemorySegment) nsetWindowPosCallback */ - public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { + static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { return nsetWindowPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3468,7 +3470,7 @@ public static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowSizeCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3486,7 +3488,7 @@ public static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemoryS * library had not been initialized. * @see #nsetWindowSizeCallback(MemorySegment, MemorySegment) nsetWindowSizeCallback */ - public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { + static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { return nsetWindowSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3515,7 +3517,7 @@ public static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullabl * close callback for all windows. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowCloseCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3533,7 +3535,7 @@ public static MemorySegment nsetWindowCloseCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetWindowCloseCallback(MemorySegment, MemorySegment) nsetWindowCloseCallback */ - public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { + static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { return nsetWindowCloseCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3559,7 +3561,7 @@ public static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullab * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowRefreshCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3577,7 +3579,7 @@ public static MemorySegment nsetWindowRefreshCallback(MemorySegment window, Memo * library had not been initialized. * @see #nsetWindowRefreshCallback(MemorySegment, MemorySegment) nsetWindowRefreshCallback */ - public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { + static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { return nsetWindowRefreshCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3604,7 +3606,7 @@ public static MemorySegment setWindowRefreshCallback(MemorySegment window, @Null * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowFocusCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3622,7 +3624,7 @@ public static MemorySegment nsetWindowFocusCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetWindowFocusCallback(MemorySegment, MemorySegment) nsetWindowFocusCallback */ - public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { + static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { return nsetWindowFocusCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3645,7 +3647,7 @@ public static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullab * this callback will never be called. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowIconifyCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3663,7 +3665,7 @@ public static MemorySegment nsetWindowIconifyCallback(MemorySegment window, Memo * library had not been initialized. * @see #nsetWindowIconifyCallback(MemorySegment, MemorySegment) nsetWindowIconifyCallback */ - public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { + static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { return nsetWindowIconifyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3684,7 +3686,7 @@ public static MemorySegment setWindowIconifyCallback(MemorySegment window, @Null * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowMaximizeCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3702,7 +3704,7 @@ public static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, Mem * library had not been initialized. * @see #nsetWindowMaximizeCallback(MemorySegment, MemorySegment) nsetWindowMaximizeCallback */ - public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { + static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { return nsetWindowMaximizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3723,7 +3725,7 @@ public static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nul * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetFramebufferSizeCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3741,7 +3743,7 @@ public static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, Me * library had not been initialized. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) nsetFramebufferSizeCallback */ - public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { + static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { return nsetFramebufferSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3763,7 +3765,7 @@ public static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nu * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale */ - public static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetWindowContentScaleCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -3781,7 +3783,7 @@ public static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, * library had not been initialized. * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) nsetWindowContentScaleCallback */ - public static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { + static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { return nsetWindowContentScaleCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3815,7 +3817,7 @@ public static MemorySegment setWindowContentScaleCallback(MemorySegment window, * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void pollEvents() { + static void pollEvents() { try { glfwPollEvents.invokeExact(); } catch (Throwable e) { @@ -3859,7 +3861,7 @@ public static void pollEvents() { * @see #pollEvents() pollEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void waitEvents() { + static void waitEvents() { try { glfwWaitEvents.invokeExact(); } catch (Throwable e) { @@ -3906,7 +3908,7 @@ public static void waitEvents() { * @see #pollEvents() pollEvents * @see #waitEvents() waitEvents */ - public static void waitEventsTimeout(double timeout) { + static void waitEventsTimeout(double timeout) { try { glfwWaitEventsTimeout.invokeExact(timeout); } catch (Throwable e) { @@ -3926,7 +3928,7 @@ public static void waitEventsTimeout(double timeout) { * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void postEmptyEvents() { + static void postEmptyEvents() { try { glfwPostEmptyEvent.invokeExact(); } catch (Throwable e) { @@ -3951,7 +3953,7 @@ public static void postEmptyEvents() { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - public static int getInputMode(MemorySegment window, int mode) { + static int getInputMode(MemorySegment window, int mode) { try { return (int) glfwGetInputMode.invokeExact(window, mode); } catch (Throwable e) { @@ -4015,7 +4017,7 @@ public static int getInputMode(MemorySegment window, int mode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getInputMode(MemorySegment, int) getInputMode */ - public static void setInputMode(MemorySegment window, int mode, int value) { + static void setInputMode(MemorySegment window, int mode, int value) { try { glfwSetInputMode.invokeExact(window, mode, value); } catch (Throwable e) { @@ -4043,7 +4045,7 @@ public static void setInputMode(MemorySegment window, int mode, int value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - public static boolean rawMouseMotionSupported() { + static boolean rawMouseMotionSupported() { try { return (int) glfwRawMouseMotionSupported.invokeExact() != FALSE; } catch (Throwable e) { @@ -4112,7 +4114,7 @@ public static boolean rawMouseMotionSupported() { * should not free it yourself. It is valid until the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetKeyName(int key, int scancode) { + static MemorySegment ngetKeyName(int key, int scancode) { try { return (MemorySegment) glfwGetKeyName.invokeExact(key, scancode); } catch (Throwable e) { @@ -4129,7 +4131,7 @@ public static MemorySegment ngetKeyName(int key, int scancode) { * @see #ngetKeyName(int, int) ngetKeyName */ @Nullable - public static String getKeyName(int key, int scancode) { + static String getKeyName(int key, int scancode) { var pName = ngetKeyName(key, scancode); return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); } @@ -4151,7 +4153,7 @@ public static String getKeyName(int key, int scancode) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and {@link #INVALID_ENUM}. * @glfw.thread_safety This function may be called from any thread. */ - public static int getKeyScancode(int key) { + static int getKeyScancode(int key) { try { return (int) glfwGetKeyScancode.invokeExact(key); } catch (Throwable e) { @@ -4190,7 +4192,7 @@ public static int getKeyScancode(int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static int getKey(MemorySegment window, int key) { + static int getKey(MemorySegment window, int key) { try { return (int) glfwGetKey.invokeExact(window, key); } catch (Throwable e) { @@ -4217,7 +4219,7 @@ public static int getKey(MemorySegment window, int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static int getMouseButton(MemorySegment window, int button) { + static int getMouseButton(MemorySegment window, int button) { try { return (int) glfwGetMouseButton.invokeExact(window, button); } catch (Throwable e) { @@ -4254,7 +4256,7 @@ public static int getMouseButton(MemorySegment window, int button) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setCursorPos(MemorySegment, double, double) setCursorPos */ - public static void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { + static void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { try { glfwGetCursorPos.invokeExact(window, xpos, ypos); } catch (Throwable e) { @@ -4273,7 +4275,7 @@ public static void ngetCursorPos(MemorySegment window, MemorySegment xpos, Memor * top edge of the content area, or {@code null}. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - public static void getCursorPos(MemorySegment window, double @Nullable [] xpos, double @Nullable [] ypos) { + static void getCursorPos(MemorySegment window, double @Nullable [] xpos, double @Nullable [] ypos) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -4299,7 +4301,7 @@ public static void getCursorPos(MemorySegment window, double @Nullable [] xpos, * @return the cursor xy-coordinate, relative to the left and top edge of the content area. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - public static Pair.OfDouble getCursorPos(MemorySegment window) { + static Pair.OfDouble getCursorPos(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -4342,7 +4344,7 @@ public static Pair.OfDouble getCursorPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) getCursorPos */ - public static void setCursorPos(MemorySegment window, double xpos, double ypos) { + static void setCursorPos(MemorySegment window, double xpos, double ypos) { try { glfwSetCursorPos.invokeExact(window, xpos, ypos); } catch (Throwable e) { @@ -4378,7 +4380,7 @@ public static void setCursorPos(MemorySegment window, double xpos, double ypos) * @see #destroyCursor(MemorySegment) destroyCursor * @see #createStandardCursor(int) createStandardCursor */ - public static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot) { + static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot) { try { return (MemorySegment) glfwCreateCursor.invokeExact(image, xhot, yhot); } catch (Throwable e) { @@ -4396,7 +4398,7 @@ public static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yho * error occurred. * @see #ncreateCursor(MemorySegment, int, int) ncreateCursor */ - public static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { + static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { return ncreateCursor(image.segment(), xhot, yhot); } @@ -4415,7 +4417,7 @@ public static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - public static MemorySegment createStandardCursor(int shape) { + static MemorySegment createStandardCursor(int shape) { try { return (MemorySegment) glfwCreateStandardCursor.invokeExact(shape); } catch (Throwable e) { @@ -4440,7 +4442,7 @@ public static MemorySegment createStandardCursor(int shape) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - public static void destroyCursor(MemorySegment cursor) { + static void destroyCursor(MemorySegment cursor) { try { glfwDestroyCursor.invokeExact(cursor); } catch (Throwable e) { @@ -4466,7 +4468,7 @@ public static void destroyCursor(MemorySegment cursor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void setCursor(MemorySegment window, MemorySegment cursor) { + static void setCursor(MemorySegment window, MemorySegment cursor) { try { glfwSetCursor.invokeExact(window, cursor); } catch (Throwable e) { @@ -4511,7 +4513,7 @@ public static void setCursor(MemorySegment window, MemorySegment cursor) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetKeyCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4529,7 +4531,7 @@ public static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetKeyCallback(MemorySegment, MemorySegment) nsetKeyCallback */ - public static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { + static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { return nsetKeyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4562,7 +4564,7 @@ public static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWK * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetCharCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4580,7 +4582,7 @@ public static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetCharCallback(MemorySegment, MemorySegment) nsetCharCallback */ - public static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { + static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { return nsetCharCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4607,7 +4609,7 @@ public static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFW * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetMouseButtonCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4625,7 +4627,7 @@ public static MemorySegment nsetMouseButtonCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetMouseButtonCallback(MemorySegment, MemorySegment) nsetMouseButtonCallback */ - public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { + static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { return nsetMouseButtonCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4648,7 +4650,7 @@ public static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullab * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetCursorPosCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4666,7 +4668,7 @@ public static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySe * library had not been initialized. * @see #nsetCursorPosCallback(MemorySegment, MemorySegment) nsetCursorPosCallback */ - public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { + static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { return nsetCursorPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4688,7 +4690,7 @@ public static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetCursorEnterCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4706,7 +4708,7 @@ public static MemorySegment nsetCursorEnterCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetCursorEnterCallback(MemorySegment, MemorySegment) nsetCursorEnterCallback */ - public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { + static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { return nsetCursorEnterCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4731,7 +4733,7 @@ public static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullab * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetScrollCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4749,7 +4751,7 @@ public static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegme * library had not been initialized. * @see #nsetScrollCallback(MemorySegment, MemorySegment) nsetScrollCallback */ - public static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { + static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { return nsetScrollCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4776,7 +4778,7 @@ public static MemorySegment setScrollCallback(MemorySegment window, @Nullable GL * @glfw.remark Wayland: File drop is currently unimplemented. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback) { + static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback) { try { return (MemorySegment) glfwSetDropCallback.invokeExact(window, callback); } catch (Throwable e) { @@ -4794,7 +4796,7 @@ public static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetDropCallback(MemorySegment, MemorySegment) nsetDropCallback */ - public static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { + static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { return nsetDropCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4813,7 +4815,7 @@ public static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFW * {@link #INVALID_ENUM} and {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static boolean joystickPresent(int jid) { + static boolean joystickPresent(int jid) { try { return (int) glfwJoystickPresent.invokeExact(jid) != FALSE; } catch (Throwable e) { @@ -4845,7 +4847,7 @@ public static boolean joystickPresent(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { + static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { try { return (MemorySegment) glfwGetJoystickAxes.invokeExact(jid, count); } catch (Throwable e) { @@ -4862,7 +4864,7 @@ public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * occurred. * @see #ngetJoystickAxes(int, MemorySegment) ngetJoystickAxes */ - public static float @Nullable [] getJoystickAxes(int jid) { + static float @Nullable [] getJoystickAxes(int jid) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); MemorySegment pAxes; @@ -4908,7 +4910,7 @@ public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { + static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { try { return (MemorySegment) glfwGetJoystickButtons.invokeExact(jid, count); } catch (Throwable e) { @@ -4924,7 +4926,7 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickButtons(int, MemorySegment) ngetJoystickButtons */ - public static boolean @Nullable [] getJoystickButtons(int jid) { + static boolean @Nullable [] getJoystickButtons(int jid) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); MemorySegment pButtons; @@ -4991,7 +4993,7 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { + static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { try { return (MemorySegment) glfwGetJoystickHats.invokeExact(jid, count); } catch (Throwable e) { @@ -5007,7 +5009,7 @@ public static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickHats(int, MemorySegment) ngetJoystickHats */ - public static byte[] getJoystickHats(int jid) { + static byte[] getJoystickHats(int jid) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { @@ -5040,7 +5042,7 @@ public static byte[] getJoystickHats(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickName(int jid) { + static MemorySegment ngetJoystickName(int jid) { try { return (MemorySegment) glfwGetJoystickName.invokeExact(jid); } catch (Throwable e) { @@ -5057,7 +5059,7 @@ public static MemorySegment ngetJoystickName(int jid) { * @see #ngetJoystickName(int) ngetJoystickName */ @Nullable - public static String getJoystickName(int jid) { + static String getJoystickName(int jid) { var pName = ngetJoystickName(jid); return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); } @@ -5093,7 +5095,7 @@ public static String getJoystickName(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickGUID(int jid) { + static MemorySegment ngetJoystickGUID(int jid) { try { return (MemorySegment) glfwGetJoystickGUID.invokeExact(jid); } catch (Throwable e) { @@ -5110,7 +5112,7 @@ public static MemorySegment ngetJoystickGUID(int jid) { * @see #ngetJoystickGUID(int) ngetJoystickGUID */ @Nullable - public static String getJoystickGUID(int jid) { + static String getJoystickGUID(int jid) { var pGUID = ngetJoystickGUID(jid); return RuntimeHelper.isNullptr(pGUID) ? null : pGUID.getString(0); } @@ -5132,7 +5134,7 @@ public static String getJoystickGUID(int jid) { * synchronized. * @see #getJoystickUserPointer(int) getJoystickUserPointer */ - public static void setJoystickUserPointer(int jid, MemorySegment pointer) { + static void setJoystickUserPointer(int jid, MemorySegment pointer) { try { glfwSetJoystickUserPointer.invokeExact(jid, pointer); } catch (Throwable e) { @@ -5155,7 +5157,7 @@ public static void setJoystickUserPointer(int jid, MemorySegment pointer) { * synchronized. * @see #setJoystickUserPointer(int, MemorySegment) setJoystickUserPointer */ - public static MemorySegment getJoystickUserPointer(int jid) { + static MemorySegment getJoystickUserPointer(int jid) { try { return (MemorySegment) glfwGetJoystickUserPointer.invokeExact(jid); } catch (Throwable e) { @@ -5182,7 +5184,7 @@ public static MemorySegment getJoystickUserPointer(int jid) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetGamepadState(int, MemorySegment) getGamepadState */ - public static boolean joystickIsGamepad(int jid) { + static boolean joystickIsGamepad(int jid) { try { return (int) glfwJoystickIsGamepad.invokeExact(jid) != FALSE; } catch (Throwable e) { @@ -5214,7 +5216,7 @@ public static boolean joystickIsGamepad(int jid) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetJoystickCallback(MemorySegment callback) { + static MemorySegment nsetJoystickCallback(MemorySegment callback) { try { return (MemorySegment) glfwSetJoystickCallback.invokeExact(callback); } catch (Throwable e) { @@ -5231,7 +5233,7 @@ public static MemorySegment nsetJoystickCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetJoystickCallback(MemorySegment) nsetJoystickCallback */ - public static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { + static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { return nsetJoystickCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -5261,7 +5263,7 @@ public static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callba * @see #joystickIsGamepad(int) joystickIsGamepad * @see #ngetGamepadName(int) getGamepadName */ - public static boolean nupdateGamepadMappings(MemorySegment string) { + static boolean nupdateGamepadMappings(MemorySegment string) { try { return (int) glfwUpdateGamepadMappings.invokeExact(string) != FALSE; } catch (Throwable e) { @@ -5277,7 +5279,7 @@ public static boolean nupdateGamepadMappings(MemorySegment string) { * error occurred. * @see #nupdateGamepadMappings(MemorySegment) nupdateGamepadMappings */ - public static boolean updateGamepadMappings(String string) { + static boolean updateGamepadMappings(String string) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -5309,7 +5311,7 @@ public static boolean updateGamepadMappings(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #joystickIsGamepad(int) joystickIsGamepad */ - public static MemorySegment ngetGamepadName(int jid) { + static MemorySegment ngetGamepadName(int jid) { try { return (MemorySegment) glfwGetGamepadName.invokeExact(jid); } catch (Throwable e) { @@ -5327,7 +5329,7 @@ public static MemorySegment ngetGamepadName(int jid) { * @see #ngetGamepadName(int) ngetGamepadName */ @Nullable - public static String getGamepadName(int jid) { + static String getGamepadName(int jid) { var pName = ngetGamepadName(jid); return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); } @@ -5361,7 +5363,7 @@ public static String getGamepadName(int jid) { * @see #nupdateGamepadMappings(MemorySegment) updateGamepadMappings * @see #joystickIsGamepad(int) joystickIsGamepad */ - public static boolean ngetGamepadState(int jid, MemorySegment state) { + static boolean ngetGamepadState(int jid, MemorySegment state) { try { return (int) glfwGetGamepadState.invokeExact(jid, state) != FALSE; } catch (Throwable e) { @@ -5379,7 +5381,7 @@ public static boolean ngetGamepadState(int jid, MemorySegment state) { * occurred. * @see #ngetGamepadState(int, MemorySegment) ngetGamepadState */ - public static boolean getGamepadState(int jid, GLFWGamepadState state) { + static boolean getGamepadState(int jid, GLFWGamepadState state) { return ngetGamepadState(jid, state.segment()); } @@ -5397,7 +5399,7 @@ public static boolean getGamepadState(int jid, GLFWGamepadState state) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetClipboardString() getClipboardString */ - public static void nsetClipboardString(MemorySegment string) { + static void nsetClipboardString(MemorySegment string) { try { glfwSetClipboardString.invokeExact(MemorySegment.NULL, string); } catch (Throwable e) { @@ -5411,7 +5413,7 @@ public static void nsetClipboardString(MemorySegment string) { * @param string A UTF-8 encoded string. * @see #nsetClipboardString(MemorySegment) nsetClipboardString */ - public static void setClipboardString(String string) { + static void setClipboardString(String string) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -5441,7 +5443,7 @@ public static void setClipboardString(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetClipboardString(MemorySegment) setClipboardString */ - public static MemorySegment ngetClipboardString() { + static MemorySegment ngetClipboardString() { try { return (MemorySegment) glfwGetClipboardString.invokeExact(MemorySegment.NULL); } catch (Throwable e) { @@ -5457,7 +5459,7 @@ public static MemorySegment ngetClipboardString() { * @see #ngetClipboardString() ngetClipboardString */ @Nullable - public static String getClipboardString(@Deprecated MemorySegment window) { + static String getClipboardString(@Deprecated MemorySegment window) { var pString = ngetClipboardString(); return RuntimeHelper.isNullptr(pString) ? null : pString.getString(0); } @@ -5483,7 +5485,7 @@ public static String getClipboardString(@Deprecated MemorySegment window) { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #setTime}. */ - public static double getTime() { + static double getTime() { try { return (double) glfwGetTime.invokeExact(); } catch (Throwable e) { @@ -5511,7 +5513,7 @@ public static double getTime() { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #getTime}. */ - public static void setTime(double time) { + static void setTime(double time) { try { glfwSetTime.invokeExact(time); } catch (Throwable e) { @@ -5532,7 +5534,7 @@ public static void setTime(double time) { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerFrequency */ - public static long getTimerValue() { + static long getTimerValue() { try { return (long) glfwGetTimerValue.invokeExact(); } catch (Throwable e) { @@ -5551,7 +5553,7 @@ public static long getTimerValue() { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerValue */ - public static long getTimerFrequency() { + static long getTimerFrequency() { try { return (long) glfwGetTimerFrequency.invokeExact(); } catch (Throwable e) { @@ -5595,7 +5597,7 @@ public static long getTimerFrequency() { * @glfw.thread_safety This function may be called from any thread. * @see #getCurrentContext */ - public static void makeContextCurrent(MemorySegment window) { + static void makeContextCurrent(MemorySegment window) { try { glfwMakeContextCurrent.invokeExact(window); } catch (Throwable e) { @@ -5615,7 +5617,7 @@ public static void makeContextCurrent(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #makeContextCurrent */ - public static MemorySegment getCurrentContext() { + static MemorySegment getCurrentContext() { try { return (MemorySegment) glfwGetCurrentContext.invokeExact(); } catch (Throwable e) { @@ -5645,7 +5647,7 @@ public static MemorySegment getCurrentContext() { * @glfw.thread_safety This function may be called from any thread. * @see #swapInterval */ - public static void swapBuffers(MemorySegment window) { + static void swapBuffers(MemorySegment window) { try { glfwSwapBuffers.invokeExact(window); } catch (Throwable e) { @@ -5688,7 +5690,7 @@ public static void swapBuffers(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #swapBuffers */ - public static void swapInterval(int interval) { + static void swapInterval(int interval) { try { glfwSwapInterval.invokeExact(interval); } catch (Throwable e) { @@ -5725,7 +5727,7 @@ public static void swapInterval(int interval) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetProcAddress */ - public static boolean nextensionSupported(MemorySegment extension) { + static boolean nextensionSupported(MemorySegment extension) { try { return (int) glfwExtensionSupported.invokeExact(extension) != FALSE; } catch (Throwable e) { @@ -5741,7 +5743,7 @@ public static boolean nextensionSupported(MemorySegment extension) { * otherwise. * @see #nextensionSupported(MemorySegment) nextensionSupported */ - public static boolean extensionSupported(String extension) { + static boolean extensionSupported(String extension) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -5782,7 +5784,7 @@ public static boolean extensionSupported(String extension) { * @glfw.thread_safety This function may be called from any thread. * @see #nextensionSupported */ - public static MemorySegment ngetProcAddress(MemorySegment procName) { + static MemorySegment ngetProcAddress(MemorySegment procName) { try { return (MemorySegment) glfwGetProcAddress.invokeExact(procName); } catch (Throwable e) { @@ -5799,7 +5801,7 @@ public static MemorySegment ngetProcAddress(MemorySegment procName) { * error occurred. * @see #ngetProcAddress(MemorySegment) ngetProcAddress */ - public static MemorySegment getProcAddress(String procName) { + static MemorySegment getProcAddress(String procName) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { @@ -5827,7 +5829,7 @@ public static MemorySegment getProcAddress(String procName) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function may be called from any thread. */ - public static boolean vulkanSupported() { + static boolean vulkanSupported() { try { return (int) glfwVulkanSupported.invokeExact() != FALSE; } catch (Throwable e) { @@ -5867,7 +5869,7 @@ public static boolean vulkanSupported() { * library is terminated. * @glfw.thread_safety This function may be called from any thread. */ - public static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) { + static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) { try { return (MemorySegment) glfwGetRequiredInstanceExtensions.invokeExact(count); } catch (Throwable e) { @@ -5882,7 +5884,7 @@ public static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) * error occurred. * @see #ngetRequiredInstanceExtensions(MemorySegment) ngetRequiredInstanceExtensions */ - public static String @Nullable [] getRequiredInstanceExtensions() { + static String @Nullable [] getRequiredInstanceExtensions() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); MemorySegment pExt; diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java index d2da6127..20a2e3f4 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java @@ -23,7 +23,6 @@ import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; -import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; import java.lang.invoke.MethodHandle; import java.util.function.Supplier; @@ -162,32 +161,6 @@ final class Handles { glfwGetProcAddress = downcall("glfwGetProcAddress", PP), glfwVulkanSupported = downcall("glfwVulkanSupported", I), glfwGetRequiredInstanceExtensions = downcall("glfwGetRequiredInstanceExtensions", Pp); - // GLFW Native - static final MethodHandle - glfwGetWin32Adapter = downcallNative("glfwGetWin32Adapter", Pp), - glfwGetWin32Monitor = downcallNative("glfwGetWin32Monitor", Pp), - glfwGetWin32Window = downcallNative("glfwGetWin32Window", PP), - glfwGetWGLContext = downcallNative("glfwGetWGLContext", PP), - glfwGetCocoaMonitor = downcallNative("glfwGetCocoaMonitor", fd_PI), - glfwGetCocoaWindow = downcallNative("glfwGetCocoaWindow", PP), - glfwGetNSGLContext = downcallNative("glfwGetNSGLContext", PP), - glfwGetX11Display = downcallNative("glfwGetX11Display", P), - glfwGetX11Adapter = downcallNative("glfwGetX11Adapter", PJ), - glfwGetX11Monitor = downcallNative("glfwGetX11Monitor", PJ), - glfwGetX11Window = downcallNative("glfwGetX11Window", PJ), - glfwSetX11SelectionString = downcallNative("glfwSetX11SelectionString", PV), - glfwGetX11SelectionString = downcallNative("glfwGetX11SelectionString", p), - glfwGetGLXContext = downcallNative("glfwGetGLXContext", PP), - glfwGetGLXWindow = downcallNative("glfwGetGLXWindow", PJ), - glfwGetWaylandDisplay = downcallNative("glfwGetWaylandDisplay", P), - glfwGetWaylandMonitor = downcallNative("glfwGetWaylandMonitor", PP), - glfwGetWaylandWindow = downcallNative("glfwGetWaylandWindow", PP), - glfwGetEGLDisplay = downcallNative("glfwGetEGLDisplay", P), - glfwGetEGLContext = downcallNative("glfwGetEGLContext", PP), - glfwGetEGLSurface = downcallNative("glfwGetEGLSurface", PP), - glfwGetOSMesaColorBuffer = downcallNative("glfwGetOSMesaColorBuffer", PPPPPI), - glfwGetOSMesaDepthBuffer = downcallNative("glfwGetOSMesaDepthBuffer", PPPPPI), - glfwGetOSMesaContext = downcallNative("glfwGetOSMesaContext", PP); private Handles() { //no instance @@ -209,9 +182,4 @@ private static MethodHandle downcallTrivial(String name, FunctionDescriptors function) { return downcall(name, function, Linker.Option.critical(false)); } - - private static MethodHandle downcallNative(String name, - FunctionDescriptors function) { - return RuntimeHelper.downcallSafe(lookup.find(name).orElse(MemorySegment.NULL), function); - } } From 443dd7fb57f2ce4f8a076e57f68b121b0054bea2 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:45:31 +0800 Subject: [PATCH 4/4] [GLFW] Rewrite GLFW.java --- .../overrungl/internal/RuntimeHelper.java | 27 +- .../src/main/java/overrungl/glfw/GLFW.java | 1838 +++++------------ .../java/overrungl/glfw/GLFWCallbacks.java | 33 +- .../java/overrungl/glfw/GLFWErrorFun.java | 4 +- .../java/overrungl/nfd/NFDNFilterItem.java | 4 +- .../java/overrungl/nfd/NFDU8FilterItem.java | 4 +- .../overrungl/demo/glfw/GLFWJoystickTest.java | 43 +- .../demo/glfw/GLFWWindowIconTest.java | 45 +- .../java/overrungl/demo/opengl/GL10Test.java | 43 +- .../java/overrungl/demo/opengl/GL15Test.java | 43 +- .../java/overrungl/demo/opengl/GL30Test.java | 45 +- .../java/overrungl/demo/opengl/GL33Test.java | 53 +- .../test/java/overrungl/demo/util/IOUtil.java | 11 +- 13 files changed, 699 insertions(+), 1494 deletions(-) diff --git a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java index 3eb0dc38..44af12e9 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java @@ -74,21 +74,12 @@ private RuntimeHelper() { throw new IllegalStateException("Do not construct instance"); } + @Deprecated(since = "0.1.0") private static MemorySegment reinterpreting(MemorySegment pointerToPointer, int index, ToLongFunction size) { final MemorySegment seg = pointerToPointer.getAtIndex(ADDRESS, index); return seg.reinterpret(size.applyAsLong(seg)); } - /** - * Gets a UTF-8 string from the given pointer of a string. - * - * @param segment the memory segment. - * @return the string. - */ - public static String unboundPointerString(MemorySegment segment) { - return unboundPointerString(segment, 0); - } - /** * Gets a UTF-8 string from the given pointer of a string at the given index. * @@ -96,6 +87,7 @@ public static String unboundPointerString(MemorySegment segment) { * @param index the index. * @return the string. */ + @Deprecated(since = "0.1.0") public static String unboundPointerString(MemorySegment segment, int index) { return reinterpreting(segment, index, str -> MemoryUtil.strlen(str) + 1).getString(0); } @@ -180,6 +172,7 @@ public static SymbolLookup load(String module, String basename, String version) * * @param segment the segment. */ + @Deprecated(since = "0.1.0") public static boolean isNullptr(@Nullable MemorySegment segment) { return segment == null || segment.equals(MemorySegment.NULL); } @@ -193,6 +186,7 @@ public static boolean isNullptr(@Nullable MemorySegment segment) { * @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL} */ @Nullable + @Deprecated(since = "0.1.0") public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptor function, Linker.Option... options) { return isNullptr(symbol) ? null : LINKER.downcallHandle(symbol, function, options); } @@ -205,6 +199,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function * @param options the linker options associated with this linkage request. * @return a downcall method handle. */ + @Deprecated(since = "0.1.0") public static MethodHandle downcallThrow(Optional optional, FunctionDescriptor function, Linker.Option... options) { return LINKER.downcallHandle(optional.orElseThrow(), function, options); } @@ -218,6 +213,7 @@ public static MethodHandle downcallThrow(Optional optional, Funct * @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL} */ @Nullable + @Deprecated(since = "0.1.0") public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptors function, Linker.Option... options) { return downcallSafe(symbol, function.descriptor(), options); } @@ -230,6 +226,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function * @param options the linker options associated with this linkage request. * @return a downcall method handle. */ + @Deprecated(since = "0.1.0") public static MethodHandle downcallThrow(Optional optional, FunctionDescriptors function, Linker.Option... options) { return downcallThrow(optional, function.descriptor(), options); } @@ -243,6 +240,7 @@ public static MethodHandle downcallThrow(Optional optional, Funct * @param generator the generator, from a zero-length address to the array type * @return arr */ + @Deprecated(since = "0.1.0") public static T[] toArray(MemorySegment seg, T[] arr, Function generator) { for (int i = 0; i < arr.length; i++) { @@ -258,6 +256,7 @@ public static T[] toArray(MemorySegment seg, T[] arr, * @param arr the array to hold the result * @return an array of the zero-length addresses. */ + @Deprecated(since = "0.1.0") public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) { return toArray(seg, arr, Function.identity()); } @@ -269,6 +268,7 @@ public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg, String[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] = unboundPointerString(seg, i); @@ -283,6 +283,7 @@ public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg, * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static boolean[] toArray(MemorySegment seg, boolean[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] = seg.get(JAVA_BOOLEAN, i); @@ -297,6 +298,7 @@ public static boolean[] toArray(MemorySegment seg, boolean[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static byte[] toArray(MemorySegment seg, byte[] arr) { MemorySegment.copy(seg, JAVA_BYTE, 0, arr, 0, arr.length); return arr; @@ -309,6 +311,7 @@ public static byte[] toArray(MemorySegment seg, byte[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static short[] toArray(MemorySegment seg, short[] arr) { MemorySegment.copy(seg, JAVA_SHORT, 0, arr, 0, arr.length); return arr; @@ -321,6 +324,7 @@ public static short[] toArray(MemorySegment seg, short[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static int[] toArray(MemorySegment seg, int[] arr) { MemorySegment.copy(seg, JAVA_INT, 0, arr, 0, arr.length); return arr; @@ -333,6 +337,7 @@ public static int[] toArray(MemorySegment seg, int[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static long[] toArray(MemorySegment seg, long[] arr) { MemorySegment.copy(seg, JAVA_LONG, 0, arr, 0, arr.length); return arr; @@ -345,6 +350,7 @@ public static long[] toArray(MemorySegment seg, long[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static float[] toArray(MemorySegment seg, float[] arr) { MemorySegment.copy(seg, JAVA_FLOAT, 0, arr, 0, arr.length); return arr; @@ -357,6 +363,7 @@ public static float[] toArray(MemorySegment seg, float[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static double[] toArray(MemorySegment seg, double[] arr) { MemorySegment.copy(seg, JAVA_DOUBLE, 0, arr, 0, arr.length); return arr; diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java index 3dde3290..0c21ffad 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -18,8 +18,10 @@ import org.jetbrains.annotations.Nullable; import overrun.marshal.Downcall; +import overrun.marshal.MemoryStack; +import overrun.marshal.Unmarshal; +import overrun.marshal.gen.*; import overrungl.internal.RuntimeHelper; -import overrungl.util.MemoryStack; import overrungl.util.value.Pair; import overrungl.util.value.Quad; import overrungl.util.value.Triplet; @@ -41,7 +43,7 @@ public interface GLFW { /** * The instance of GLFW. */ - GLFW INSTANCE = Downcall.load(Handles.lookup); + GLFW INSTANCE = Downcall.load(lookup); /** * The major version number of the GLFW header. @@ -914,13 +916,9 @@ static String getErrorString(int errorCode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #terminate */ - static boolean init() { - try { - return (int) glfwInit.invokeExact() != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwInit") + boolean init(); /** * Terminates the GLFW library. @@ -945,13 +943,8 @@ static boolean init() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init */ - static void terminate() { - try { - glfwTerminate.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwTerminate") + void terminate(); /** * Sets the specified init hint to the desired value. @@ -973,13 +966,8 @@ static void terminate() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init() init */ - static void initHint(int hint, int value) { - try { - glfwInitHint.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwInitHint") + void initHint(int hint, int value); /** * Retrieves the version of the GLFW library. @@ -998,13 +986,8 @@ static void initHint(int hint, int value) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersionString() getVersionString */ - static void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev) { - try { - glfwGetVersion.invokeExact(major, minor, rev); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVersion") + void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev); /** * Retrieves the version of the GLFW library. @@ -1014,27 +997,8 @@ static void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment * @param rev Where to store the revision number, or {@code null}. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - static void getVersion(int @Nullable [] major, int @Nullable [] minor, int @Nullable [] rev) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pMajor = major != null ? stack.callocInt() : MemorySegment.NULL; - var pMinor = minor != null ? stack.callocInt() : MemorySegment.NULL; - var pRev = rev != null ? stack.callocInt() : MemorySegment.NULL; - ngetVersion(pMajor, pMinor, pRev); - if (major != null && major.length > 0) { - major[0] = pMajor.get(JAVA_INT, 0); - } - if (minor != null && minor.length > 0) { - minor[0] = pMinor.get(JAVA_INT, 0); - } - if (rev != null && rev.length > 0) { - rev[0] = pRev.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetVersion") + void getVersion(@Ref int @Nullable [] major, @Ref int @Nullable [] minor, @Ref int @Nullable [] rev); /** * Retrieves the version of the GLFW library. @@ -1042,19 +1006,16 @@ static void getVersion(int @Nullable [] major, int @Nullable [] minor, int @Null * @return the major, minor and revision version number * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - static Triplet.OfInt getVersion() { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pMajor = stack.callocInt(); - var pMinor = stack.callocInt(); - var pRev = stack.callocInt(); + @Skip + default Triplet.OfInt getVersion() { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pMajor = stack.ints(0); + var pMinor = stack.ints(0); + var pRev = stack.ints(0); ngetVersion(pMajor, pMinor, pRev); return new Triplet.OfInt(pMajor.get(JAVA_INT, 0), pMinor.get(JAVA_INT, 0), pRev.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1077,13 +1038,8 @@ static Triplet.OfInt getVersion() { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) getVersion */ - static MemorySegment ngetVersionString() { - try { - return (MemorySegment) glfwGetVersionString.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVersionString") + MemorySegment ngetVersionString(); /** * Returns a string describing the compile-time configuration. @@ -1091,9 +1047,10 @@ static MemorySegment ngetVersionString() { * @return The ASCII encoded GLFW version string. * @see #ngetVersionString() ngetVersionString */ - static String getVersionString() { - return ngetVersionString().getString(0); - } + @Entrypoint("glfwGetVersionString") + @SizedSeg(Unmarshal.STR_SIZE) + @StrCharset("US-ASCII") + String getVersionString(); /** * Returns and clears the last error for the calling thread. @@ -1114,13 +1071,8 @@ static String getVersionString() { * @glfw.thread_safety This function may be called from any thread. * @see #nsetErrorCallback(MemorySegment) setErrorCallback */ - static int ngetError(MemorySegment description) { - try { - return (int) glfwGetError.invokeExact(description); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetError") + int ngetError(MemorySegment description); /** * Returns and clears the last error for the calling thread. @@ -1129,20 +1081,8 @@ static int ngetError(MemorySegment description) { * @return The last error code for the calling thread, or {@link #NO_ERROR} (zero). * @see #ngetError(MemorySegment) ngetError */ - static int getError(String @Nullable [] description) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment seg = description != null ? stack.mallocPointer() : MemorySegment.NULL; - final int err = ngetError(seg); - if (description != null && description.length > 0) { - description[0] = RuntimeHelper.unboundPointerString(seg); - } - return err; - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetError") + int getError(@Ref String @Nullable [] description); /** * Returns and clears the last error for the calling thread. @@ -1150,15 +1090,12 @@ static int getError(String @Nullable [] description) { * @return the error description pointer. and the last error code for the calling thread, or {@link #NO_ERROR} (zero) * @see #ngetError(MemorySegment) ngetError */ - static Tuple2.OfObjInt getError() { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment seg = stack.mallocPointer(); + @Skip + default Tuple2.OfObjInt getError() { + try (MemoryStack stack = MemoryStack.stackPush()) { + final MemorySegment seg = stack.allocate(ADDRESS); final int err = ngetError(seg); - return new Tuple2.OfObjInt<>(RuntimeHelper.unboundPointerString(seg), err); - } finally { - stack.setPointer(stackPointer); + return new Tuple2.OfObjInt<>(Unmarshal.unmarshalAsString(seg.get(Unmarshal.STR_LAYOUT, 0L)), err); } } @@ -1190,13 +1127,8 @@ static Tuple2.OfObjInt getError() { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetError(MemorySegment) getError */ - static MemorySegment nsetErrorCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetErrorCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetErrorCallback") + MemorySegment nsetErrorCallback(MemorySegment callback); /** * Sets the error callback. @@ -1205,7 +1137,8 @@ static MemorySegment nsetErrorCallback(MemorySegment callback) { * @return The previously set callback, or {@link MemorySegment#NULL NULL} if no callback was set. * @see #nsetErrorCallback(MemorySegment) nsetErrorCallback */ - static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { + @Skip + default MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { return nsetErrorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -1227,13 +1160,8 @@ static MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getPrimaryMonitor() getPrimaryMonitor */ - static MemorySegment ngetMonitors(MemorySegment count) { - try { - return (MemorySegment) glfwGetMonitors.invokeExact(count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitors") + MemorySegment ngetMonitors(MemorySegment count); /** * Returns the currently connected monitors. @@ -1242,17 +1170,12 @@ static MemorySegment ngetMonitors(MemorySegment count) { * if an error occurred. * @see #ngetMonitors(MemorySegment) ngetMonitors */ - static MemorySegment @Nullable [] getMonitors() { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default MemorySegment @Nullable [] getMonitors() { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pMonitors = ngetMonitors(pCount); - return RuntimeHelper.isNullptr(pMonitors) ? - null : - RuntimeHelper.toArray(pMonitors, new MemorySegment[pCount.get(JAVA_INT, 0)]); - } finally { - stack.setPointer(stackPointer); + return Unmarshal.unmarshalAsAddressArray(pMonitors.reinterpret(ADDRESS.scale(0L, pCount.get(JAVA_INT, 0L)))); } } @@ -1270,13 +1193,8 @@ static MemorySegment ngetMonitors(MemorySegment count) { * {@link #ngetMonitors(MemorySegment) getMonitors}. * @see #ngetMonitors(MemorySegment) getMonitors */ - static MemorySegment getPrimaryMonitor() { - try { - return (MemorySegment) glfwGetPrimaryMonitor.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetPrimaryMonitor") + MemorySegment getPrimaryMonitor(); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1294,13 +1212,8 @@ static MemorySegment getPrimaryMonitor() { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetMonitorPos.invokeExact(monitor, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorPos") + void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1310,23 +1223,8 @@ static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegm * @param ypos Where to store the monitor y-coordinate, or {@code null}. * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorPos(monitor, px, py); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorPos") + void getMonitorPos(MemorySegment monitor, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1335,16 +1233,13 @@ static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, int @Nul * @return the monitor xy-coordinate * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - static Pair.OfInt getMonitorPos(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); + @Skip + default Pair.OfInt getMonitorPos(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); ngetMonitorPos(monitor, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1370,13 +1265,8 @@ static Pair.OfInt getMonitorPos(MemorySegment monitor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height) { - try { - glfwGetMonitorWorkarea.invokeExact(monitor, xpos, ypos, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorWorkarea") + void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height); /** * Retrieves the work area of the monitor. @@ -1388,31 +1278,8 @@ static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, Memor * @param height Where to store the monitor height, or {@code null}. * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorWorkarea(monitor, px, py, pw, ph); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_INT, 0); - } - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorWorkarea") + void getMonitorWorkarea(MemorySegment monitor, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the work area of the monitor. @@ -1421,21 +1288,18 @@ static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xpos, int * @return the monitor xy-coordinate, the monitor width and the monitor height * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); + var pw = stack.ints(0); + var ph = stack.ints(0); ngetMonitorWorkarea(monitor, px, py, pw, ph); return new Quad.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0), pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1463,13 +1327,8 @@ static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { * the current resolution and system DPI instead of querying the monitor EDID data. * @glfw.thread_safety This function must only be called from the main thread. */ - static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM) { - try { - glfwGetMonitorPhysicalSize.invokeExact(monitor, widthMM, heightMM); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorPhysicalSize") + void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM); /** * Returns the physical size of the monitor. @@ -1481,23 +1340,8 @@ static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM * monitor's display area, or {@code null}. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [] widthMM, int @Nullable [] heightMM) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = widthMM != null ? stack.callocInt() : MemorySegment.NULL; - var ph = heightMM != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorPhysicalSize(monitor, pw, ph); - if (widthMM != null && widthMM.length > 0) { - widthMM[0] = pw.get(JAVA_INT, 0); - } - if (heightMM != null && heightMM.length > 0) { - heightMM[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorPhysicalSize") + void getMonitorPhysicalSize(MemorySegment monitor, @Ref int @Nullable [] widthMM, @Ref int @Nullable [] heightMM); /** * Returns the physical size of the monitor. @@ -1506,16 +1350,13 @@ static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [] width * @return the width and height, in millimetres, of the monitor's display area. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetMonitorPhysicalSize(monitor, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1542,13 +1383,8 @@ static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale */ - static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale) { - try { - glfwGetMonitorContentScale.invokeExact(monitor, xscale, yscale); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorContentScale") + void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale); /** * Retrieves the content scale for the specified monitor. @@ -1558,23 +1394,8 @@ static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - static void getMonitorContentScale(MemorySegment monitor, float @Nullable [] xscale, float @Nullable [] yscale) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; - var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; - ngetMonitorContentScale(monitor, px, py); - if (xscale != null && xscale.length > 0) { - xscale[0] = px.get(JAVA_FLOAT, 0); - } - if (yscale != null && yscale.length > 0) { - yscale[0] = py.get(JAVA_FLOAT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorContentScale") + void getMonitorContentScale(MemorySegment monitor, @Ref float @Nullable [] xscale, @Ref float @Nullable [] yscale); /** * Retrieves the content scale for the specified monitor. @@ -1583,16 +1404,13 @@ static void getMonitorContentScale(MemorySegment monitor, float @Nullable [] xsc * @return the xy-axis content scale * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocFloat(); - var py = stack.callocFloat(); + @Skip + default Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.floats(0F); + var py = stack.floats(0F); ngetMonitorContentScale(monitor, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1612,13 +1430,8 @@ static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetMonitorName(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetMonitorName.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorName") + MemorySegment ngetMonitorName(MemorySegment monitor); /** * Returns the name of the specified monitor. @@ -1628,11 +1441,10 @@ static MemorySegment ngetMonitorName(MemorySegment monitor) { * error occurred. * @see #ngetMonitorName(MemorySegment) ngetMonitorName */ + @Entrypoint("glfwGetMonitorName") @Nullable - static String getMonitorName(MemorySegment monitor) { - var pName = ngetMonitorName(monitor); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + @SizedSeg(Unmarshal.STR_SIZE) + String getMonitorName(MemorySegment monitor); /** * Sets the user pointer of the specified monitor. @@ -1651,13 +1463,8 @@ static String getMonitorName(MemorySegment monitor) { * synchronized. * @see #getMonitorUserPointer(MemorySegment) getMonitorUserPointer */ - static void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer) { - try { - glfwSetMonitorUserPointer.invokeExact(monitor, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMonitorUserPointer") + void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer); /** * {@return the user pointer of the specified monitor} @@ -1674,13 +1481,8 @@ static void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer) * synchronized. * @see #setMonitorUserPointer(MemorySegment, MemorySegment) setMonitorUserPointer */ - static MemorySegment getMonitorUserPointer(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetMonitorUserPointer.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorUserPointer") + MemorySegment getMonitorUserPointer(MemorySegment monitor); /** * Sets the monitor configuration callback. @@ -1699,13 +1501,8 @@ static MemorySegment getMonitorUserPointer(MemorySegment monitor) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetMonitorCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetMonitorCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMonitorCallback") + MemorySegment nsetMonitorCallback(MemorySegment callback); /** * Sets the monitor configuration callback. @@ -1716,7 +1513,8 @@ static MemorySegment nsetMonitorCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetMonitorCallback(MemorySegment) nsetMonitorCallback */ - static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { + @Skip + default MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { return nsetMonitorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -1743,13 +1541,8 @@ static MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoMode(MemorySegment) getVideoMode */ - static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) { - try { - return (MemorySegment) glfwGetVideoModes.invokeExact(monitor, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVideoModes") + MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count); /** * Returns the available video modes for the specified monitor. @@ -1759,17 +1552,16 @@ static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) * error occurred. * @see #ngetVideoModes(MemorySegment, MemorySegment) ngetVideoModes */ - static @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pModes = ngetVideoModes(monitor, pCount); - return RuntimeHelper.isNullptr(pModes) ? - null : - new GLFWVidMode(pModes, pCount.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); + if (Unmarshal.isNullPointer(pModes)) { + return null; + } + final int count = pCount.get(JAVA_INT, 0); + return new GLFWVidMode(pModes.reinterpret(GLFWVidMode.LAYOUT.scale(0L, count)), count); } } @@ -1791,13 +1583,8 @@ static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoModes(MemorySegment, MemorySegment) getVideoModes */ - static MemorySegment ngetVideoMode(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetVideoMode.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVideoMode") + MemorySegment ngetVideoMode(MemorySegment monitor); /** * Returns the current mode of the specified monitor. @@ -1808,10 +1595,11 @@ static MemorySegment ngetVideoMode(MemorySegment monitor) { * @see #ngetVideoMode(MemorySegment) ngetVideoMode */ @Nullable - static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { + @Skip + default GLFWVidMode.Value getVideoMode(MemorySegment monitor) { var pMode = ngetVideoMode(monitor); - if (RuntimeHelper.isNullptr(pMode)) return null; - return new GLFWVidMode(pMode).value(); + if (Unmarshal.isNullPointer(pMode)) return null; + return new GLFWVidMode(pMode.reinterpret(GLFWVidMode.LAYOUT.byteSize())).value(); } /** @@ -1837,13 +1625,8 @@ static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { * will thus never be implemented and emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void setGamma(MemorySegment monitor, float gamma) { - try { - glfwSetGamma.invokeExact(monitor, gamma); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetGamma") + void setGamma(MemorySegment monitor, float gamma); /** * Returns the current gamma ramp for the specified monitor. @@ -1864,13 +1647,8 @@ static void setGamma(MemorySegment monitor, float gamma) { * monitor or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetGammaRamp(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetGammaRamp.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetGammaRamp") + MemorySegment ngetGammaRamp(MemorySegment monitor); /** * Returns the current gamma ramp for the specified monitor. @@ -1880,12 +1658,9 @@ static MemorySegment ngetGammaRamp(MemorySegment monitor) { * error occurred. * @see #ngetGammaRamp(MemorySegment) ngetGammaRamp */ + @Entrypoint("glfwGetGammaRamp") @Nullable - static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { - var pRamp = ngetGammaRamp(monitor); - if (RuntimeHelper.isNullptr(pRamp)) return null; - return new GLFWGammaRamp(pRamp); - } + GLFWGammaRamp getGammaRamp(MemorySegment monitor); /** * Sets the current gamma ramp for the specified monitor. @@ -1917,13 +1692,8 @@ static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { * returns. * @glfw.thread_safety This function must only be called from the main thread. */ - static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { - try { - glfwSetGammaRamp.invokeExact(monitor, ramp); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetGammaRamp") + void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp); /** * Sets the current gamma ramp for the specified monitor. @@ -1932,9 +1702,8 @@ static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { * @param ramp The gamma ramp to use. * @see #nsetGammaRamp(MemorySegment, MemorySegment) nsetGammaRamp */ - static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { - nsetGammaRamp(monitor, ramp.segment()); - } + @Entrypoint("glfwSetGammaRamp") + void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp); /** * Resets all window hints to their default values. @@ -1947,13 +1716,8 @@ static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { * @see #windowHint(int, int) windowHint * @see #nwindowHintString(int, MemorySegment) windowHintString */ - static void defaultWindowHints() { - try { - glfwDefaultWindowHints.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDefaultWindowHints") + void defaultWindowHints(); /** * Sets the specified window hint to the desired value. @@ -1981,13 +1745,8 @@ static void defaultWindowHints() { * @see #nwindowHintString(int, MemorySegment) windowHintString * @see #defaultWindowHints */ - static void windowHint(int hint, int value) { - try { - glfwWindowHint.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWindowHint") + void windowHint(int hint, int value); /** * Sets the specified window hint to the desired value. @@ -1996,9 +1755,8 @@ static void windowHint(int hint, int value) { * @param value The new value of the window hint. * @see #windowHint(int, int) */ - static void windowHint(int hint, boolean value) { - windowHint(hint, value ? TRUE : FALSE); - } + @Entrypoint("glfwWindowHint") + void windowHint(int hint, @Convert(Type.INT) boolean value); /** * Sets the specified window hint to the desired value. @@ -2028,13 +1786,8 @@ static void windowHint(int hint, boolean value) { * @see #windowHint(int, int) windowHint * @see #defaultWindowHints */ - static void nwindowHintString(int hint, MemorySegment value) { - try { - glfwWindowHintString.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWindowHintString") + void nwindowHintString(int hint, MemorySegment value); /** * Sets the specified window hint to the desired value. @@ -2043,15 +1796,8 @@ static void nwindowHintString(int hint, MemorySegment value) { * @param value The new value of the window hint. * @see #nwindowHintString(int, MemorySegment) nwindowHintString */ - static void windowHintString(int hint, String value) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - nwindowHintString(hint, stack.allocateFrom(value)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwWindowHintString") + void windowHintString(int hint, String value); /** * Creates a window and its associated context. @@ -2204,13 +1950,8 @@ static void windowHintString(int hint, String value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #destroyWindow */ - static MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share) { - try { - return (MemorySegment) glfwCreateWindow.invokeExact(width, height, title, monitor, share); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateWindow") + MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share); /** * Creates a window and its associated context. @@ -2228,15 +1969,8 @@ static MemorySegment ncreateWindow(int width, int height, MemorySegment title, M * error occurred. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) ncreateWindow */ - static MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return ncreateWindow(width, height, stack.allocateFrom(title), monitor, share); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwCreateWindow") + MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share); /** * Destroys the specified window and its context. @@ -2256,13 +1990,8 @@ static MemorySegment createWindow(int width, int height, String title, MemorySeg * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) createWindow */ - static void destroyWindow(MemorySegment window) { - try { - glfwDestroyWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDestroyWindow") + void destroyWindow(MemorySegment window); /** * Checks the close flag of the specified window. @@ -2275,13 +2004,9 @@ static void destroyWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - static boolean windowShouldClose(MemorySegment window) { - try { - return (int) glfwWindowShouldClose.invokeExact(window) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwWindowShouldClose") + boolean windowShouldClose(MemorySegment window); /** * Sets the close flag of the specified window. @@ -2296,13 +2021,8 @@ static boolean windowShouldClose(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - static void setWindowShouldClose(MemorySegment window, boolean value) { - try { - glfwSetWindowShouldClose.invokeExact(window, value ? TRUE : FALSE); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowShouldClose") + void setWindowShouldClose(MemorySegment window, @Convert(Type.INT) boolean value); /** * Sets the title of the specified window. @@ -2318,13 +2038,8 @@ static void setWindowShouldClose(MemorySegment window, boolean value) { * process events. * @glfw.thread_safety This function must only be called from the main thread. */ - static void nsetWindowTitle(MemorySegment window, MemorySegment title) { - try { - glfwSetWindowTitle.invokeExact(window, title); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowTitle") + void nsetWindowTitle(MemorySegment window, MemorySegment title); /** * Sets the title of the specified window. @@ -2333,15 +2048,8 @@ static void nsetWindowTitle(MemorySegment window, MemorySegment title) { * @param title The UTF-8 encoded window title. * @see #nsetWindowTitle(MemorySegment, MemorySegment) nsetWindowTitle */ - static void setWindowTitle(MemorySegment window, String title) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - nsetWindowTitle(window, stack.allocateFrom(title)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwSetWindowTitle") + void setWindowTitle(MemorySegment window, String title); /** * Sets the icon for the specified window. @@ -2379,13 +2087,8 @@ static void setWindowTitle(MemorySegment window, String title) { * This function always emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void nsetWindowIcon(MemorySegment window, int count, MemorySegment images) { - try { - glfwSetWindowIcon.invokeExact(window, count, images); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowIcon") + void nsetWindowIcon(MemorySegment window, int count, MemorySegment images); /** * Sets the icon for the specified window. @@ -2397,7 +2100,8 @@ static void nsetWindowIcon(MemorySegment window, int count, MemorySegment images * count is zero. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - static void setWindowIcon(MemorySegment window, int count, GLFWImage images) { + @Skip + default void setWindowIcon(MemorySegment window, int count, GLFWImage images) { if (images == null || count == 0) { nsetWindowIcon(window, 0, MemorySegment.NULL); } else { @@ -2413,7 +2117,8 @@ static void setWindowIcon(MemorySegment window, int count, GLFWImage images) { * revert to the default window icon. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - static void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { + @Skip + default void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { setWindowIcon(window, images == null ? 0 : Math.toIntExact(images.elementCount()), images); } @@ -2439,13 +2144,8 @@ static void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowPos(MemorySegment, int, int) setWindowPos */ - static void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetWindowPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowPos") + void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos); /** * Retrieves the position of the content area of the specified window. @@ -2456,23 +2156,8 @@ static void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegmen * @param ypos Where to store the y-coordinate of the upper-left corner of * the content area, or {@code null}. */ - static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowPos(window, px, py); - if (xpos != null && xpos.length > 1) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 1) { - ypos[0] = py.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowPos") + void getWindowPos(MemorySegment window, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos); /** * Retrieves the position of the content area of the specified window. @@ -2480,16 +2165,13 @@ static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int @Nulla * @param window The window to query. * @return the xy-coordinate of the upper-left corner of the content area. */ - static Pair.OfInt getWindowPos(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); + @Skip + default Pair.OfInt getWindowPos(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); ngetWindowPos(window, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2517,13 +2199,8 @@ static Pair.OfInt getWindowPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowPos(MemorySegment, MemorySegment, MemorySegment) getWindowPos */ - static void setWindowPos(MemorySegment window, int xpos, int ypos) { - try { - glfwSetWindowPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowPos") + void setWindowPos(MemorySegment window, int xpos, int ypos); /** * Retrieves the size of the content area of the specified window. @@ -2546,13 +2223,8 @@ static void setWindowPos(MemorySegment window, int xpos, int ypos) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - static void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height) { - try { - glfwGetWindowSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowSize") + void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height); /** * Retrieves the size of the content area of the specified window. @@ -2564,23 +2236,8 @@ static void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegm * content area, or {@code null}. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - static void getWindowSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowSize(window, pw, ph); - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowSize") + void getWindowSize(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the size of the content area of the specified window. @@ -2589,16 +2246,13 @@ static void getWindowSize(MemorySegment window, int @Nullable [] width, int @Nul * @return the width and height, in screen coordinates, of the content area. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - static Pair.OfInt getWindowSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getWindowSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetWindowSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2635,13 +2289,8 @@ static Pair.OfInt getWindowSize(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAspectRatio(MemorySegment, int, int) setWindowAspectRatio */ - static void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight) { - try { - glfwSetWindowSizeLimits.invokeExact(window, minWidth, minHeight, maxWidth, maxHeight); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSizeLimits") + void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight); /** * Sets the aspect ratio of the specified window. @@ -2676,13 +2325,8 @@ static void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeigh * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSizeLimits(MemorySegment, int, int, int, int) setWindowSizeLimits */ - static void setWindowAspectRatio(MemorySegment window, int numer, int denom) { - try { - glfwSetWindowAspectRatio.invokeExact(window, numer, denom); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowAspectRatio") + void setWindowAspectRatio(MemorySegment window, int numer, int denom); /** * Sets the size of the content area of the specified window. @@ -2715,13 +2359,8 @@ static void setWindowAspectRatio(MemorySegment window, int numer, int denom) { * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) getWindowSize * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - static void setWindowSize(MemorySegment window, int width, int height) { - try { - glfwSetWindowSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSize") + void setWindowSize(MemorySegment window, int width, int height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2743,13 +2382,8 @@ static void setWindowSize(MemorySegment window, int width, int height) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) setFramebufferSizeCallback */ - static void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height) { - try { - glfwGetFramebufferSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetFramebufferSize") + void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2761,23 +2395,8 @@ static void ngetFramebufferSize(MemorySegment window, MemorySegment width, Memor * or {@code null}. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - static void getFramebufferSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetFramebufferSize(window, pw, ph); - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetFramebufferSize") + void getFramebufferSize(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2786,16 +2405,13 @@ static void getFramebufferSize(MemorySegment window, int @Nullable [] width, int * @return the width and height, in pixels, of the framebuffer. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - static Pair.OfInt getFramebufferSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getFramebufferSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetFramebufferSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2828,13 +2444,8 @@ static Pair.OfInt getFramebufferSize(MemorySegment window) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom) { - try { - glfwGetWindowFrameSize.invokeExact(window, left, top, right, bottom); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowFrameSize") + void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom); /** * Retrieves the size of the frame of the window. @@ -2850,31 +2461,8 @@ static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, Memory * bottom edge of the window frame, or {@code null}. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - static void getWindowFrameSize(MemorySegment window, int @Nullable [] left, int @Nullable [] top, int @Nullable [] right, int @Nullable [] bottom) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pl = left != null ? stack.callocInt() : MemorySegment.NULL; - var pt = top != null ? stack.callocInt() : MemorySegment.NULL; - var pr = right != null ? stack.callocInt() : MemorySegment.NULL; - var pb = bottom != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowFrameSize(window, pl, pt, pr, pb); - if (left != null && left.length > 0) { - left[0] = pl.get(JAVA_INT, 0); - } - if (top != null && top.length > 0) { - top[0] = pt.get(JAVA_INT, 0); - } - if (right != null && right.length > 0) { - right[0] = pr.get(JAVA_INT, 0); - } - if (bottom != null && bottom.length > 0) { - bottom[0] = pb.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowFrameSize") + void getWindowFrameSize(MemorySegment window, @Ref int @Nullable [] left, @Ref int @Nullable [] top, @Ref int @Nullable [] right, @Ref int @Nullable [] bottom); /** * Retrieves the size of the frame of the window. @@ -2884,21 +2472,18 @@ static void getWindowFrameSize(MemorySegment window, int @Nullable [] left, int * edge of the window frame. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - static Quad.OfInt getWindowFrameSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pl = stack.callocInt(); - var pt = stack.callocInt(); - var pr = stack.callocInt(); - var pb = stack.callocInt(); + @Skip + default Quad.OfInt getWindowFrameSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pl = stack.ints(0); + var pt = stack.ints(0); + var pr = stack.ints(0); + var pb = stack.ints(0); ngetWindowFrameSize(window, pl, pt, pr, pb); return new Quad.OfInt(pl.get(JAVA_INT, 0), pt.get(JAVA_INT, 0), pr.get(JAVA_INT, 0), pb.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2926,13 +2511,8 @@ static Quad.OfInt getWindowFrameSize(MemorySegment window) { * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) setWindowContentScaleCallback * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) getMonitorContentScale */ - static void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale) { - try { - glfwGetWindowContentScale.invokeExact(window, xscale, yscale); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowContentScale") + void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale); /** * Retrieves the content scale for the specified window. @@ -2942,23 +2522,8 @@ static void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, M * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - static void getWindowContentScale(MemorySegment window, float @Nullable [] xscale, float @Nullable [] yscale) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; - var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; - ngetWindowContentScale(window, px, py); - if (xscale != null && xscale.length > 0) { - xscale[0] = px.get(JAVA_FLOAT, 0); - } - if (yscale != null && yscale.length > 0) { - yscale[0] = py.get(JAVA_FLOAT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowContentScale") + void getWindowContentScale(MemorySegment window, @Ref float @Nullable [] xscale, @Ref float @Nullable [] yscale); /** * Retrieves the content scale for the specified window. @@ -2967,16 +2532,13 @@ static void getWindowContentScale(MemorySegment window, float @Nullable [] xscal * @return the xy-axis content scale. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - static Pair.OfFloat getWindowContentScale(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocFloat(); - var py = stack.callocFloat(); + @Skip + default Pair.OfFloat getWindowContentScale(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.floats(0F); + var py = stack.floats(0F); ngetWindowContentScale(window, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2998,13 +2560,8 @@ static Pair.OfFloat getWindowContentScale(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowOpacity(MemorySegment, float) setWindowOpacity */ - static float getWindowOpacity(MemorySegment window) { - try { - return (float) glfwGetWindowOpacity.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowOpacity") + float getWindowOpacity(MemorySegment window); /** * Sets the opacity of the whole window. @@ -3026,13 +2583,8 @@ static float getWindowOpacity(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowOpacity(MemorySegment) getWindowOpacity */ - static void setWindowOpacity(MemorySegment window, float opacity) { - try { - glfwSetWindowOpacity.invokeExact(window, opacity); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowOpacity") + void setWindowOpacity(MemorySegment window, float opacity); /** * Iconifies the specified window. @@ -3052,13 +2604,8 @@ static void setWindowOpacity(MemorySegment window, float opacity) { * @see #restoreWindow(MemorySegment) restoreWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - static void iconifyWindow(MemorySegment window) { - try { - glfwIconifyWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwIconifyWindow") + void iconifyWindow(MemorySegment window); /** * Restores the specified window. @@ -3077,13 +2624,8 @@ static void iconifyWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - static void restoreWindow(MemorySegment window) { - try { - glfwRestoreWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwRestoreWindow") + void restoreWindow(MemorySegment window); /** * Maximizes the specified window. @@ -3100,13 +2642,8 @@ static void restoreWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #restoreWindow(MemorySegment) restoreWindow */ - static void maximizeWindow(MemorySegment window) { - try { - glfwMaximizeWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwMaximizeWindow") + void maximizeWindow(MemorySegment window); /** * Makes the specified window visible. @@ -3130,13 +2667,8 @@ static void maximizeWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #hideWindow(MemorySegment) hideWindow */ - static void showWindow(MemorySegment window) { - try { - glfwShowWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwShowWindow") + void showWindow(MemorySegment window); /** * Hides the specified window. @@ -3151,13 +2683,8 @@ static void showWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #showWindow(MemorySegment) showWindow */ - static void hideWindow(MemorySegment window) { - try { - glfwHideWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwHideWindow") + void hideWindow(MemorySegment window); /** * Brings the specified window to front and sets input focus. @@ -3187,13 +2714,8 @@ static void hideWindow(MemorySegment window) { * to front, this function will always emit {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void focusWindow(MemorySegment window) { - try { - glfwFocusWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwFocusWindow") + void focusWindow(MemorySegment window); /** * Requests user attention to the specified window. @@ -3212,13 +2734,8 @@ static void focusWindow(MemorySegment window) { * specific window. * @glfw.thread_safety This function must only be called from the main thread. */ - static void requestWindowAttention(MemorySegment window) { - try { - glfwRequestWindowAttention.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwRequestWindowAttention") + void requestWindowAttention(MemorySegment window); /** * Returns the monitor that the window uses for full screen mode. @@ -3233,13 +2750,8 @@ static void requestWindowAttention(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - static MemorySegment getWindowMonitor(MemorySegment window) { - try { - return (MemorySegment) glfwGetWindowMonitor.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowMonitor") + MemorySegment getWindowMonitor(MemorySegment window); /** * Sets the mode, monitor, video mode and placement of a window. @@ -3289,13 +2801,8 @@ static MemorySegment getWindowMonitor(MemorySegment window) { * @see #getWindowMonitor(MemorySegment) getWindowMonitor * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate) { - try { - glfwSetWindowMonitor.invokeExact(window, monitor, xpos, ypos, width, height, refreshRate); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowMonitor") + void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate); /** * Returns an attribute of the specified window. @@ -3324,13 +2831,8 @@ static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xp * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAttrib(MemorySegment, int, boolean) setWindowAttrib */ - static int getWindowAttrib(MemorySegment window, int attrib) { - try { - return (int) glfwGetWindowAttrib.invokeExact(window, attrib); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowAttrib") + int getWindowAttrib(MemorySegment window, int attrib); /** * Sets an attribute of the specified window. @@ -3359,13 +2861,8 @@ static int getWindowAttrib(MemorySegment window, int attrib) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowAttrib(MemorySegment, int) getWindowAttrib */ - static void setWindowAttrib(MemorySegment window, int attrib, boolean value) { - try { - glfwSetWindowAttrib.invokeExact(window, attrib, value ? TRUE : FALSE); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowAttrib") + void setWindowAttrib(MemorySegment window, int attrib, @Convert(Type.INT) boolean value); /** * Sets the user pointer of the specified window. @@ -3381,13 +2878,8 @@ static void setWindowAttrib(MemorySegment window, int attrib, boolean value) { * synchronized. * @see #getWindowUserPointer(MemorySegment) getWindowUserPointer */ - static void setWindowUserPointer(MemorySegment window, MemorySegment pointer) { - try { - glfwSetWindowUserPointer.invokeExact(window, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowUserPointer") + void setWindowUserPointer(MemorySegment window, MemorySegment pointer); /** * {@return the user pointer of the specified window} @@ -3401,13 +2893,8 @@ static void setWindowUserPointer(MemorySegment window, MemorySegment pointer) { * synchronized. * @see #setWindowUserPointer(MemorySegment, MemorySegment) setWindowUserPointer */ - static MemorySegment getWindowUserPointer(MemorySegment window) { - try { - return (MemorySegment) glfwGetWindowUserPointer.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowUserPointer") + MemorySegment getWindowUserPointer(MemorySegment window); /** * Sets the position callback for the specified window. @@ -3430,13 +2917,8 @@ static MemorySegment getWindowUserPointer(MemorySegment window) { * an application to know its global position. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowPosCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowPosCallback") + MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback); /** * Sets the position callback for the specified window. @@ -3448,7 +2930,8 @@ static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment c * library had not been initialized. * @see #nsetWindowPosCallback(MemorySegment, MemorySegment) nsetWindowPosCallback */ - static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { + @Skip + default MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { return nsetWindowPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3470,13 +2953,8 @@ static MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWi * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowSizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSizeCallback") + MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the size callback for the specified window. @@ -3488,7 +2966,8 @@ static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetWindowSizeCallback(MemorySegment, MemorySegment) nsetWindowSizeCallback */ - static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { + @Skip + default MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { return nsetWindowSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3517,13 +2996,8 @@ static MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWW * close callback for all windows. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowCloseCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowCloseCallback") + MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback); /** * Sets the close callback for the specified window. @@ -3535,7 +3009,8 @@ static MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetWindowCloseCallback(MemorySegment, MemorySegment) nsetWindowCloseCallback */ - static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { + @Skip + default MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { return nsetWindowCloseCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3561,13 +3036,8 @@ static MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFW * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowRefreshCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowRefreshCallback") + MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback); /** * Sets the refresh callback for the specified window. @@ -3579,7 +3049,8 @@ static MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegme * library had not been initialized. * @see #nsetWindowRefreshCallback(MemorySegment, MemorySegment) nsetWindowRefreshCallback */ - static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { + @Skip + default MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { return nsetWindowRefreshCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3606,13 +3077,8 @@ static MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GL * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowFocusCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowFocusCallback") + MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback); /** * Sets the focus callback for the specified window. @@ -3624,7 +3090,8 @@ static MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetWindowFocusCallback(MemorySegment, MemorySegment) nsetWindowFocusCallback */ - static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { + @Skip + default MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { return nsetWindowFocusCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3647,13 +3114,8 @@ static MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFW * this callback will never be called. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowIconifyCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowIconifyCallback") + MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback); /** * Sets the iconify callback for the specified window. @@ -3665,7 +3127,8 @@ static MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegme * library had not been initialized. * @see #nsetWindowIconifyCallback(MemorySegment, MemorySegment) nsetWindowIconifyCallback */ - static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { + @Skip + default MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { return nsetWindowIconifyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3686,13 +3149,8 @@ static MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GL * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowMaximizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowMaximizeCallback") + MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the maximize callback for the specified window. @@ -3704,7 +3162,8 @@ static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegm * library had not been initialized. * @see #nsetWindowMaximizeCallback(MemorySegment, MemorySegment) nsetWindowMaximizeCallback */ - static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { + @Skip + default MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { return nsetWindowMaximizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3725,13 +3184,8 @@ static MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable G * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetFramebufferSizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetFramebufferSizeCallback") + MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the framebuffer resize callback for the specified window. @@ -3743,7 +3197,8 @@ static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySeg * library had not been initialized. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) nsetFramebufferSizeCallback */ - static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { + @Skip + default MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { return nsetFramebufferSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3765,13 +3220,8 @@ static MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale */ - static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowContentScaleCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowContentScaleCallback") + MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback); /** * Sets the window content scale callback for the specified window. @@ -3783,7 +3233,8 @@ static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, Memory * library had not been initialized. * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) nsetWindowContentScaleCallback */ - static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { + @Skip + default MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { return nsetWindowContentScaleCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -3817,13 +3268,8 @@ static MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullab * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - static void pollEvents() { - try { - glfwPollEvents.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwPollEvents") + void pollEvents(); /** * Waits until events are queued and processes them. @@ -3861,13 +3307,8 @@ static void pollEvents() { * @see #pollEvents() pollEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - static void waitEvents() { - try { - glfwWaitEvents.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWaitEvents") + void waitEvents(); /** * Waits with timeout until events are queued and processes them. @@ -3908,13 +3349,8 @@ static void waitEvents() { * @see #pollEvents() pollEvents * @see #waitEvents() waitEvents */ - static void waitEventsTimeout(double timeout) { - try { - glfwWaitEventsTimeout.invokeExact(timeout); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWaitEventsTimeout") + void waitEventsTimeout(double timeout); /** * Posts an empty event to the event queue. @@ -3928,13 +3364,8 @@ static void waitEventsTimeout(double timeout) { * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - static void postEmptyEvents() { - try { - glfwPostEmptyEvent.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwPostEmptyEvent") + void postEmptyEvents(); /** * {@return the value of an input option for the specified window} @@ -3953,13 +3384,8 @@ static void postEmptyEvents() { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - static int getInputMode(MemorySegment window, int mode) { - try { - return (int) glfwGetInputMode.invokeExact(window, mode); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetInputMode") + int getInputMode(MemorySegment window, int mode); /** * Sets an input option for the specified window. @@ -4017,13 +3443,8 @@ static int getInputMode(MemorySegment window, int mode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getInputMode(MemorySegment, int) getInputMode */ - static void setInputMode(MemorySegment window, int mode, int value) { - try { - glfwSetInputMode.invokeExact(window, mode, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetInputMode") + void setInputMode(MemorySegment window, int mode, int value); /** * Returns whether raw mouse motion is supported. @@ -4045,13 +3466,9 @@ static void setInputMode(MemorySegment window, int mode, int value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - static boolean rawMouseMotionSupported() { - try { - return (int) glfwRawMouseMotionSupported.invokeExact() != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwRawMouseMotionSupported") + boolean rawMouseMotionSupported(); /** * Returns the layout-specific name of the specified printable key. @@ -4114,13 +3531,8 @@ static boolean rawMouseMotionSupported() { * should not free it yourself. It is valid until the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetKeyName(int key, int scancode) { - try { - return (MemorySegment) glfwGetKeyName.invokeExact(key, scancode); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKeyName") + MemorySegment ngetKeyName(int key, int scancode); /** * Returns the layout-specific name of the specified printable key. @@ -4130,11 +3542,9 @@ static MemorySegment ngetKeyName(int key, int scancode) { * @return The UTF-8 encoded, layout-specific name of the key, or {@code null}. * @see #ngetKeyName(int, int) ngetKeyName */ + @Entrypoint("glfwGetKeyName") @Nullable - static String getKeyName(int key, int scancode) { - var pName = ngetKeyName(key, scancode); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getKeyName(int key, int scancode); /** * Returns the platform-specific scancode of the specified key. @@ -4153,13 +3563,8 @@ static String getKeyName(int key, int scancode) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and {@link #INVALID_ENUM}. * @glfw.thread_safety This function may be called from any thread. */ - static int getKeyScancode(int key) { - try { - return (int) glfwGetKeyScancode.invokeExact(key); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKeyScancode") + int getKeyScancode(int key); /** * Returns the last reported state of a keyboard key for the specified @@ -4192,13 +3597,8 @@ static int getKeyScancode(int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - static int getKey(MemorySegment window, int key) { - try { - return (int) glfwGetKey.invokeExact(window, key); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKey") + int getKey(MemorySegment window, int key); /** * Returns the last reported state of a mouse button for the specified @@ -4219,13 +3619,8 @@ static int getKey(MemorySegment window, int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - static int getMouseButton(MemorySegment window, int button) { - try { - return (int) glfwGetMouseButton.invokeExact(window, button); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMouseButton") + int getMouseButton(MemorySegment window, int button); /** * Retrieves the position of the cursor relative to the content area of @@ -4256,13 +3651,8 @@ static int getMouseButton(MemorySegment window, int button) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setCursorPos(MemorySegment, double, double) setCursorPos */ - static void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetCursorPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetCursorPos") + void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos); /** * Retrieves the position of the cursor relative to the content area of @@ -4275,23 +3665,8 @@ static void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegmen * top edge of the content area, or {@code null}. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - static void getCursorPos(MemorySegment window, double @Nullable [] xpos, double @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocDouble() : MemorySegment.NULL; - var py = ypos != null ? stack.callocDouble() : MemorySegment.NULL; - ngetCursorPos(window, px, py); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_DOUBLE, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_DOUBLE, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetCursorPos") + void getCursorPos(MemorySegment window, @Ref double @Nullable [] xpos, @Ref double @Nullable [] ypos); /** * Retrieves the position of the cursor relative to the content area of @@ -4301,16 +3676,13 @@ static void getCursorPos(MemorySegment window, double @Nullable [] xpos, double * @return the cursor xy-coordinate, relative to the left and top edge of the content area. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - static Pair.OfDouble getCursorPos(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocDouble(); - var py = stack.callocDouble(); + @Skip + default Pair.OfDouble getCursorPos(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.doubles(0D); + var py = stack.doubles(0D); ngetCursorPos(window, px, py); return new Pair.OfDouble(px.get(JAVA_DOUBLE, 0), py.get(JAVA_DOUBLE, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -4344,13 +3716,8 @@ static Pair.OfDouble getCursorPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) getCursorPos */ - static void setCursorPos(MemorySegment window, double xpos, double ypos) { - try { - glfwSetCursorPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorPos") + void setCursorPos(MemorySegment window, double xpos, double ypos); /** * Creates a custom cursor. @@ -4380,13 +3747,8 @@ static void setCursorPos(MemorySegment window, double xpos, double ypos) { * @see #destroyCursor(MemorySegment) destroyCursor * @see #createStandardCursor(int) createStandardCursor */ - static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot) { - try { - return (MemorySegment) glfwCreateCursor.invokeExact(image, xhot, yhot); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateCursor") + MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot); /** * Creates a custom cursor. @@ -4398,9 +3760,8 @@ static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot) { * error occurred. * @see #ncreateCursor(MemorySegment, int, int) ncreateCursor */ - static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { - return ncreateCursor(image.segment(), xhot, yhot); - } + @Entrypoint("glfwCreateCursor") + MemorySegment createCursor(GLFWImage image, int xhot, int yhot); /** * Creates a cursor with a standard shape. @@ -4417,13 +3778,8 @@ static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - static MemorySegment createStandardCursor(int shape) { - try { - return (MemorySegment) glfwCreateStandardCursor.invokeExact(shape); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateStandardCursor") + MemorySegment createStandardCursor(int shape); /** * Destroys a cursor. @@ -4442,13 +3798,8 @@ static MemorySegment createStandardCursor(int shape) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - static void destroyCursor(MemorySegment cursor) { - try { - glfwDestroyCursor.invokeExact(cursor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDestroyCursor") + void destroyCursor(MemorySegment cursor); /** * Sets the cursor for the window. @@ -4468,13 +3819,8 @@ static void destroyCursor(MemorySegment cursor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static void setCursor(MemorySegment window, MemorySegment cursor) { - try { - glfwSetCursor.invokeExact(window, cursor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursor") + void setCursor(MemorySegment window, MemorySegment cursor); /** * Sets the key callback. @@ -4513,13 +3859,8 @@ static void setCursor(MemorySegment window, MemorySegment cursor) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetKeyCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetKeyCallback") + MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback); /** * Sets the key callback. @@ -4531,7 +3872,8 @@ static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callbac * library had not been initialized. * @see #nsetKeyCallback(MemorySegment, MemorySegment) nsetKeyCallback */ - static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { + @Skip + default MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { return nsetKeyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4564,13 +3906,8 @@ static MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun c * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCharCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCharCallback") + MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback); /** * Sets the Unicode character callback. @@ -4582,7 +3919,8 @@ static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callba * library had not been initialized. * @see #nsetCharCallback(MemorySegment, MemorySegment) nsetCharCallback */ - static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { + @Skip + default MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { return nsetCharCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4609,13 +3947,8 @@ static MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetMouseButtonCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMouseButtonCallback") + MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback); /** * Sets the mouse button callback. @@ -4627,7 +3960,8 @@ static MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetMouseButtonCallback(MemorySegment, MemorySegment) nsetMouseButtonCallback */ - static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { + @Skip + default MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { return nsetMouseButtonCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4650,13 +3984,8 @@ static MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFW * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCursorPosCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorPosCallback") + MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback); /** * Sets the cursor position callback. @@ -4668,7 +3997,8 @@ static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment c * library had not been initialized. * @see #nsetCursorPosCallback(MemorySegment, MemorySegment) nsetCursorPosCallback */ - static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { + @Skip + default MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { return nsetCursorPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4690,13 +4020,8 @@ static MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCu * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCursorEnterCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorEnterCallback") + MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback); /** * Sets the cursor enter/leave callback. @@ -4708,7 +4033,8 @@ static MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment * library had not been initialized. * @see #nsetCursorEnterCallback(MemorySegment, MemorySegment) nsetCursorEnterCallback */ - static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { + @Skip + default MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { return nsetCursorEnterCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4733,13 +4059,8 @@ static MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFW * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetScrollCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetScrollCallback") + MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback); /** * Sets the scroll callback. @@ -4751,7 +4072,8 @@ static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment call * library had not been initialized. * @see #nsetScrollCallback(MemorySegment, MemorySegment) nsetScrollCallback */ - static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { + @Skip + default MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { return nsetScrollCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4778,13 +4100,8 @@ static MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrol * @glfw.remark Wayland: File drop is currently unimplemented. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetDropCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetDropCallback") + MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback); /** * Sets the path drop callback. @@ -4796,7 +4113,8 @@ static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callba * library had not been initialized. * @see #nsetDropCallback(MemorySegment, MemorySegment) nsetDropCallback */ - static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { + @Skip + default MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { return nsetDropCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } @@ -4815,13 +4133,9 @@ static MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun * {@link #INVALID_ENUM} and {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - static boolean joystickPresent(int jid) { - try { - return (int) glfwJoystickPresent.invokeExact(jid) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwJoystickPresent") + boolean joystickPresent(int jid); /** * Returns the values of all axes of the specified joystick. @@ -4847,13 +4161,8 @@ static boolean joystickPresent(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickAxes.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickAxes") + MemorySegment ngetJoystickAxes(int jid, MemorySegment count); /** * Returns the values of all axes of the specified joystick. @@ -4864,20 +4173,15 @@ static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * occurred. * @see #ngetJoystickAxes(int, MemorySegment) ngetJoystickAxes */ - static float @Nullable [] getJoystickAxes(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - MemorySegment pAxes; - final int count; - try { - var pCount = stack.callocInt(); - pAxes = ngetJoystickAxes(jid, pCount); - count = pCount.get(JAVA_INT, 0); - } finally { - stack.setPointer(stackPointer); + @Skip + default float @Nullable [] getJoystickAxes(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); + MemorySegment pAxes = ngetJoystickAxes(jid, pCount); + final int count = pCount.get(JAVA_INT, 0); + if (count == 0) return null; + return Unmarshal.unmarshalAsFloatArray(pAxes.reinterpret(JAVA_FLOAT.scale(0L, count))); } - if (count == 0) return null; - return RuntimeHelper.toArray(pAxes, new float[count]); } /** @@ -4910,13 +4214,8 @@ static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickButtons.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickButtons") + MemorySegment ngetJoystickButtons(int jid, MemorySegment count); /** * Returns the state of all buttons of the specified joystick. @@ -4926,24 +4225,15 @@ static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickButtons(int, MemorySegment) ngetJoystickButtons */ - static boolean @Nullable [] getJoystickButtons(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - MemorySegment pButtons; - final int count; - try { - var pCount = stack.callocInt(); - pButtons = ngetJoystickButtons(jid, pCount); - count = pCount.get(JAVA_INT, 0); - } finally { - stack.setPointer(stackPointer); - } - if (count == 0) return null; - boolean[] buttons = new boolean[count]; - for (int i = 0; i < count; i++) { - buttons[i] = pButtons.getAtIndex(JAVA_INT, i) == PRESS; + @Skip + default int @Nullable [] getJoystickButtons(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); + MemorySegment pButtons = ngetJoystickButtons(jid, pCount); + final int count = pCount.get(JAVA_INT, 0); + if (count == 0) return null; + return Unmarshal.unmarshalAsIntArray(pButtons.reinterpret(JAVA_INT.scale(0L, count))); } - return buttons; } /** @@ -4969,7 +4259,6 @@ static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * The diagonal directions are bitwise combinations of the primary (up, right, * down and left) directions, and you can test for these individually by ANDing * it with the corresponding direction. - * * {@snippet lang = java: * if (hats[2] & HAT_RIGHT) { * // State of hat 2 could be right-up, right or right-down @@ -4993,13 +4282,8 @@ static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickHats.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickHats") + MemorySegment ngetJoystickHats(int jid, MemorySegment count); /** * Returns the state of all hats of the specified joystick. @@ -5009,15 +4293,12 @@ static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickHats(int, MemorySegment) ngetJoystickHats */ - static byte[] getJoystickHats(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default byte[] getJoystickHats(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pHats = ngetJoystickHats(jid, pCount); - return RuntimeHelper.toArray(pHats, new byte[pCount.get(JAVA_INT, 0)]); - } finally { - stack.setPointer(stackPointer); + return Unmarshal.unmarshalAsByteArray(pHats.reinterpret(JAVA_BYTE.scale(0L, pCount.get(JAVA_INT, 0)))); } } @@ -5042,13 +4323,8 @@ static byte[] getJoystickHats(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetJoystickName(int jid) { - try { - return (MemorySegment) glfwGetJoystickName.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickName") + MemorySegment ngetJoystickName(int jid); /** * Returns the name of the specified joystick. @@ -5058,11 +4334,9 @@ static MemorySegment ngetJoystickName(int jid) { * is not present or an error occurred. * @see #ngetJoystickName(int) ngetJoystickName */ + @Entrypoint("glfwGetJoystickName") @Nullable - static String getJoystickName(int jid) { - var pName = ngetJoystickName(jid); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getJoystickName(int jid); /** * Returns the SDL compatible GUID of the specified joystick. @@ -5095,13 +4369,8 @@ static String getJoystickName(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment ngetJoystickGUID(int jid) { - try { - return (MemorySegment) glfwGetJoystickGUID.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickGUID") + MemorySegment ngetJoystickGUID(int jid); /** * Returns the SDL compatible GUID of the specified joystick. @@ -5111,11 +4380,9 @@ static MemorySegment ngetJoystickGUID(int jid) { * is not present or an error occurred. * @see #ngetJoystickGUID(int) ngetJoystickGUID */ + @Entrypoint("glfwGetJoystickGUID") @Nullable - static String getJoystickGUID(int jid) { - var pGUID = ngetJoystickGUID(jid); - return RuntimeHelper.isNullptr(pGUID) ? null : pGUID.getString(0); - } + String getJoystickGUID(int jid); /** * Sets the user pointer of the specified joystick. @@ -5134,13 +4401,8 @@ static String getJoystickGUID(int jid) { * synchronized. * @see #getJoystickUserPointer(int) getJoystickUserPointer */ - static void setJoystickUserPointer(int jid, MemorySegment pointer) { - try { - glfwSetJoystickUserPointer.invokeExact(jid, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetJoystickUserPointer") + void setJoystickUserPointer(int jid, MemorySegment pointer); /** * {@return the user pointer of the specified joystick} @@ -5157,13 +4419,8 @@ static void setJoystickUserPointer(int jid, MemorySegment pointer) { * synchronized. * @see #setJoystickUserPointer(int, MemorySegment) setJoystickUserPointer */ - static MemorySegment getJoystickUserPointer(int jid) { - try { - return (MemorySegment) glfwGetJoystickUserPointer.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickUserPointer") + MemorySegment getJoystickUserPointer(int jid); /** * Returns whether the specified joystick has a gamepad mapping. @@ -5184,13 +4441,9 @@ static MemorySegment getJoystickUserPointer(int jid) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetGamepadState(int, MemorySegment) getGamepadState */ - static boolean joystickIsGamepad(int jid) { - try { - return (int) glfwJoystickIsGamepad.invokeExact(jid) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwJoystickIsGamepad") + boolean joystickIsGamepad(int jid); /** * Sets the joystick configuration callback. @@ -5216,13 +4469,8 @@ static boolean joystickIsGamepad(int jid) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function must only be called from the main thread. */ - static MemorySegment nsetJoystickCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetJoystickCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetJoystickCallback") + MemorySegment nsetJoystickCallback(MemorySegment callback); /** * Sets the joystick configuration callback. @@ -5233,7 +4481,8 @@ static MemorySegment nsetJoystickCallback(MemorySegment callback) { * library had not been initialized. * @see #nsetJoystickCallback(MemorySegment) nsetJoystickCallback */ - static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { + @Skip + default MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { return nsetJoystickCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } @@ -5263,13 +4512,9 @@ static MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { * @see #joystickIsGamepad(int) joystickIsGamepad * @see #ngetGamepadName(int) getGamepadName */ - static boolean nupdateGamepadMappings(MemorySegment string) { - try { - return (int) glfwUpdateGamepadMappings.invokeExact(string) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwUpdateGamepadMappings") + boolean nupdateGamepadMappings(MemorySegment string); /** * Adds the specified SDL_GameControllerDB gamepad mappings. @@ -5279,15 +4524,9 @@ static boolean nupdateGamepadMappings(MemorySegment string) { * error occurred. * @see #nupdateGamepadMappings(MemorySegment) nupdateGamepadMappings */ - static boolean updateGamepadMappings(String string) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return nupdateGamepadMappings(stack.allocateFrom(string)); - } finally { - stack.setPointer(stackPointer); - } - } + @Convert(Type.INT) + @Entrypoint("glfwUpdateGamepadMappings") + boolean updateGamepadMappings(String string); /** * Returns the human-readable gamepad name for the specified joystick. @@ -5311,13 +4550,8 @@ static boolean updateGamepadMappings(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #joystickIsGamepad(int) joystickIsGamepad */ - static MemorySegment ngetGamepadName(int jid) { - try { - return (MemorySegment) glfwGetGamepadName.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetGamepadName") + MemorySegment ngetGamepadName(int jid); /** * Returns the human-readable gamepad name for the specified joystick. @@ -5328,11 +4562,9 @@ static MemorySegment ngetGamepadName(int jid) { * error occurred. * @see #ngetGamepadName(int) ngetGamepadName */ + @Entrypoint("glfwGetGamepadName") @Nullable - static String getGamepadName(int jid) { - var pName = ngetGamepadName(jid); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getGamepadName(int jid); /** * Retrieves the state of the specified joystick remapped as a gamepad. @@ -5363,13 +4595,9 @@ static String getGamepadName(int jid) { * @see #nupdateGamepadMappings(MemorySegment) updateGamepadMappings * @see #joystickIsGamepad(int) joystickIsGamepad */ - static boolean ngetGamepadState(int jid, MemorySegment state) { - try { - return (int) glfwGetGamepadState.invokeExact(jid, state) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwGetGamepadState") + boolean ngetGamepadState(int jid, MemorySegment state); /** * Retrieves the state of the specified joystick remapped as a gamepad. @@ -5381,9 +4609,9 @@ static boolean ngetGamepadState(int jid, MemorySegment state) { * occurred. * @see #ngetGamepadState(int, MemorySegment) ngetGamepadState */ - static boolean getGamepadState(int jid, GLFWGamepadState state) { - return ngetGamepadState(jid, state.segment()); - } + @Convert(Type.INT) + @Entrypoint("glfwGetGamepadState") + boolean getGamepadState(int jid, GLFWGamepadState state); /** * Sets the clipboard to the specified string. @@ -5391,6 +4619,7 @@ static boolean getGamepadState(int jid, GLFWGamepadState state) { * This function sets the system clipboard to the specified, UTF-8 encoded * string. * + * @param window window Deprecated. Any valid window or {@code NULL}. * @param string A UTF-8 encoded string. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and * {@link #PLATFORM_ERROR}. @@ -5399,12 +4628,26 @@ static boolean getGamepadState(int jid, GLFWGamepadState state) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetClipboardString() getClipboardString */ - static void nsetClipboardString(MemorySegment string) { - try { - glfwSetClipboardString.invokeExact(MemorySegment.NULL, string); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwSetClipboardString") + void nsetClipboardString(MemorySegment window, MemorySegment string); + + /** + * Sets the clipboard to the specified string. + *

+ * This function sets the system clipboard to the specified, UTF-8 encoded + * string. + * + * @param string A UTF-8 encoded string. + * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and + * {@link #PLATFORM_ERROR}. + * @glfw.pointer_lifetime The specified string is copied before this function + * returns. + * @glfw.thread_safety This function must only be called from the main thread. + * @see #ngetClipboardString() getClipboardString + */ + @Skip + default void nsetClipboardString(MemorySegment string) { + nsetClipboardString(MemorySegment.NULL, string); } /** @@ -5413,13 +4656,10 @@ static void nsetClipboardString(MemorySegment string) { * @param string A UTF-8 encoded string. * @see #nsetClipboardString(MemorySegment) nsetClipboardString */ - static void setClipboardString(String string) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { + @Skip + default void setClipboardString(String string) { + try (MemoryStack stack = MemoryStack.stackPush()) { nsetClipboardString(stack.allocateFrom(string)); - } finally { - stack.setPointer(stackPointer); } } @@ -5431,6 +4671,7 @@ static void setClipboardString(String string) { * if its contents cannot be converted, {@link MemorySegment#NULL NULL} is returned and a * {@link #FORMAT_UNAVAILABLE} error is generated. * + * @param window Deprecated. Any valid window or {@code NULL}. * @return The contents of the clipboard as a UTF-8 encoded string, or {@link MemorySegment#NULL NULL} * if an error occurred. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}, @@ -5443,12 +4684,33 @@ static void setClipboardString(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetClipboardString(MemorySegment) setClipboardString */ - static MemorySegment ngetClipboardString() { - try { - return (MemorySegment) glfwGetClipboardString.invokeExact(MemorySegment.NULL); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwGetClipboardString") + @SizedSeg(Unmarshal.STR_SIZE) + MemorySegment ngetClipboardString(MemorySegment window); + + /** + * Returns the contents of the clipboard as a string. + *

+ * This function returns the contents of the system clipboard, if it contains + * or is convertible to a UTF-8 encoded string. If the clipboard is empty or + * if its contents cannot be converted, {@link MemorySegment#NULL NULL} is returned and a + * {@link #FORMAT_UNAVAILABLE} error is generated. + * + * @return The contents of the clipboard as a UTF-8 encoded string, or {@link MemorySegment#NULL NULL} + * if an error occurred. + * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}, + * {@link #FORMAT_UNAVAILABLE} and {@link #PLATFORM_ERROR}. + * @glfw.pointer_lifetime The returned string is allocated and freed by GLFW. You + * should not free it yourself. It is valid until the next call to + * {@code getClipboardString} or + * {@link #nsetClipboardString(MemorySegment) setClipboardString}, + * or until the library is terminated. + * @glfw.thread_safety This function must only be called from the main thread. + * @see #nsetClipboardString(MemorySegment) setClipboardString + */ + @Skip + default MemorySegment ngetClipboardString() { + return ngetClipboardString(MemorySegment.NULL); } /** @@ -5458,10 +4720,10 @@ static MemorySegment ngetClipboardString() { * if an error occurred. * @see #ngetClipboardString() ngetClipboardString */ + @Skip @Nullable - static String getClipboardString(@Deprecated MemorySegment window) { - var pString = ngetClipboardString(); - return RuntimeHelper.isNullptr(pString) ? null : pString.getString(0); + default String getClipboardString() { + return ngetClipboardString().getString(0L); } /** @@ -5485,13 +4747,8 @@ static String getClipboardString(@Deprecated MemorySegment window) { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #setTime}. */ - static double getTime() { - try { - return (double) glfwGetTime.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetTime") + double getTime(); /** * Sets the GLFW time. @@ -5513,13 +4770,8 @@ static double getTime() { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #getTime}. */ - static void setTime(double time) { - try { - glfwSetTime.invokeExact(time); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetTime") + void setTime(double time); /** * Returns the current value of the raw timer. @@ -5534,13 +4786,8 @@ static void setTime(double time) { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerFrequency */ - static long getTimerValue() { - try { - return (long) glfwGetTimerValue.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetTimerValue") + long getTimerValue(); /** * Returns the frequency, in Hz, of the raw timer. @@ -5553,13 +4800,8 @@ static long getTimerValue() { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerValue */ - static long getTimerFrequency() { - try { - return (long) glfwGetTimerFrequency.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetTimerFrequency") + long getTimerFrequency(); /** * Makes the context of the specified window current for the calling @@ -5597,13 +4839,8 @@ static long getTimerFrequency() { * @glfw.thread_safety This function may be called from any thread. * @see #getCurrentContext */ - static void makeContextCurrent(MemorySegment window) { - try { - glfwMakeContextCurrent.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwMakeContextCurrent") + void makeContextCurrent(MemorySegment window); /** * Returns the window whose context is current on the calling thread. @@ -5617,13 +4854,8 @@ static void makeContextCurrent(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #makeContextCurrent */ - static MemorySegment getCurrentContext() { - try { - return (MemorySegment) glfwGetCurrentContext.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetCurrentContext") + MemorySegment getCurrentContext(); /** * Swaps the front and back buffers of the specified window. @@ -5647,13 +4879,8 @@ static MemorySegment getCurrentContext() { * @glfw.thread_safety This function may be called from any thread. * @see #swapInterval */ - static void swapBuffers(MemorySegment window) { - try { - glfwSwapBuffers.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSwapBuffers") + void swapBuffers(MemorySegment window); /** * Sets the swap interval for the current context. @@ -5690,13 +4917,8 @@ static void swapBuffers(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #swapBuffers */ - static void swapInterval(int interval) { - try { - glfwSwapInterval.invokeExact(interval); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSwapInterval") + void swapInterval(int interval); /** * Returns whether the specified extension is available. @@ -5727,13 +4949,9 @@ static void swapInterval(int interval) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetProcAddress */ - static boolean nextensionSupported(MemorySegment extension) { - try { - return (int) glfwExtensionSupported.invokeExact(extension) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwExtensionSupported") + boolean nextensionSupported(MemorySegment extension); /** * Returns whether the specified extension is available. @@ -5743,15 +4961,9 @@ static boolean nextensionSupported(MemorySegment extension) { * otherwise. * @see #nextensionSupported(MemorySegment) nextensionSupported */ - static boolean extensionSupported(String extension) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return nextensionSupported(stack.allocateFrom(extension)); - } finally { - stack.setPointer(stackPointer); - } - } + @Convert(Type.INT) + @Entrypoint("glfwExtensionSupported") + boolean extensionSupported(@StrCharset("US-ASCII") String extension); /** * Returns the address of the specified function for the current @@ -5784,13 +4996,8 @@ static boolean extensionSupported(String extension) { * @glfw.thread_safety This function may be called from any thread. * @see #nextensionSupported */ - static MemorySegment ngetProcAddress(MemorySegment procName) { - try { - return (MemorySegment) glfwGetProcAddress.invokeExact(procName); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetProcAddress") + MemorySegment ngetProcAddress(MemorySegment procName); /** * Returns the address of the specified function for the current @@ -5801,15 +5008,8 @@ static MemorySegment ngetProcAddress(MemorySegment procName) { * error occurred. * @see #ngetProcAddress(MemorySegment) ngetProcAddress */ - static MemorySegment getProcAddress(String procName) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return ngetProcAddress(stack.allocateFrom(procName)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetProcAddress") + MemorySegment getProcAddress(String procName); /** * Returns whether the Vulkan loader and an ICD have been found. @@ -5829,13 +5029,9 @@ static MemorySegment getProcAddress(String procName) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function may be called from any thread. */ - static boolean vulkanSupported() { - try { - return (int) glfwVulkanSupported.invokeExact() != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwVulkanSupported") + boolean vulkanSupported(); /** * Returns the Vulkan instance extensions required by GLFW. @@ -5869,13 +5065,8 @@ static boolean vulkanSupported() { * library is terminated. * @glfw.thread_safety This function may be called from any thread. */ - static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) { - try { - return (MemorySegment) glfwGetRequiredInstanceExtensions.invokeExact(count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetRequiredInstanceExtensions") + MemorySegment ngetRequiredInstanceExtensions(MemorySegment count); /** * Returns the Vulkan instance extensions required by GLFW. @@ -5884,19 +5075,14 @@ static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) { * error occurred. * @see #ngetRequiredInstanceExtensions(MemorySegment) ngetRequiredInstanceExtensions */ - static String @Nullable [] getRequiredInstanceExtensions() { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - MemorySegment pExt; - final int count; - try { - var pCount = stack.callocInt(); - pExt = ngetRequiredInstanceExtensions(pCount); - count = pCount.get(JAVA_INT, 0); - } finally { - stack.setPointer(stackPointer); + @Skip + default String @Nullable [] getRequiredInstanceExtensions() { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); + MemorySegment pExt = ngetRequiredInstanceExtensions(pCount); + final int count = pCount.get(JAVA_INT, 0); + if (count == 0) return null; + return Unmarshal.unmarshalAsStringArray(pExt.reinterpret(ADDRESS.scale(0L, count))); } - if (count == 0) return null; - return RuntimeHelper.toUnboundedArray(pExt, new String[count]); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java index 8aebde72..99d03e85 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java @@ -52,22 +52,23 @@ public static Arena create(MemorySegment window) { */ public static void free(MemorySegment window) { if (ARENA_MAP.containsKey(window)) { - GLFW.setCharCallback(window, null); - GLFW.setCursorEnterCallback(window, null); - GLFW.setCursorPosCallback(window, null); - GLFW.setDropCallback(window, null); - GLFW.setFramebufferSizeCallback(window, null); - GLFW.setKeyCallback(window, null); - GLFW.setMouseButtonCallback(window, null); - GLFW.setScrollCallback(window, null); - GLFW.setWindowCloseCallback(window, null); - GLFW.setWindowContentScaleCallback(window, null); - GLFW.setWindowFocusCallback(window, null); - GLFW.setWindowIconifyCallback(window, null); - GLFW.setWindowMaximizeCallback(window, null); - GLFW.setWindowPosCallback(window, null); - GLFW.setWindowRefreshCallback(window, null); - GLFW.setWindowSizeCallback(window, null); + final GLFW glfw = GLFW.INSTANCE; + glfw.setCharCallback(window, null); + glfw.setCursorEnterCallback(window, null); + glfw.setCursorPosCallback(window, null); + glfw.setDropCallback(window, null); + glfw.setFramebufferSizeCallback(window, null); + glfw.setKeyCallback(window, null); + glfw.setMouseButtonCallback(window, null); + glfw.setScrollCallback(window, null); + glfw.setWindowCloseCallback(window, null); + glfw.setWindowContentScaleCallback(window, null); + glfw.setWindowFocusCallback(window, null); + glfw.setWindowIconifyCallback(window, null); + glfw.setWindowMaximizeCallback(window, null); + glfw.setWindowPosCallback(window, null); + glfw.setWindowRefreshCallback(window, null); + glfw.setWindowSizeCallback(window, null); ARENA_MAP.remove(window).close(); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java index 93a333ed..a8751f40 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java @@ -68,10 +68,10 @@ default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarsh /** * Sets the error callback. * - * @return The previous callback or {@code NULL}. + * @return The previously set callback, or {@link MemorySegment#NULL NULL} if no callback was set. */ default MemorySegment set() { - return GLFW.setErrorCallback(this); + return GLFW.INSTANCE.setErrorCallback(this); } @Override diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java index e8f5317a..5856d329 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java @@ -99,8 +99,8 @@ public static NFDNFilterItem create(SegmentAllocator allocator, Pair... final NFDNFilterItem buffer = new NFDNFilterItem(allocator.allocate(LAYOUT, items.length), items.length); for (int i = 0, len = items.length; i < len; i++) { Pair item = items[i]; - buffer._name.set(allocator, i, item.key()); - buffer._spec.set(allocator, i, item.value()); + buffer._name.set(i, allocator, item.key()); + buffer._spec.set(i, allocator, item.value()); } return buffer; } diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java index cb206a89..81a2e229 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java @@ -99,8 +99,8 @@ public static NFDU8FilterItem create(SegmentAllocator allocator, Pair... final NFDU8FilterItem buffer = new NFDU8FilterItem(allocator.allocate(LAYOUT, items.length), items.length); for (int i = 0, len = items.length; i < len; i++) { Pair item = items[i]; - buffer._name.set(allocator, i, item.key()); - buffer._spec.set(allocator, i, item.value()); + buffer._name.set(i, allocator, item.key()); + buffer._spec.set(i, allocator, item.value()); } return buffer; } diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java index 535eb9fe..cf5e508c 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java @@ -32,6 +32,7 @@ * @since 0.1.0 */ public final class GLFWJoystickTest { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -39,38 +40,38 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - GLFW.windowHint(GLFW.CLIENT_API, GLFW.NO_API); - window = GLFW.createWindow(200, 100, "Holder", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + glfw.windowHint(GLFW.CLIENT_API, GLFW.NO_API); + window = glfw.createWindow(200, 100, "Holder", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setJoystickCallback((jid, event) -> { + glfw.setJoystickCallback((jid, event) -> { switch (event) { case GLFW.CONNECTED -> { - boolean isGamepad = GLFW.joystickIsGamepad(jid); + boolean isGamepad = glfw.joystickIsGamepad(jid); var prefix = isGamepad ? "Gamepad " : "Joystick "; - System.out.println(STR."\{prefix}\{jid}: \"\{(isGamepad ? GLFW.getGamepadName(jid) : GLFW.getJoystickName(jid))}\" has connected"); + System.out.println(STR."\{prefix}\{jid}: \"\{(isGamepad ? glfw.getGamepadName(jid) : glfw.getJoystickName(jid))}\" has connected"); } case GLFW.DISCONNECTED -> System.out.println(STR."Joystick \{jid} has disconnected"); } }); - GLFW.showWindow(window); + glfw.showWindow(window); } private void loop() { @@ -78,14 +79,14 @@ private void loop() { for (int i = 0; i < states.length; i++) { states[i] = new GLFWGamepadState(Arena.ofAuto()); } - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { for (int i = 0; i <= GLFW.JOYSTICK_LAST; i++) { - if (GLFW.joystickPresent(i)) { - if (GLFW.joystickIsGamepad(i)) { + if (glfw.joystickPresent(i)) { + if (glfw.joystickIsGamepad(i)) { var state = states[i]; - if (GLFW.getGamepadState(i, state)) { + if (glfw.getGamepadState(i, state)) { System.out.println(STR.""" - Get gamepad state for [jid=\{i},name=\{GLFW.getGamepadName(i)}] successful: + Get gamepad state for [jid=\{i},name=\{glfw.getGamepadName(i)}] successful: Buttons: [A(Cross)=\{state.button(GLFW.GAMEPAD_BUTTON_A)}, B(Circle)=\{state.button(GLFW.GAMEPAD_BUTTON_B)}, X(Square)=\{state.button(GLFW.GAMEPAD_BUTTON_X)}, Y(Triangle)=\{state.button(GLFW.GAMEPAD_BUTTON_Y)}, Left bumper=\{state.button(GLFW.GAMEPAD_BUTTON_LEFT_BUMPER)}, Right bumper=\{state.button(GLFW.GAMEPAD_BUTTON_RIGHT_BUMPER)}, Back=\{state.button(GLFW.GAMEPAD_BUTTON_BACK)}, Start=\{state.button(GLFW.GAMEPAD_BUTTON_START)}, Guide=\{state.button(GLFW.GAMEPAD_BUTTON_GUIDE)}, Left thumb=\{state.button(GLFW.GAMEPAD_BUTTON_LEFT_THUMB)}, Right thumb=\{state.button(GLFW.GAMEPAD_BUTTON_RIGHT_THUMB)}, @@ -96,7 +97,7 @@ private void loop() { } } } - GLFW.waitEventsTimeout(3); + glfw.waitEventsTimeout(3); } } diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java index cacff5c4..1443f4c0 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GLFWWindowIconTest { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -50,19 +51,19 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init(Arena arena) { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); try { @@ -78,48 +79,48 @@ private void init(Arena arena) { image.width.set(px.get(JAVA_INT, 0)); image.height.set(py.get(JAVA_INT, 0)); image.pixels.set(data); - GLFW.setWindowIcon(window, image); + glfw.setWindowIcon(window, image); stbImage.free(data); } catch (IOException e) { throw new RuntimeException(e); } - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load() { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java index 4dbf2a8e..5cc93b34 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java @@ -34,6 +34,7 @@ * @since 0.1.0 */ public final class GL10Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -42,51 +43,51 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load() { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle @@ -99,9 +100,9 @@ private void loop() { GL10.vertex2f(0.5f, -0.5f); GL10.end(); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java index 768103ba..076543de 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GL15Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int vbo, tex; @@ -54,45 +55,45 @@ public void run() { GL.deleteTexture(tex); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(640, 480, "OpenGL 1.5", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(640, 480, "OpenGL 1.5", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); GL.enable(GL.TEXTURE_2D); @@ -137,7 +138,7 @@ private void load(Arena arena) { } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle @@ -158,9 +159,9 @@ private void loop() { GL.bindBuffer(GL.ARRAY_BUFFER, 0); GL.bindTexture(GL.TEXTURE_2D, 0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java index 5d3cee9b..95200ff4 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GL30Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int program; private int colorFactor; @@ -60,45 +61,45 @@ public void run() { GL.deleteTexture(tex); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(640, 480, "OpenGL 3.0", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(640, 480, "OpenGL 3.0", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); @@ -201,22 +202,22 @@ void main() { } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle GL.bindTexture(GL.TEXTURE_2D, tex); GL.useProgram(program); - GL.uniform1f(colorFactor, (float) ((Math.sin(GLFW.getTime() * 2) + 1 * 0.5) * 0.6 + 0.4)); + GL.uniform1f(colorFactor, (float) ((Math.sin(glfw.getTime() * 2) + 1 * 0.5) * 0.6 + 0.4)); GL.bindVertexArray(vao); GL.drawElements(GL.TRIANGLES, 6, GL.UNSIGNED_BYTE, MemorySegment.NULL); GL.bindVertexArray(0); GL.useProgram(0); GL.bindTexture(GL.TEXTURE_2D, 0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java index 420a0ad9..7eef2b79 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java @@ -43,6 +43,7 @@ public class GL33Test { private static final int INSTANCE_COUNT = square(10); private static final String WND_TITLE = "OpenGL 3.3"; private static final boolean VSYNC = true; + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int program; private int rotationMat; @@ -68,49 +69,49 @@ public void run() { } GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); debugProc.close(); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - GLFW.windowHint(GLFW.CONTEXT_VERSION_MAJOR, 3); - GLFW.windowHint(GLFW.CONTEXT_VERSION_MINOR, 3); - GLFW.windowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE); - window = GLFW.createWindow(640, 480, WND_TITLE, MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + glfw.windowHint(GLFW.CONTEXT_VERSION_MAJOR, 3); + glfw.windowHint(GLFW.CONTEXT_VERSION_MINOR, 3); + glfw.windowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE); + window = glfw.createWindow(640, 480, WND_TITLE, MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - if (VSYNC) GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + if (VSYNC) glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); debugProc = GLUtil.setupDebugMessageCallback(); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); @@ -222,9 +223,9 @@ private void loop() { var matrix = new Matrix4f(); var pRotationMat = Matrixn.allocate(Arena.ofAuto(), matrix); - var timer = Timer.ofGetter(20, GLFW::getTime); + var timer = Timer.ofGetter(20, glfw::getTime); - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { timer.advanceTime(); timer.performTicks(null); @@ -243,13 +244,13 @@ private void loop() { GL.bindVertexArray(0); GL.useProgram(0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); // using lambda gets higher FPS ?? timer.calcFPS(fps -> { - GLFW.setWindowTitle(window, STR."\{WND_TITLE} FPS: \{fps}"); + glfw.setWindowTitle(window, STR."\{WND_TITLE} FPS: \{fps}"); }); } } diff --git a/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java b/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java index f2336550..089e04df 100644 --- a/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java +++ b/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java @@ -69,7 +69,8 @@ public static MemorySegment ioResourceToSegment(Arena arena, String resource, lo Objects.requireNonNull(IOUtil.class.getClassLoader().getResourceAsStream(resource), STR."Failed to load resource '\{resource}'!") ) { - MemorySegment segment = arena.allocate(segmentSize); + Arena readArena = Arena.ofConfined(); + MemorySegment segment = readArena.allocate(segmentSize); // Creates a byte array to avoid creating it each loop final byte[] bytes = new byte[bufferSize]; @@ -77,13 +78,17 @@ public static MemorySegment ioResourceToSegment(Arena arena, String resource, lo int count; while ((count = is.read(bytes)) > 0) { if (pos + count >= segment.byteSize()) { - segment = resizeSegment(arena, segment, Math.ceilDiv(segment.byteSize() * 3, 2)); // 50% + Arena newArena = Arena.ofConfined(); + segment = resizeSegment(newArena, segment, Math.ceilDiv(segment.byteSize() * 3, 2)); // 50% + readArena.close(); + readArena = newArena; } MemorySegment.copy(bytes, 0, segment, ValueLayout.JAVA_BYTE, pos, count); pos += count; } + readArena.close(); - return segment.asSlice(0, pos); + return segment.asSlice(0, pos).reinterpret(arena, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(STR."Illegal URI: \{resource}", e); }