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
* 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. *
* 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 @@
*
* 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
* 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* 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 { *
@@ -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 { *
@@ -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 { *
+ * 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