diff --git a/gradle.properties b/gradle.properties index ecfbe7ee..f0013a91 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,5 @@ jdkEnablePreview=true jdkEarlyAccessDoc=jdk22 kotlinTargetJdkVersion=21 -overrunMarshalVersion=0.1.0-alpha.9-jdk22 +overrunMarshalVersion=0.1.0-alpha.10-jdk22 overrunPlatformVersion=1.0.0 - -cLibraryVersion=0.1.0.0 diff --git a/modules/overrungl.core/src/main/java/overrungl/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..44af12e9 100644 --- a/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java +++ b/modules/overrungl.core/src/main/java/overrungl/internal/RuntimeHelper.java @@ -60,6 +60,9 @@ public final class RuntimeHelper { public static final boolean CHECKS = Configurations.CHECKS.get(); private static final StackWalker STACK_WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); private static final Map CANONICAL_LAYOUTS = LINKER.canonicalLayouts(); + /** + * Some canonical layouts + */ public static final MemoryLayout LONG = CANONICAL_LAYOUTS.get("long"), SIZE_T = CANONICAL_LAYOUTS.get("size_t"), WCHAR_T = CANONICAL_LAYOUTS.get("wchar_t"); @@ -71,21 +74,12 @@ private RuntimeHelper() { throw new IllegalStateException("Do not construct instance"); } + @Deprecated(since = "0.1.0") private static MemorySegment reinterpreting(MemorySegment pointerToPointer, int index, ToLongFunction size) { final MemorySegment seg = pointerToPointer.getAtIndex(ADDRESS, index); return seg.reinterpret(size.applyAsLong(seg)); } - /** - * Gets a UTF-8 string from the given pointer of a string. - * - * @param segment the memory segment. - * @return the string. - */ - public static String unboundPointerString(MemorySegment segment) { - return unboundPointerString(segment, 0); - } - /** * Gets a UTF-8 string from the given pointer of a string at the given index. * @@ -93,20 +87,11 @@ public static String unboundPointerString(MemorySegment segment) { * @param index the index. * @return the string. */ + @Deprecated(since = "0.1.0") public static String unboundPointerString(MemorySegment segment, int index) { return reinterpreting(segment, index, str -> MemoryUtil.strlen(str) + 1).getString(0); } - /** - * 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. * @@ -187,6 +172,7 @@ public static SymbolLookup load(String module, String basename, String version) * * @param segment the segment. */ + @Deprecated(since = "0.1.0") public static boolean isNullptr(@Nullable MemorySegment segment) { return segment == null || segment.equals(MemorySegment.NULL); } @@ -200,6 +186,7 @@ public static boolean isNullptr(@Nullable MemorySegment segment) { * @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL} */ @Nullable + @Deprecated(since = "0.1.0") public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptor function, Linker.Option... options) { return isNullptr(symbol) ? null : LINKER.downcallHandle(symbol, function, options); } @@ -212,6 +199,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function * @param options the linker options associated with this linkage request. * @return a downcall method handle. */ + @Deprecated(since = "0.1.0") public static MethodHandle downcallThrow(Optional optional, FunctionDescriptor function, Linker.Option... options) { return LINKER.downcallHandle(optional.orElseThrow(), function, options); } @@ -225,6 +213,7 @@ public static MethodHandle downcallThrow(Optional optional, Funct * @return a downcall method handle. or {@code null} if the symbol {@link MemorySegment#NULL} */ @Nullable + @Deprecated(since = "0.1.0") public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, FunctionDescriptors function, Linker.Option... options) { return downcallSafe(symbol, function.descriptor(), options); } @@ -237,6 +226,7 @@ public static MethodHandle downcallSafe(@Nullable MemorySegment symbol, Function * @param options the linker options associated with this linkage request. * @return a downcall method handle. */ + @Deprecated(since = "0.1.0") public static MethodHandle downcallThrow(Optional optional, FunctionDescriptors function, Linker.Option... options) { return downcallThrow(optional, function.descriptor(), options); } @@ -250,6 +240,7 @@ public static MethodHandle downcallThrow(Optional optional, Funct * @param generator the generator, from a zero-length address to the array type * @return arr */ + @Deprecated(since = "0.1.0") public static T[] toArray(MemorySegment seg, T[] arr, Function generator) { for (int i = 0; i < arr.length; i++) { @@ -265,6 +256,7 @@ public static T[] toArray(MemorySegment seg, T[] arr, * @param arr the array to hold the result * @return an array of the zero-length addresses. */ + @Deprecated(since = "0.1.0") public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) { return toArray(seg, arr, Function.identity()); } @@ -276,6 +268,7 @@ public static MemorySegment[] toArray(MemorySegment seg, MemorySegment[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg, String[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] = unboundPointerString(seg, i); @@ -290,6 +283,7 @@ public static String[] toUnboundedArray(@NativeType("char**") MemorySegment seg, * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static boolean[] toArray(MemorySegment seg, boolean[] arr) { for (int i = 0; i < arr.length; i++) { arr[i] = seg.get(JAVA_BOOLEAN, i); @@ -304,6 +298,7 @@ public static boolean[] toArray(MemorySegment seg, boolean[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static byte[] toArray(MemorySegment seg, byte[] arr) { MemorySegment.copy(seg, JAVA_BYTE, 0, arr, 0, arr.length); return arr; @@ -316,6 +311,7 @@ public static byte[] toArray(MemorySegment seg, byte[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static short[] toArray(MemorySegment seg, short[] arr) { MemorySegment.copy(seg, JAVA_SHORT, 0, arr, 0, arr.length); return arr; @@ -328,6 +324,7 @@ public static short[] toArray(MemorySegment seg, short[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static int[] toArray(MemorySegment seg, int[] arr) { MemorySegment.copy(seg, JAVA_INT, 0, arr, 0, arr.length); return arr; @@ -340,6 +337,7 @@ public static int[] toArray(MemorySegment seg, int[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static long[] toArray(MemorySegment seg, long[] arr) { MemorySegment.copy(seg, JAVA_LONG, 0, arr, 0, arr.length); return arr; @@ -352,6 +350,7 @@ public static long[] toArray(MemorySegment seg, long[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static float[] toArray(MemorySegment seg, float[] arr) { MemorySegment.copy(seg, JAVA_FLOAT, 0, arr, 0, arr.length); return arr; @@ -364,6 +363,7 @@ public static float[] toArray(MemorySegment seg, float[] arr) { * @param arr the array to hold the result * @return arr */ + @Deprecated(since = "0.1.0") public static double[] toArray(MemorySegment seg, double[] arr) { MemorySegment.copy(seg, JAVA_DOUBLE, 0, arr, 0, arr.length); return arr; diff --git a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java index 62d44085..1fe6bf5c 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/DebugAllocator.java @@ -20,7 +20,6 @@ import org.jetbrains.annotations.Nullable; import overrungl.Configurations; import overrungl.OverrunGL; -import overrungl.internal.Exceptions; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -99,7 +98,7 @@ private static void trackAbort(long address, Allocation allocationOld, Allocatio trackAbortPrint(allocationOld, "Old", addressHex); trackAbortPrint(allocationNew, "New", addressHex); - throw Exceptions.ISE."The memory address specified is already being tracked: 0x\{addressHex}"; + throw new IllegalStateException(STR."The memory address specified is already being tracked: 0x\{addressHex}"); } private static void trackAbortPrint(Allocation allocation, String name, String address) { @@ -138,7 +137,7 @@ static long untrack(long address) { private static void untrackAbort(long address) { String addressHex = Long.toHexString(address).toUpperCase(); - throw Exceptions.ISE."The memory address specified is not being tracked: 0x\{addressHex}"; + throw new IllegalStateException(STR."The memory address specified is not being tracked: 0x\{addressHex}"); } private record Allocation(long address, long size, long threadId, @Nullable Object[] stacktrace) { diff --git a/modules/overrungl.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..0c21ffad 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -17,9 +17,11 @@ package overrungl.glfw; import org.jetbrains.annotations.Nullable; +import overrun.marshal.Downcall; +import overrun.marshal.MemoryStack; +import overrun.marshal.Unmarshal; +import overrun.marshal.gen.*; import overrungl.internal.RuntimeHelper; -import overrungl.util.MemoryStack; -import overrungl.util.MemoryUtil; import overrungl.util.value.Pair; import overrungl.util.value.Quad; import overrungl.util.value.Triplet; @@ -37,25 +39,30 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFW { +public interface GLFW { + /** + * The instance of GLFW. + */ + GLFW INSTANCE = Downcall.load(lookup); + /** * The major version number of the GLFW header. *

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

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

* This is incremented when a bug fix release is made that does not contain any API changes. */ - public static final int VERSION_REVISION = 9; + int VERSION_REVISION = 9; /** * One. @@ -64,7 +71,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. *

@@ -72,25 +79,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, @@ -104,12 +111,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, /* - */ @@ -163,7 +170,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, @@ -234,39 +241,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, @@ -282,7 +289,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, @@ -303,7 +310,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, @@ -328,7 +335,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, @@ -342,7 +349,7 @@ public final class GLFW { *

Analysis

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

@@ -353,7 +360,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. *

@@ -365,7 +372,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}. @@ -373,7 +380,7 @@ public final class GLFW { *

Analysis

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

Analysis

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

@@ -453,7 +460,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. *

@@ -463,7 +470,7 @@ public final class GLFW { *

Analysis

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

Window related hints

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

Framebuffer related hints

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

Context related hints

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

macOS specific window hints

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

Cursor mode

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

macOS specific init hints

*
    @@ -840,7 +847,7 @@ public final class GLFW { * when the first window is created, which is when AppKit is initialized. Set this with {@link #initHint}. *
*/ - public static final int COCOA_CHDIR_RESOURCES = 0x00051001, + int COCOA_CHDIR_RESOURCES = 0x00051001, COCOA_MENUBAR = 0x00051002; /** * Wayland specific init hint. @@ -849,16 +856,12 @@ public final class GLFW { * Possible values are {@link #WAYLAND_PREFER_LIBDECOR} and {@link #WAYLAND_DISABLE_LIBDECOR}. * This is ignored on other platforms. */ - public static final int WAYLAND_LIBDECOR = 0x00053001; + int WAYLAND_LIBDECOR = 0x00053001; /** * Don't care value. */ - public static final int DONT_CARE = -1; - - private GLFW() { - throw new IllegalStateException("Do not construct instance"); - } + int DONT_CARE = -1; /** * Converts the given error code to a readable string. @@ -868,7 +871,7 @@ private GLFW() { * @param errorCode the error code. * @return the error string. */ - public static String getErrorString(int errorCode) { + static String getErrorString(int errorCode) { return switch (errorCode) { case NO_ERROR -> "NO_ERROR"; case NOT_INITIALIZED -> "NOT_INITIALIZED"; @@ -913,13 +916,9 @@ public static String getErrorString(int errorCode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #terminate */ - public static boolean init() { - try { - return (int) glfwInit.invokeExact() != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwInit") + boolean init(); /** * Terminates the GLFW library. @@ -944,13 +943,8 @@ public static boolean init() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init */ - public static void terminate() { - try { - glfwTerminate.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwTerminate") + void terminate(); /** * Sets the specified init hint to the desired value. @@ -972,13 +966,8 @@ public static void terminate() { * @glfw.thread_safety This function must only be called from the main thread. * @see #init() init */ - public static void initHint(int hint, int value) { - try { - glfwInitHint.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwInitHint") + void initHint(int hint, int value); /** * Retrieves the version of the GLFW library. @@ -997,13 +986,8 @@ public static void initHint(int hint, int value) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersionString() getVersionString */ - public static void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev) { - try { - glfwGetVersion.invokeExact(major, minor, rev); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVersion") + void ngetVersion(MemorySegment major, MemorySegment minor, MemorySegment rev); /** * Retrieves the version of the GLFW library. @@ -1013,27 +997,8 @@ public static void ngetVersion(MemorySegment major, MemorySegment minor, MemoryS * @param rev Where to store the revision number, or {@code null}. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - public static void getVersion(int @Nullable [] major, int @Nullable [] minor, int @Nullable [] rev) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pMajor = major != null ? stack.callocInt() : MemorySegment.NULL; - var pMinor = minor != null ? stack.callocInt() : MemorySegment.NULL; - var pRev = rev != null ? stack.callocInt() : MemorySegment.NULL; - ngetVersion(pMajor, pMinor, pRev); - if (major != null && major.length > 0) { - major[0] = pMajor.get(JAVA_INT, 0); - } - if (minor != null && minor.length > 0) { - minor[0] = pMinor.get(JAVA_INT, 0); - } - if (rev != null && rev.length > 0) { - rev[0] = pRev.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetVersion") + void getVersion(@Ref int @Nullable [] major, @Ref int @Nullable [] minor, @Ref int @Nullable [] rev); /** * Retrieves the version of the GLFW library. @@ -1041,19 +1006,16 @@ public static void getVersion(int @Nullable [] major, int @Nullable [] minor, in * @return the major, minor and revision version number * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) ngetVersion */ - public static Triplet.OfInt getVersion() { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pMajor = stack.callocInt(); - var pMinor = stack.callocInt(); - var pRev = stack.callocInt(); + @Skip + default Triplet.OfInt getVersion() { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pMajor = stack.ints(0); + var pMinor = stack.ints(0); + var pRev = stack.ints(0); ngetVersion(pMajor, pMinor, pRev); return new Triplet.OfInt(pMajor.get(JAVA_INT, 0), pMinor.get(JAVA_INT, 0), pRev.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1076,13 +1038,8 @@ public static Triplet.OfInt getVersion() { * @glfw.thread_safety This function may be called from any thread. * @see #ngetVersion(MemorySegment, MemorySegment, MemorySegment) getVersion */ - public static MemorySegment ngetVersionString() { - try { - return (MemorySegment) glfwGetVersionString.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVersionString") + MemorySegment ngetVersionString(); /** * Returns a string describing the compile-time configuration. @@ -1090,9 +1047,10 @@ public static MemorySegment ngetVersionString() { * @return The ASCII encoded GLFW version string. * @see #ngetVersionString() ngetVersionString */ - public static String getVersionString() { - return ngetVersionString().getString(0); - } + @Entrypoint("glfwGetVersionString") + @SizedSeg(Unmarshal.STR_SIZE) + @StrCharset("US-ASCII") + String getVersionString(); /** * Returns and clears the last error for the calling thread. @@ -1113,13 +1071,8 @@ public static String getVersionString() { * @glfw.thread_safety This function may be called from any thread. * @see #nsetErrorCallback(MemorySegment) setErrorCallback */ - public static int ngetError(MemorySegment description) { - try { - return (int) glfwGetError.invokeExact(description); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetError") + int ngetError(MemorySegment description); /** * Returns and clears the last error for the calling thread. @@ -1128,20 +1081,8 @@ public static int ngetError(MemorySegment description) { * @return The last error code for the calling thread, or {@link #NO_ERROR} (zero). * @see #ngetError(MemorySegment) ngetError */ - public static int getError(String @Nullable [] description) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment seg = description != null ? stack.mallocPointer() : MemorySegment.NULL; - final int err = ngetError(seg); - if (description != null && description.length > 0) { - description[0] = RuntimeHelper.unboundPointerString(seg); - } - return err; - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetError") + int getError(@Ref String @Nullable [] description); /** * Returns and clears the last error for the calling thread. @@ -1149,15 +1090,12 @@ public static int getError(String @Nullable [] description) { * @return the error description pointer. and the last error code for the calling thread, or {@link #NO_ERROR} (zero) * @see #ngetError(MemorySegment) ngetError */ - public static Tuple2.OfObjInt getError() { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - final MemorySegment seg = stack.mallocPointer(); + @Skip + default Tuple2.OfObjInt getError() { + try (MemoryStack stack = MemoryStack.stackPush()) { + final MemorySegment seg = stack.allocate(ADDRESS); final int err = ngetError(seg); - return new Tuple2.OfObjInt<>(RuntimeHelper.unboundPointerString(seg), err); - } finally { - stack.setPointer(stackPointer); + return new Tuple2.OfObjInt<>(Unmarshal.unmarshalAsString(seg.get(Unmarshal.STR_LAYOUT, 0L)), err); } } @@ -1189,13 +1127,8 @@ public static Tuple2.OfObjInt getError() { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetError(MemorySegment) getError */ - public static MemorySegment nsetErrorCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetErrorCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetErrorCallback") + MemorySegment nsetErrorCallback(MemorySegment callback); /** * Sets the error callback. @@ -1204,8 +1137,9 @@ 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); + @Skip + default MemorySegment setErrorCallback(@Nullable GLFWErrorFun callback) { + return nsetErrorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** @@ -1226,13 +1160,8 @@ public static MemorySegment setErrorCallback(@Nullable IGLFWErrorFun callback) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getPrimaryMonitor() getPrimaryMonitor */ - public static MemorySegment ngetMonitors(MemorySegment count) { - try { - return (MemorySegment) glfwGetMonitors.invokeExact(count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitors") + MemorySegment ngetMonitors(MemorySegment count); /** * Returns the currently connected monitors. @@ -1241,17 +1170,12 @@ public static MemorySegment ngetMonitors(MemorySegment count) { * if an error occurred. * @see #ngetMonitors(MemorySegment) ngetMonitors */ - public static MemorySegment @Nullable [] getMonitors() { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default MemorySegment @Nullable [] getMonitors() { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pMonitors = ngetMonitors(pCount); - return RuntimeHelper.isNullptr(pMonitors) ? - null : - RuntimeHelper.toArray(pMonitors, new MemorySegment[pCount.get(JAVA_INT, 0)]); - } finally { - stack.setPointer(stackPointer); + return Unmarshal.unmarshalAsAddressArray(pMonitors.reinterpret(ADDRESS.scale(0L, pCount.get(JAVA_INT, 0L)))); } } @@ -1269,13 +1193,8 @@ public static MemorySegment ngetMonitors(MemorySegment count) { * {@link #ngetMonitors(MemorySegment) getMonitors}. * @see #ngetMonitors(MemorySegment) getMonitors */ - public static MemorySegment getPrimaryMonitor() { - try { - return (MemorySegment) glfwGetPrimaryMonitor.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetPrimaryMonitor") + MemorySegment getPrimaryMonitor(); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1293,13 +1212,8 @@ public static MemorySegment getPrimaryMonitor() { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetMonitorPos.invokeExact(monitor, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorPos") + void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1309,23 +1223,8 @@ public static void ngetMonitorPos(MemorySegment monitor, MemorySegment xpos, Mem * @param ypos Where to store the monitor y-coordinate, or {@code null}. * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - public static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorPos(monitor, px, py); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorPos") + void getMonitorPos(MemorySegment monitor, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos); /** * Returns the position of the monitor's viewport on the virtual screen. @@ -1334,16 +1233,13 @@ public static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, i * @return the monitor xy-coordinate * @see #ngetMonitorPos(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPos */ - public static Pair.OfInt getMonitorPos(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); + @Skip + default Pair.OfInt getMonitorPos(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); ngetMonitorPos(monitor, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1369,13 +1265,8 @@ public static Pair.OfInt getMonitorPos(MemorySegment monitor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height) { - try { - glfwGetMonitorWorkarea.invokeExact(monitor, xpos, ypos, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorWorkarea") + void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos, MemorySegment ypos, MemorySegment width, MemorySegment height); /** * Retrieves the work area of the monitor. @@ -1387,31 +1278,8 @@ public static void ngetMonitorWorkarea(MemorySegment monitor, MemorySegment xpos * @param height Where to store the monitor height, or {@code null}. * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - public static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xpos, int @Nullable [] ypos, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorWorkarea(monitor, px, py, pw, ph); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_INT, 0); - } - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorWorkarea") + void getMonitorWorkarea(MemorySegment monitor, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the work area of the monitor. @@ -1420,21 +1288,18 @@ public static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xp * @return the monitor xy-coordinate, the monitor width and the monitor height * @see #ngetMonitorWorkarea(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetMonitorWorkarea */ - public static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); + var pw = stack.ints(0); + var ph = stack.ints(0); ngetMonitorWorkarea(monitor, px, py, pw, ph); return new Quad.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0), pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1462,13 +1327,8 @@ public static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { * the current resolution and system DPI instead of querying the monitor EDID data. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM) { - try { - glfwGetMonitorPhysicalSize.invokeExact(monitor, widthMM, heightMM); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorPhysicalSize") + void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment widthMM, MemorySegment heightMM); /** * Returns the physical size of the monitor. @@ -1480,23 +1340,8 @@ public static void ngetMonitorPhysicalSize(MemorySegment monitor, MemorySegment * monitor's display area, or {@code null}. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - public static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [] widthMM, int @Nullable [] heightMM) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = widthMM != null ? stack.callocInt() : MemorySegment.NULL; - var ph = heightMM != null ? stack.callocInt() : MemorySegment.NULL; - ngetMonitorPhysicalSize(monitor, pw, ph); - if (widthMM != null && widthMM.length > 0) { - widthMM[0] = pw.get(JAVA_INT, 0); - } - if (heightMM != null && heightMM.length > 0) { - heightMM[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorPhysicalSize") + void getMonitorPhysicalSize(MemorySegment monitor, @Ref int @Nullable [] widthMM, @Ref int @Nullable [] heightMM); /** * Returns the physical size of the monitor. @@ -1505,16 +1350,13 @@ public static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [ * @return the width and height, in millimetres, of the monitor's display area. * @see #ngetMonitorPhysicalSize(MemorySegment, MemorySegment, MemorySegment) ngetMonitorPhysicalSize */ - public static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetMonitorPhysicalSize(monitor, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1541,13 +1383,8 @@ public static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) getWindowContentScale */ - public static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale) { - try { - glfwGetMonitorContentScale.invokeExact(monitor, xscale, yscale); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorContentScale") + void ngetMonitorContentScale(MemorySegment monitor, MemorySegment xscale, MemorySegment yscale); /** * Retrieves the content scale for the specified monitor. @@ -1557,23 +1394,8 @@ public static void ngetMonitorContentScale(MemorySegment monitor, MemorySegment * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - public static void getMonitorContentScale(MemorySegment monitor, float @Nullable [] xscale, float @Nullable [] yscale) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; - var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; - ngetMonitorContentScale(monitor, px, py); - if (xscale != null && xscale.length > 0) { - xscale[0] = px.get(JAVA_FLOAT, 0); - } - if (yscale != null && yscale.length > 0) { - yscale[0] = py.get(JAVA_FLOAT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetMonitorContentScale") + void getMonitorContentScale(MemorySegment monitor, @Ref float @Nullable [] xscale, @Ref float @Nullable [] yscale); /** * Retrieves the content scale for the specified monitor. @@ -1582,16 +1404,13 @@ public static void getMonitorContentScale(MemorySegment monitor, float @Nullable * @return the xy-axis content scale * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) ngetMonitorContentScale */ - public static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocFloat(); - var py = stack.callocFloat(); + @Skip + default Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.floats(0F); + var py = stack.floats(0F); ngetMonitorContentScale(monitor, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -1611,13 +1430,8 @@ public static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetMonitorName(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetMonitorName.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorName") + MemorySegment ngetMonitorName(MemorySegment monitor); /** * Returns the name of the specified monitor. @@ -1627,11 +1441,10 @@ public static MemorySegment ngetMonitorName(MemorySegment monitor) { * error occurred. * @see #ngetMonitorName(MemorySegment) ngetMonitorName */ + @Entrypoint("glfwGetMonitorName") @Nullable - public static String getMonitorName(MemorySegment monitor) { - var pName = ngetMonitorName(monitor); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + @SizedSeg(Unmarshal.STR_SIZE) + String getMonitorName(MemorySegment monitor); /** * Sets the user pointer of the specified monitor. @@ -1650,13 +1463,8 @@ public static String getMonitorName(MemorySegment monitor) { * synchronized. * @see #getMonitorUserPointer(MemorySegment) getMonitorUserPointer */ - public static void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer) { - try { - glfwSetMonitorUserPointer.invokeExact(monitor, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMonitorUserPointer") + void setMonitorUserPointer(MemorySegment monitor, MemorySegment pointer); /** * {@return the user pointer of the specified monitor} @@ -1673,13 +1481,8 @@ public static void setMonitorUserPointer(MemorySegment monitor, MemorySegment po * synchronized. * @see #setMonitorUserPointer(MemorySegment, MemorySegment) setMonitorUserPointer */ - public static MemorySegment getMonitorUserPointer(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetMonitorUserPointer.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMonitorUserPointer") + MemorySegment getMonitorUserPointer(MemorySegment monitor); /** * Sets the monitor configuration callback. @@ -1694,17 +1497,12 @@ 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. */ - public static MemorySegment nsetMonitorCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetMonitorCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMonitorCallback") + MemorySegment nsetMonitorCallback(MemorySegment callback); /** * Sets the monitor configuration callback. @@ -1715,8 +1513,9 @@ 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); + @Skip + default MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { + return nsetMonitorCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** @@ -1742,13 +1541,8 @@ public static MemorySegment setMonitorCallback(@Nullable IGLFWMonitorFun callbac * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoMode(MemorySegment) getVideoMode */ - public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count) { - try { - return (MemorySegment) glfwGetVideoModes.invokeExact(monitor, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVideoModes") + MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment count); /** * Returns the available video modes for the specified monitor. @@ -1758,17 +1552,16 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment * error occurred. * @see #ngetVideoModes(MemorySegment, MemorySegment) ngetVideoModes */ - public static @Nullable GLFWVidMode.Buffer getVideoModes(MemorySegment monitor) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default @Nullable GLFWVidMode getVideoModes(MemorySegment monitor) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pModes = ngetVideoModes(monitor, pCount); - return RuntimeHelper.isNullptr(pModes) ? - null : - new GLFWVidMode.Buffer(pModes, pCount.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); + if (Unmarshal.isNullPointer(pModes)) { + return null; + } + final int count = pCount.get(JAVA_INT, 0); + return new GLFWVidMode(pModes.reinterpret(GLFWVidMode.LAYOUT.scale(0L, count)), count); } } @@ -1790,13 +1583,8 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetVideoModes(MemorySegment, MemorySegment) getVideoModes */ - public static MemorySegment ngetVideoMode(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetVideoMode.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetVideoMode") + MemorySegment ngetVideoMode(MemorySegment monitor); /** * Returns the current mode of the specified monitor. @@ -1807,10 +1595,11 @@ public static MemorySegment ngetVideoMode(MemorySegment monitor) { * @see #ngetVideoMode(MemorySegment) ngetVideoMode */ @Nullable - public static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { + @Skip + default GLFWVidMode.Value getVideoMode(MemorySegment monitor) { var pMode = ngetVideoMode(monitor); - if (RuntimeHelper.isNullptr(pMode)) return null; - return new GLFWVidMode(pMode).value(); + if (Unmarshal.isNullPointer(pMode)) return null; + return new GLFWVidMode(pMode.reinterpret(GLFWVidMode.LAYOUT.byteSize())).value(); } /** @@ -1836,13 +1625,8 @@ public static GLFWVidMode.Value getVideoMode(MemorySegment monitor) { * will thus never be implemented and emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void setGamma(MemorySegment monitor, float gamma) { - try { - glfwSetGamma.invokeExact(monitor, gamma); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetGamma") + void setGamma(MemorySegment monitor, float gamma); /** * Returns the current gamma ramp for the specified monitor. @@ -1863,13 +1647,8 @@ public static void setGamma(MemorySegment monitor, float gamma) { * monitor or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetGammaRamp(MemorySegment monitor) { - try { - return (MemorySegment) glfwGetGammaRamp.invokeExact(monitor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetGammaRamp") + MemorySegment ngetGammaRamp(MemorySegment monitor); /** * Returns the current gamma ramp for the specified monitor. @@ -1879,12 +1658,9 @@ public static MemorySegment ngetGammaRamp(MemorySegment monitor) { * error occurred. * @see #ngetGammaRamp(MemorySegment) ngetGammaRamp */ + @Entrypoint("glfwGetGammaRamp") @Nullable - public static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { - var pRamp = ngetGammaRamp(monitor); - if (RuntimeHelper.isNullptr(pRamp)) return null; - return new GLFWGammaRamp(pRamp); - } + GLFWGammaRamp getGammaRamp(MemorySegment monitor); /** * Sets the current gamma ramp for the specified monitor. @@ -1916,13 +1692,8 @@ public static GLFWGammaRamp getGammaRamp(MemorySegment monitor) { * returns. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { - try { - glfwSetGammaRamp.invokeExact(monitor, ramp); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetGammaRamp") + void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp); /** * Sets the current gamma ramp for the specified monitor. @@ -1931,9 +1702,8 @@ public static void nsetGammaRamp(MemorySegment monitor, MemorySegment ramp) { * @param ramp The gamma ramp to use. * @see #nsetGammaRamp(MemorySegment, MemorySegment) nsetGammaRamp */ - public static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { - nsetGammaRamp(monitor, ramp.address()); - } + @Entrypoint("glfwSetGammaRamp") + void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp); /** * Resets all window hints to their default values. @@ -1946,13 +1716,8 @@ public static void setGammaRamp(MemorySegment monitor, GLFWGammaRamp ramp) { * @see #windowHint(int, int) windowHint * @see #nwindowHintString(int, MemorySegment) windowHintString */ - public static void defaultWindowHints() { - try { - glfwDefaultWindowHints.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDefaultWindowHints") + void defaultWindowHints(); /** * Sets the specified window hint to the desired value. @@ -1980,13 +1745,8 @@ public static void defaultWindowHints() { * @see #nwindowHintString(int, MemorySegment) windowHintString * @see #defaultWindowHints */ - public static void windowHint(int hint, int value) { - try { - glfwWindowHint.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWindowHint") + void windowHint(int hint, int value); /** * Sets the specified window hint to the desired value. @@ -1995,9 +1755,8 @@ public static void windowHint(int hint, int value) { * @param value The new value of the window hint. * @see #windowHint(int, int) */ - public static void windowHint(int hint, boolean value) { - windowHint(hint, value ? TRUE : FALSE); - } + @Entrypoint("glfwWindowHint") + void windowHint(int hint, @Convert(Type.INT) boolean value); /** * Sets the specified window hint to the desired value. @@ -2027,13 +1786,8 @@ public static void windowHint(int hint, boolean value) { * @see #windowHint(int, int) windowHint * @see #defaultWindowHints */ - public static void nwindowHintString(int hint, MemorySegment value) { - try { - glfwWindowHintString.invokeExact(hint, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWindowHintString") + void nwindowHintString(int hint, MemorySegment value); /** * Sets the specified window hint to the desired value. @@ -2042,15 +1796,8 @@ public static void nwindowHintString(int hint, MemorySegment value) { * @param value The new value of the window hint. * @see #nwindowHintString(int, MemorySegment) nwindowHintString */ - public static void windowHintString(int hint, String value) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - nwindowHintString(hint, stack.allocateFrom(value)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwWindowHintString") + void windowHintString(int hint, String value); /** * Creates a window and its associated context. @@ -2203,13 +1950,8 @@ public static void windowHintString(int hint, String value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #destroyWindow */ - public static MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share) { - try { - return (MemorySegment) glfwCreateWindow.invokeExact(width, height, title, monitor, share); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateWindow") + MemorySegment ncreateWindow(int width, int height, MemorySegment title, MemorySegment monitor, MemorySegment share); /** * Creates a window and its associated context. @@ -2227,15 +1969,8 @@ public static MemorySegment ncreateWindow(int width, int height, MemorySegment t * error occurred. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) ncreateWindow */ - public static MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return ncreateWindow(width, height, stack.allocateFrom(title), monitor, share); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwCreateWindow") + MemorySegment createWindow(int width, int height, String title, MemorySegment monitor, MemorySegment share); /** * Destroys the specified window and its context. @@ -2255,13 +1990,8 @@ public static MemorySegment createWindow(int width, int height, String title, Me * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateWindow(int, int, MemorySegment, MemorySegment, MemorySegment) createWindow */ - public static void destroyWindow(MemorySegment window) { - try { - glfwDestroyWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDestroyWindow") + void destroyWindow(MemorySegment window); /** * Checks the close flag of the specified window. @@ -2274,13 +2004,9 @@ public static void destroyWindow(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static boolean windowShouldClose(MemorySegment window) { - try { - return (int) glfwWindowShouldClose.invokeExact(window) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwWindowShouldClose") + boolean windowShouldClose(MemorySegment window); /** * Sets the close flag of the specified window. @@ -2295,13 +2021,8 @@ public static boolean windowShouldClose(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. Access is not * synchronized. */ - public static void setWindowShouldClose(MemorySegment window, boolean value) { - try { - glfwSetWindowShouldClose.invokeExact(window, value ? TRUE : FALSE); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowShouldClose") + void setWindowShouldClose(MemorySegment window, @Convert(Type.INT) boolean value); /** * Sets the title of the specified window. @@ -2317,13 +2038,8 @@ public static void setWindowShouldClose(MemorySegment window, boolean value) { * process events. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetWindowTitle(MemorySegment window, MemorySegment title) { - try { - glfwSetWindowTitle.invokeExact(window, title); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowTitle") + void nsetWindowTitle(MemorySegment window, MemorySegment title); /** * Sets the title of the specified window. @@ -2332,15 +2048,8 @@ public static void nsetWindowTitle(MemorySegment window, MemorySegment title) { * @param title The UTF-8 encoded window title. * @see #nsetWindowTitle(MemorySegment, MemorySegment) nsetWindowTitle */ - public static void setWindowTitle(MemorySegment window, String title) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - nsetWindowTitle(window, stack.allocateFrom(title)); - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwSetWindowTitle") + void setWindowTitle(MemorySegment window, String title); /** * Sets the icon for the specified window. @@ -2378,13 +2087,8 @@ public static void setWindowTitle(MemorySegment window, String title) { * This function always emits {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void nsetWindowIcon(MemorySegment window, int count, MemorySegment images) { - try { - glfwSetWindowIcon.invokeExact(window, count, images); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowIcon") + void nsetWindowIcon(MemorySegment window, int count, MemorySegment images); /** * Sets the icon for the specified window. @@ -2396,11 +2100,12 @@ public static void nsetWindowIcon(MemorySegment window, int count, MemorySegment * count is zero. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, int count, GLFWImage.Buffer images) { + @Skip + default void setWindowIcon(MemorySegment window, int count, GLFWImage images) { if (images == null || count == 0) { nsetWindowIcon(window, 0, MemorySegment.NULL); } else { - nsetWindowIcon(window, count, images.address()); + nsetWindowIcon(window, count, images.segment()); } } @@ -2412,12 +2117,9 @@ public static void setWindowIcon(MemorySegment window, int count, GLFWImage.Buff * revert to the default window icon. * @see #nsetWindowIcon(MemorySegment, int, MemorySegment) nsetWindowIcon */ - public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage.Buffer images) { - if (images == null) { - nsetWindowIcon(window, 0, MemorySegment.NULL); - } else { - setWindowIcon(window, (int) Math.min(images.elementCount(), Integer.MAX_VALUE), images); - } + @Skip + default void setWindowIcon(MemorySegment window, @Nullable GLFWImage images) { + setWindowIcon(window, images == null ? 0 : Math.toIntExact(images.elementCount()), images); } /** @@ -2442,13 +2144,8 @@ public static void setWindowIcon(MemorySegment window, @Nullable GLFWImage.Buffe * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowPos(MemorySegment, int, int) setWindowPos */ - public static void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetWindowPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowPos") + void ngetWindowPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos); /** * Retrieves the position of the content area of the specified window. @@ -2459,23 +2156,8 @@ public static void ngetWindowPos(MemorySegment window, MemorySegment xpos, Memor * @param ypos Where to store the y-coordinate of the upper-left corner of * the content area, or {@code null}. */ - public static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; - var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowPos(window, px, py); - if (xpos != null && xpos.length > 1) { - xpos[0] = px.get(JAVA_INT, 0); - } - if (ypos != null && ypos.length > 1) { - ypos[0] = py.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowPos") + void getWindowPos(MemorySegment window, @Ref int @Nullable [] xpos, @Ref int @Nullable [] ypos); /** * Retrieves the position of the content area of the specified window. @@ -2483,16 +2165,13 @@ public static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int * @param window The window to query. * @return the xy-coordinate of the upper-left corner of the content area. */ - public static Pair.OfInt getWindowPos(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocInt(); - var py = stack.callocInt(); + @Skip + default Pair.OfInt getWindowPos(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.ints(0); + var py = stack.ints(0); ngetWindowPos(window, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2520,13 +2199,8 @@ public static Pair.OfInt getWindowPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetWindowPos(MemorySegment, MemorySegment, MemorySegment) getWindowPos */ - public static void setWindowPos(MemorySegment window, int xpos, int ypos) { - try { - glfwSetWindowPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowPos") + void setWindowPos(MemorySegment window, int xpos, int ypos); /** * Retrieves the size of the content area of the specified window. @@ -2549,13 +2223,8 @@ public static void setWindowPos(MemorySegment window, int xpos, int ypos) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - public static void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height) { - try { - glfwGetWindowSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowSize") + void ngetWindowSize(MemorySegment window, MemorySegment width, MemorySegment height); /** * Retrieves the size of the content area of the specified window. @@ -2567,23 +2236,8 @@ public static void ngetWindowSize(MemorySegment window, MemorySegment width, Mem * content area, or {@code null}. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - public static void getWindowSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowSize(window, pw, ph); - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowSize") + void getWindowSize(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the size of the content area of the specified window. @@ -2592,16 +2246,13 @@ public static void getWindowSize(MemorySegment window, int @Nullable [] width, i * @return the width and height, in screen coordinates, of the content area. * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) ngetWindowSize */ - public static Pair.OfInt getWindowSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getWindowSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetWindowSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2638,13 +2289,8 @@ public static Pair.OfInt getWindowSize(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAspectRatio(MemorySegment, int, int) setWindowAspectRatio */ - public static void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight) { - try { - glfwSetWindowSizeLimits.invokeExact(window, minWidth, minHeight, maxWidth, maxHeight); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSizeLimits") + void setWindowSizeLimits(MemorySegment window, int minWidth, int minHeight, int maxWidth, int maxHeight); /** * Sets the aspect ratio of the specified window. @@ -2679,13 +2325,8 @@ public static void setWindowSizeLimits(MemorySegment window, int minWidth, int m * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowSizeLimits(MemorySegment, int, int, int, int) setWindowSizeLimits */ - public static void setWindowAspectRatio(MemorySegment window, int numer, int denom) { - try { - glfwSetWindowAspectRatio.invokeExact(window, numer, denom); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowAspectRatio") + void setWindowAspectRatio(MemorySegment window, int numer, int denom); /** * Sets the size of the content area of the specified window. @@ -2718,13 +2359,8 @@ public static void setWindowAspectRatio(MemorySegment window, int numer, int den * @see #ngetWindowSize(MemorySegment, MemorySegment, MemorySegment) getWindowSize * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - public static void setWindowSize(MemorySegment window, int width, int height) { - try { - glfwSetWindowSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSize") + void setWindowSize(MemorySegment window, int width, int height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2746,13 +2382,8 @@ public static void setWindowSize(MemorySegment window, int width, int height) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetFramebufferSizeCallback(MemorySegment, MemorySegment) setFramebufferSizeCallback */ - public static void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height) { - try { - glfwGetFramebufferSize.invokeExact(window, width, height); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetFramebufferSize") + void ngetFramebufferSize(MemorySegment window, MemorySegment width, MemorySegment height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2764,23 +2395,8 @@ public static void ngetFramebufferSize(MemorySegment window, MemorySegment width * or {@code null}. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - public static void getFramebufferSize(MemorySegment window, int @Nullable [] width, int @Nullable [] height) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = width != null ? stack.callocInt() : MemorySegment.NULL; - var ph = height != null ? stack.callocInt() : MemorySegment.NULL; - ngetFramebufferSize(window, pw, ph); - if (width != null && width.length > 0) { - width[0] = pw.get(JAVA_INT, 0); - } - if (height != null && height.length > 0) { - height[0] = ph.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetFramebufferSize") + void getFramebufferSize(MemorySegment window, @Ref int @Nullable [] width, @Ref int @Nullable [] height); /** * Retrieves the size of the framebuffer of the specified window. @@ -2789,16 +2405,13 @@ public static void getFramebufferSize(MemorySegment window, int @Nullable [] wid * @return the width and height, in pixels, of the framebuffer. * @see #ngetFramebufferSize(MemorySegment, MemorySegment, MemorySegment) ngetFramebufferSize */ - public static Pair.OfInt getFramebufferSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pw = stack.callocInt(); - var ph = stack.callocInt(); + @Skip + default Pair.OfInt getFramebufferSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pw = stack.ints(0); + var ph = stack.ints(0); ngetFramebufferSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2831,13 +2444,8 @@ public static Pair.OfInt getFramebufferSize(MemorySegment window) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom) { - try { - glfwGetWindowFrameSize.invokeExact(window, left, top, right, bottom); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowFrameSize") + void ngetWindowFrameSize(MemorySegment window, MemorySegment left, MemorySegment top, MemorySegment right, MemorySegment bottom); /** * Retrieves the size of the frame of the window. @@ -2853,31 +2461,8 @@ public static void ngetWindowFrameSize(MemorySegment window, MemorySegment left, * bottom edge of the window frame, or {@code null}. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - public static void getWindowFrameSize(MemorySegment window, int @Nullable [] left, int @Nullable [] top, int @Nullable [] right, int @Nullable [] bottom) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pl = left != null ? stack.callocInt() : MemorySegment.NULL; - var pt = top != null ? stack.callocInt() : MemorySegment.NULL; - var pr = right != null ? stack.callocInt() : MemorySegment.NULL; - var pb = bottom != null ? stack.callocInt() : MemorySegment.NULL; - ngetWindowFrameSize(window, pl, pt, pr, pb); - if (left != null && left.length > 0) { - left[0] = pl.get(JAVA_INT, 0); - } - if (top != null && top.length > 0) { - top[0] = pt.get(JAVA_INT, 0); - } - if (right != null && right.length > 0) { - right[0] = pr.get(JAVA_INT, 0); - } - if (bottom != null && bottom.length > 0) { - bottom[0] = pb.get(JAVA_INT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowFrameSize") + void getWindowFrameSize(MemorySegment window, @Ref int @Nullable [] left, @Ref int @Nullable [] top, @Ref int @Nullable [] right, @Ref int @Nullable [] bottom); /** * Retrieves the size of the frame of the window. @@ -2887,21 +2472,18 @@ public static void getWindowFrameSize(MemorySegment window, int @Nullable [] lef * edge of the window frame. * @see #ngetWindowFrameSize(MemorySegment, MemorySegment, MemorySegment, MemorySegment, MemorySegment) ngetWindowFrameSize */ - public static Quad.OfInt getWindowFrameSize(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pl = stack.callocInt(); - var pt = stack.callocInt(); - var pr = stack.callocInt(); - var pb = stack.callocInt(); + @Skip + default Quad.OfInt getWindowFrameSize(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pl = stack.ints(0); + var pt = stack.ints(0); + var pr = stack.ints(0); + var pb = stack.ints(0); ngetWindowFrameSize(window, pl, pt, pr, pb); return new Quad.OfInt(pl.get(JAVA_INT, 0), pt.get(JAVA_INT, 0), pr.get(JAVA_INT, 0), pb.get(JAVA_INT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -2929,13 +2511,8 @@ public static Quad.OfInt getWindowFrameSize(MemorySegment window) { * @see #nsetWindowContentScaleCallback(MemorySegment, MemorySegment) setWindowContentScaleCallback * @see #ngetMonitorContentScale(MemorySegment, MemorySegment, MemorySegment) getMonitorContentScale */ - public static void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale) { - try { - glfwGetWindowContentScale.invokeExact(window, xscale, yscale); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowContentScale") + void ngetWindowContentScale(MemorySegment window, MemorySegment xscale, MemorySegment yscale); /** * Retrieves the content scale for the specified window. @@ -2945,23 +2522,8 @@ public static void ngetWindowContentScale(MemorySegment window, MemorySegment xs * @param yscale Where to store the y-axis content scale, or {@code null}. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - public static void getWindowContentScale(MemorySegment window, float @Nullable [] xscale, float @Nullable [] yscale) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; - var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; - ngetWindowContentScale(window, px, py); - if (xscale != null && xscale.length > 0) { - xscale[0] = px.get(JAVA_FLOAT, 0); - } - if (yscale != null && yscale.length > 0) { - yscale[0] = py.get(JAVA_FLOAT, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetWindowContentScale") + void getWindowContentScale(MemorySegment window, @Ref float @Nullable [] xscale, @Ref float @Nullable [] yscale); /** * Retrieves the content scale for the specified window. @@ -2970,16 +2532,13 @@ public static void getWindowContentScale(MemorySegment window, float @Nullable [ * @return the xy-axis content scale. * @see #ngetWindowContentScale(MemorySegment, MemorySegment, MemorySegment) ngetWindowContentScale */ - public static Pair.OfFloat getWindowContentScale(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocFloat(); - var py = stack.callocFloat(); + @Skip + default Pair.OfFloat getWindowContentScale(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.floats(0F); + var py = stack.floats(0F); ngetWindowContentScale(window, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -3001,13 +2560,8 @@ public static Pair.OfFloat getWindowContentScale(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowOpacity(MemorySegment, float) setWindowOpacity */ - public static float getWindowOpacity(MemorySegment window) { - try { - return (float) glfwGetWindowOpacity.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowOpacity") + float getWindowOpacity(MemorySegment window); /** * Sets the opacity of the whole window. @@ -3029,13 +2583,8 @@ public static float getWindowOpacity(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowOpacity(MemorySegment) getWindowOpacity */ - public static void setWindowOpacity(MemorySegment window, float opacity) { - try { - glfwSetWindowOpacity.invokeExact(window, opacity); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowOpacity") + void setWindowOpacity(MemorySegment window, float opacity); /** * Iconifies the specified window. @@ -3055,13 +2604,8 @@ public static void setWindowOpacity(MemorySegment window, float opacity) { * @see #restoreWindow(MemorySegment) restoreWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - public static void iconifyWindow(MemorySegment window) { - try { - glfwIconifyWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwIconifyWindow") + void iconifyWindow(MemorySegment window); /** * Restores the specified window. @@ -3080,13 +2624,8 @@ public static void iconifyWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #maximizeWindow(MemorySegment) maximizeWindow */ - public static void restoreWindow(MemorySegment window) { - try { - glfwRestoreWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwRestoreWindow") + void restoreWindow(MemorySegment window); /** * Maximizes the specified window. @@ -3103,13 +2642,8 @@ public static void restoreWindow(MemorySegment window) { * @see #iconifyWindow(MemorySegment) iconifyWindow * @see #restoreWindow(MemorySegment) restoreWindow */ - public static void maximizeWindow(MemorySegment window) { - try { - glfwMaximizeWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwMaximizeWindow") + void maximizeWindow(MemorySegment window); /** * Makes the specified window visible. @@ -3133,13 +2667,8 @@ public static void maximizeWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #hideWindow(MemorySegment) hideWindow */ - public static void showWindow(MemorySegment window) { - try { - glfwShowWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwShowWindow") + void showWindow(MemorySegment window); /** * Hides the specified window. @@ -3154,13 +2683,8 @@ public static void showWindow(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #showWindow(MemorySegment) showWindow */ - public static void hideWindow(MemorySegment window) { - try { - glfwHideWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwHideWindow") + void hideWindow(MemorySegment window); /** * Brings the specified window to front and sets input focus. @@ -3190,13 +2714,8 @@ public static void hideWindow(MemorySegment window) { * to front, this function will always emit {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void focusWindow(MemorySegment window) { - try { - glfwFocusWindow.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwFocusWindow") + void focusWindow(MemorySegment window); /** * Requests user attention to the specified window. @@ -3215,13 +2734,8 @@ public static void focusWindow(MemorySegment window) { * specific window. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void requestWindowAttention(MemorySegment window) { - try { - glfwRequestWindowAttention.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwRequestWindowAttention") + void requestWindowAttention(MemorySegment window); /** * Returns the monitor that the window uses for full screen mode. @@ -3236,13 +2750,8 @@ public static void requestWindowAttention(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowMonitor(MemorySegment, MemorySegment, int, int, int, int, int) setWindowMonitor */ - public static MemorySegment getWindowMonitor(MemorySegment window) { - try { - return (MemorySegment) glfwGetWindowMonitor.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowMonitor") + MemorySegment getWindowMonitor(MemorySegment window); /** * Sets the mode, monitor, video mode and placement of a window. @@ -3292,13 +2801,8 @@ public static MemorySegment getWindowMonitor(MemorySegment window) { * @see #getWindowMonitor(MemorySegment) getWindowMonitor * @see #setWindowSize(MemorySegment, int, int) setWindowSize */ - public static void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate) { - try { - glfwSetWindowMonitor.invokeExact(window, monitor, xpos, ypos, width, height, refreshRate); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowMonitor") + void setWindowMonitor(MemorySegment window, MemorySegment monitor, int xpos, int ypos, int width, int height, int refreshRate); /** * Returns an attribute of the specified window. @@ -3327,13 +2831,8 @@ public static void setWindowMonitor(MemorySegment window, MemorySegment monitor, * @glfw.thread_safety This function must only be called from the main thread. * @see #setWindowAttrib(MemorySegment, int, boolean) setWindowAttrib */ - public static int getWindowAttrib(MemorySegment window, int attrib) { - try { - return (int) glfwGetWindowAttrib.invokeExact(window, attrib); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowAttrib") + int getWindowAttrib(MemorySegment window, int attrib); /** * Sets an attribute of the specified window. @@ -3362,13 +2861,8 @@ public static int getWindowAttrib(MemorySegment window, int attrib) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getWindowAttrib(MemorySegment, int) getWindowAttrib */ - public static void setWindowAttrib(MemorySegment window, int attrib, boolean value) { - try { - glfwSetWindowAttrib.invokeExact(window, attrib, value ? TRUE : FALSE); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowAttrib") + void setWindowAttrib(MemorySegment window, int attrib, @Convert(Type.INT) boolean value); /** * Sets the user pointer of the specified window. @@ -3384,13 +2878,8 @@ public static void setWindowAttrib(MemorySegment window, int attrib, boolean val * synchronized. * @see #getWindowUserPointer(MemorySegment) getWindowUserPointer */ - public static void setWindowUserPointer(MemorySegment window, MemorySegment pointer) { - try { - glfwSetWindowUserPointer.invokeExact(window, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowUserPointer") + void setWindowUserPointer(MemorySegment window, MemorySegment pointer); /** * {@return the user pointer of the specified window} @@ -3404,13 +2893,8 @@ public static void setWindowUserPointer(MemorySegment window, MemorySegment poin * synchronized. * @see #setWindowUserPointer(MemorySegment, MemorySegment) setWindowUserPointer */ - public static MemorySegment getWindowUserPointer(MemorySegment window) { - try { - return (MemorySegment) glfwGetWindowUserPointer.invokeExact(window); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetWindowUserPointer") + MemorySegment getWindowUserPointer(MemorySegment window); /** * Sets the position callback for the specified window. @@ -3427,19 +2911,14 @@ 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. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowPosCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowPosCallback") + MemorySegment nsetWindowPosCallback(MemorySegment window, MemorySegment callback); /** * Sets the position callback for the specified window. @@ -3451,8 +2930,9 @@ 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); + @Skip + default MemorySegment setWindowPosCallback(MemorySegment window, @Nullable GLFWWindowPosFun callback) { + return nsetWindowPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3469,17 +2949,12 @@ 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. */ - public static MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowSizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowSizeCallback") + MemorySegment nsetWindowSizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the size callback for the specified window. @@ -3491,8 +2966,9 @@ 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); + @Skip + default MemorySegment setWindowSizeCallback(MemorySegment window, @Nullable GLFWWindowSizeFun callback) { + return nsetWindowSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3514,19 +2990,14 @@ 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. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowCloseCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowCloseCallback") + MemorySegment nsetWindowCloseCallback(MemorySegment window, MemorySegment callback); /** * Sets the close callback for the specified window. @@ -3538,8 +3009,9 @@ 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); + @Skip + default MemorySegment setWindowCloseCallback(MemorySegment window, @Nullable GLFWWindowCloseFun callback) { + return nsetWindowCloseCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3560,17 +3032,12 @@ 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. */ - public static MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowRefreshCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowRefreshCallback") + MemorySegment nsetWindowRefreshCallback(MemorySegment window, MemorySegment callback); /** * Sets the refresh callback for the specified window. @@ -3582,8 +3049,9 @@ 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); + @Skip + default MemorySegment setWindowRefreshCallback(MemorySegment window, @Nullable GLFWWindowRefreshFun callback) { + return nsetWindowRefreshCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3605,17 +3073,12 @@ 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. */ - public static MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowFocusCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowFocusCallback") + MemorySegment nsetWindowFocusCallback(MemorySegment window, MemorySegment callback); /** * Sets the focus callback for the specified window. @@ -3627,8 +3090,9 @@ 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); + @Skip + default MemorySegment setWindowFocusCallback(MemorySegment window, @Nullable GLFWWindowFocusFun callback) { + return nsetWindowFocusCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3644,19 +3108,14 @@ 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. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowIconifyCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowIconifyCallback") + MemorySegment nsetWindowIconifyCallback(MemorySegment window, MemorySegment callback); /** * Sets the iconify callback for the specified window. @@ -3668,8 +3127,9 @@ 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); + @Skip + default MemorySegment setWindowIconifyCallback(MemorySegment window, @Nullable GLFWWindowIconifyFun callback) { + return nsetWindowIconifyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3685,17 +3145,12 @@ 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. */ - public static MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowMaximizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowMaximizeCallback") + MemorySegment nsetWindowMaximizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the maximize callback for the specified window. @@ -3707,8 +3162,9 @@ 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); + @Skip + default MemorySegment setWindowMaximizeCallback(MemorySegment window, @Nullable GLFWWindowMaximizeFun callback) { + return nsetWindowMaximizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3724,17 +3180,12 @@ 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. */ - public static MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetFramebufferSizeCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetFramebufferSizeCallback") + MemorySegment nsetFramebufferSizeCallback(MemorySegment window, MemorySegment callback); /** * Sets the framebuffer resize callback for the specified window. @@ -3746,8 +3197,9 @@ 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); + @Skip + default MemorySegment setFramebufferSizeCallback(MemorySegment window, @Nullable GLFWFramebufferSizeFun callback) { + return nsetFramebufferSizeCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3763,18 +3215,13 @@ 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 */ - public static MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetWindowContentScaleCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetWindowContentScaleCallback") + MemorySegment nsetWindowContentScaleCallback(MemorySegment window, MemorySegment callback); /** * Sets the window content scale callback for the specified window. @@ -3786,8 +3233,9 @@ 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); + @Skip + default MemorySegment setWindowContentScaleCallback(MemorySegment window, @Nullable GLFWWindowContentScaleFun callback) { + return nsetWindowContentScaleCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -3820,13 +3268,8 @@ public static MemorySegment setWindowContentScaleCallback(MemorySegment window, * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void pollEvents() { - try { - glfwPollEvents.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwPollEvents") + void pollEvents(); /** * Waits until events are queued and processes them. @@ -3864,13 +3307,8 @@ public static void pollEvents() { * @see #pollEvents() pollEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void waitEvents() { - try { - glfwWaitEvents.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWaitEvents") + void waitEvents(); /** * Waits with timeout until events are queued and processes them. @@ -3911,13 +3349,8 @@ public static void waitEvents() { * @see #pollEvents() pollEvents * @see #waitEvents() waitEvents */ - public static void waitEventsTimeout(double timeout) { - try { - glfwWaitEventsTimeout.invokeExact(timeout); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwWaitEventsTimeout") + void waitEventsTimeout(double timeout); /** * Posts an empty event to the event queue. @@ -3931,13 +3364,8 @@ public static void waitEventsTimeout(double timeout) { * @see #waitEvents() waitEvents * @see #waitEventsTimeout(double) waitEventsTimeout */ - public static void postEmptyEvents() { - try { - glfwPostEmptyEvent.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwPostEmptyEvent") + void postEmptyEvents(); /** * {@return the value of an input option for the specified window} @@ -3956,13 +3384,8 @@ public static void postEmptyEvents() { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - public static int getInputMode(MemorySegment window, int mode) { - try { - return (int) glfwGetInputMode.invokeExact(window, mode); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetInputMode") + int getInputMode(MemorySegment window, int mode); /** * Sets an input option for the specified window. @@ -4020,13 +3443,8 @@ public static int getInputMode(MemorySegment window, int mode) { * @glfw.thread_safety This function must only be called from the main thread. * @see #getInputMode(MemorySegment, int) getInputMode */ - public static void setInputMode(MemorySegment window, int mode, int value) { - try { - glfwSetInputMode.invokeExact(window, mode, value); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetInputMode") + void setInputMode(MemorySegment window, int mode, int value); /** * Returns whether raw mouse motion is supported. @@ -4048,13 +3466,9 @@ public static void setInputMode(MemorySegment window, int mode, int value) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setInputMode(MemorySegment, int, int) setInputMode */ - public static boolean rawMouseMotionSupported() { - try { - return (int) glfwRawMouseMotionSupported.invokeExact() != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwRawMouseMotionSupported") + boolean rawMouseMotionSupported(); /** * Returns the layout-specific name of the specified printable key. @@ -4117,13 +3531,8 @@ public static boolean rawMouseMotionSupported() { * should not free it yourself. It is valid until the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetKeyName(int key, int scancode) { - try { - return (MemorySegment) glfwGetKeyName.invokeExact(key, scancode); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKeyName") + MemorySegment ngetKeyName(int key, int scancode); /** * Returns the layout-specific name of the specified printable key. @@ -4133,11 +3542,9 @@ public static MemorySegment ngetKeyName(int key, int scancode) { * @return The UTF-8 encoded, layout-specific name of the key, or {@code null}. * @see #ngetKeyName(int, int) ngetKeyName */ + @Entrypoint("glfwGetKeyName") @Nullable - public static String getKeyName(int key, int scancode) { - var pName = ngetKeyName(key, scancode); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getKeyName(int key, int scancode); /** * Returns the platform-specific scancode of the specified key. @@ -4156,13 +3563,8 @@ public static String getKeyName(int key, int scancode) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and {@link #INVALID_ENUM}. * @glfw.thread_safety This function may be called from any thread. */ - public static int getKeyScancode(int key) { - try { - return (int) glfwGetKeyScancode.invokeExact(key); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKeyScancode") + int getKeyScancode(int key); /** * Returns the last reported state of a keyboard key for the specified @@ -4195,13 +3597,8 @@ public static int getKeyScancode(int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static int getKey(MemorySegment window, int key) { - try { - return (int) glfwGetKey.invokeExact(window, key); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetKey") + int getKey(MemorySegment window, int key); /** * Returns the last reported state of a mouse button for the specified @@ -4222,13 +3619,8 @@ public static int getKey(MemorySegment window, int key) { * {@link #INVALID_ENUM}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static int getMouseButton(MemorySegment window, int button) { - try { - return (int) glfwGetMouseButton.invokeExact(window, button); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetMouseButton") + int getMouseButton(MemorySegment window, int button); /** * Retrieves the position of the cursor relative to the content area of @@ -4259,13 +3651,8 @@ public static int getMouseButton(MemorySegment window, int button) { * @glfw.thread_safety This function must only be called from the main thread. * @see #setCursorPos(MemorySegment, double, double) setCursorPos */ - public static void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos) { - try { - glfwGetCursorPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetCursorPos") + void ngetCursorPos(MemorySegment window, MemorySegment xpos, MemorySegment ypos); /** * Retrieves the position of the cursor relative to the content area of @@ -4278,23 +3665,8 @@ public static void ngetCursorPos(MemorySegment window, MemorySegment xpos, Memor * top edge of the content area, or {@code null}. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - public static void getCursorPos(MemorySegment window, double @Nullable [] xpos, double @Nullable [] ypos) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = xpos != null ? stack.callocDouble() : MemorySegment.NULL; - var py = ypos != null ? stack.callocDouble() : MemorySegment.NULL; - ngetCursorPos(window, px, py); - if (xpos != null && xpos.length > 0) { - xpos[0] = px.get(JAVA_DOUBLE, 0); - } - if (ypos != null && ypos.length > 0) { - ypos[0] = py.get(JAVA_DOUBLE, 0); - } - } finally { - stack.setPointer(stackPointer); - } - } + @Entrypoint("glfwGetCursorPos") + void getCursorPos(MemorySegment window, @Ref double @Nullable [] xpos, @Ref double @Nullable [] ypos); /** * Retrieves the position of the cursor relative to the content area of @@ -4304,16 +3676,13 @@ public static void getCursorPos(MemorySegment window, double @Nullable [] xpos, * @return the cursor xy-coordinate, relative to the left and top edge of the content area. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) ngetCursorPos */ - public static Pair.OfDouble getCursorPos(MemorySegment window) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var px = stack.callocDouble(); - var py = stack.callocDouble(); + @Skip + default Pair.OfDouble getCursorPos(MemorySegment window) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var px = stack.doubles(0D); + var py = stack.doubles(0D); ngetCursorPos(window, px, py); return new Pair.OfDouble(px.get(JAVA_DOUBLE, 0), py.get(JAVA_DOUBLE, 0)); - } finally { - stack.setPointer(stackPointer); } } @@ -4347,13 +3716,8 @@ public static Pair.OfDouble getCursorPos(MemorySegment window) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetCursorPos(MemorySegment, MemorySegment, MemorySegment) getCursorPos */ - public static void setCursorPos(MemorySegment window, double xpos, double ypos) { - try { - glfwSetCursorPos.invokeExact(window, xpos, ypos); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorPos") + void setCursorPos(MemorySegment window, double xpos, double ypos); /** * Creates a custom cursor. @@ -4383,13 +3747,8 @@ public static void setCursorPos(MemorySegment window, double xpos, double ypos) * @see #destroyCursor(MemorySegment) destroyCursor * @see #createStandardCursor(int) createStandardCursor */ - public static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot) { - try { - return (MemorySegment) glfwCreateCursor.invokeExact(image, xhot, yhot); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateCursor") + MemorySegment ncreateCursor(MemorySegment image, int xhot, int yhot); /** * Creates a custom cursor. @@ -4401,9 +3760,8 @@ public static MemorySegment ncreateCursor(MemorySegment image, int xhot, int yho * error occurred. * @see #ncreateCursor(MemorySegment, int, int) ncreateCursor */ - public static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { - return ncreateCursor(image.address(), xhot, yhot); - } + @Entrypoint("glfwCreateCursor") + MemorySegment createCursor(GLFWImage image, int xhot, int yhot); /** * Creates a cursor with a standard shape. @@ -4420,13 +3778,8 @@ public static MemorySegment createCursor(GLFWImage image, int xhot, int yhot) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - public static MemorySegment createStandardCursor(int shape) { - try { - return (MemorySegment) glfwCreateStandardCursor.invokeExact(shape); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwCreateStandardCursor") + MemorySegment createStandardCursor(int shape); /** * Destroys a cursor. @@ -4445,13 +3798,8 @@ public static MemorySegment createStandardCursor(int shape) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ncreateCursor(MemorySegment, int, int) createCursor */ - public static void destroyCursor(MemorySegment cursor) { - try { - glfwDestroyCursor.invokeExact(cursor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwDestroyCursor") + void destroyCursor(MemorySegment cursor); /** * Sets the cursor for the window. @@ -4471,13 +3819,8 @@ public static void destroyCursor(MemorySegment cursor) { * {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static void setCursor(MemorySegment window, MemorySegment cursor) { - try { - glfwSetCursor.invokeExact(window, cursor); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursor") + void setCursor(MemorySegment window, MemorySegment cursor); /** * Sets the key callback. @@ -4512,17 +3855,12 @@ 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. */ - public static MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetKeyCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetKeyCallback") + MemorySegment nsetKeyCallback(MemorySegment window, MemorySegment callback); /** * Sets the key callback. @@ -4534,8 +3872,9 @@ 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); + @Skip + default MemorySegment setKeyCallback(MemorySegment window, @Nullable GLFWKeyFun callback) { + return nsetKeyCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4563,17 +3902,12 @@ 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. */ - public static MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCharCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCharCallback") + MemorySegment nsetCharCallback(MemorySegment window, MemorySegment callback); /** * Sets the Unicode character callback. @@ -4585,8 +3919,9 @@ 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); + @Skip + default MemorySegment setCharCallback(MemorySegment window, @Nullable GLFWCharFun callback) { + return nsetCharCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4608,17 +3943,12 @@ 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. */ - public static MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetMouseButtonCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetMouseButtonCallback") + MemorySegment nsetMouseButtonCallback(MemorySegment window, MemorySegment callback); /** * Sets the mouse button callback. @@ -4630,8 +3960,9 @@ 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); + @Skip + default MemorySegment setMouseButtonCallback(MemorySegment window, @Nullable GLFWMouseButtonFun callback) { + return nsetMouseButtonCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4649,17 +3980,12 @@ 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. */ - public static MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCursorPosCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorPosCallback") + MemorySegment nsetCursorPosCallback(MemorySegment window, MemorySegment callback); /** * Sets the cursor position callback. @@ -4671,8 +3997,9 @@ 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); + @Skip + default MemorySegment setCursorPosCallback(MemorySegment window, @Nullable GLFWCursorPosFun callback) { + return nsetCursorPosCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4689,17 +4016,12 @@ 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. */ - public static MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetCursorEnterCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetCursorEnterCallback") + MemorySegment nsetCursorEnterCallback(MemorySegment window, MemorySegment callback); /** * Sets the cursor enter/leave callback. @@ -4711,8 +4033,9 @@ 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); + @Skip + default MemorySegment setCursorEnterCallback(MemorySegment window, @Nullable GLFWCursorEnterFun callback) { + return nsetCursorEnterCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4732,17 +4055,12 @@ 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. */ - public static MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetScrollCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetScrollCallback") + MemorySegment nsetScrollCallback(MemorySegment window, MemorySegment callback); /** * Sets the scroll callback. @@ -4754,8 +4072,9 @@ 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); + @Skip + default MemorySegment setScrollCallback(MemorySegment window, @Nullable GLFWScrollFun callback) { + return nsetScrollCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4776,18 +4095,13 @@ 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. */ - public static MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback) { - try { - return (MemorySegment) glfwSetDropCallback.invokeExact(window, callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetDropCallback") + MemorySegment nsetDropCallback(MemorySegment window, MemorySegment callback); /** * Sets the path drop callback. @@ -4799,8 +4113,9 @@ 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); + @Skip + default MemorySegment setDropCallback(MemorySegment window, @Nullable GLFWDropFun callback) { + return nsetDropCallback(window, callback != null ? callback.stub(GLFWCallbacks.create(window)) : MemorySegment.NULL); } /** @@ -4818,13 +4133,9 @@ public static MemorySegment setDropCallback(MemorySegment window, @Nullable IGLF * {@link #INVALID_ENUM} and {@link #PLATFORM_ERROR}. * @glfw.thread_safety This function must only be called from the main thread. */ - public static boolean joystickPresent(int jid) { - try { - return (int) glfwJoystickPresent.invokeExact(jid) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwJoystickPresent") + boolean joystickPresent(int jid); /** * Returns the values of all axes of the specified joystick. @@ -4850,13 +4161,8 @@ public static boolean joystickPresent(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickAxes.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickAxes") + MemorySegment ngetJoystickAxes(int jid, MemorySegment count); /** * Returns the values of all axes of the specified joystick. @@ -4867,20 +4173,15 @@ public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * occurred. * @see #ngetJoystickAxes(int, MemorySegment) ngetJoystickAxes */ - public static float @Nullable [] getJoystickAxes(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - MemorySegment pAxes; - final int count; - try { - var pCount = stack.callocInt(); - pAxes = ngetJoystickAxes(jid, pCount); - count = pCount.get(JAVA_INT, 0); - } finally { - stack.setPointer(stackPointer); + @Skip + default float @Nullable [] getJoystickAxes(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); + MemorySegment pAxes = ngetJoystickAxes(jid, pCount); + final int count = pCount.get(JAVA_INT, 0); + if (count == 0) return null; + return Unmarshal.unmarshalAsFloatArray(pAxes.reinterpret(JAVA_FLOAT.scale(0L, count))); } - if (count == 0) return null; - return RuntimeHelper.toArray(pAxes, new float[count]); } /** @@ -4913,13 +4214,8 @@ public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickButtons.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickButtons") + MemorySegment ngetJoystickButtons(int jid, MemorySegment count); /** * Returns the state of all buttons of the specified joystick. @@ -4929,24 +4225,15 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickButtons(int, MemorySegment) ngetJoystickButtons */ - public static boolean @Nullable [] getJoystickButtons(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - MemorySegment pButtons; - final int count; - try { - var pCount = stack.callocInt(); - pButtons = ngetJoystickButtons(jid, pCount); - count = pCount.get(JAVA_INT, 0); - } finally { - stack.setPointer(stackPointer); - } - if (count == 0) return null; - boolean[] buttons = new boolean[count]; - for (int i = 0; i < count; i++) { - buttons[i] = pButtons.getAtIndex(JAVA_INT, i) == PRESS; + @Skip + default int @Nullable [] getJoystickButtons(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); + MemorySegment pButtons = ngetJoystickButtons(jid, pCount); + final int count = pCount.get(JAVA_INT, 0); + if (count == 0) return null; + return Unmarshal.unmarshalAsIntArray(pButtons.reinterpret(JAVA_INT.scale(0L, count))); } - return buttons; } /** @@ -4972,7 +4259,6 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * The diagonal directions are bitwise combinations of the primary (up, right, * down and left) directions, and you can test for these individually by ANDing * it with the corresponding direction. - * * {@snippet lang = java: * if (hats[2] & HAT_RIGHT) { * // State of hat 2 could be right-up, right or right-down @@ -4996,13 +4282,8 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { * is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { - try { - return (MemorySegment) glfwGetJoystickHats.invokeExact(jid, count); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickHats") + MemorySegment ngetJoystickHats(int jid, MemorySegment count); /** * Returns the state of all hats of the specified joystick. @@ -5012,15 +4293,12 @@ public static MemorySegment ngetJoystickHats(int jid, MemorySegment count) { * or an error occurred. * @see #ngetJoystickHats(int, MemorySegment) ngetJoystickHats */ - public static byte[] getJoystickHats(int jid) { - var stack = MemoryStack.stackGet(); - long stackPointer = stack.getPointer(); - try { - var pCount = stack.callocInt(); + @Skip + default byte[] getJoystickHats(int jid) { + try (MemoryStack stack = MemoryStack.stackPush()) { + var pCount = stack.ints(0); var pHats = ngetJoystickHats(jid, pCount); - return RuntimeHelper.toArray(pHats, new byte[pCount.get(JAVA_INT, 0)]); - } finally { - stack.setPointer(stackPointer); + return Unmarshal.unmarshalAsByteArray(pHats.reinterpret(JAVA_BYTE.scale(0L, pCount.get(JAVA_INT, 0)))); } } @@ -5045,13 +4323,8 @@ public static byte[] getJoystickHats(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickName(int jid) { - try { - return (MemorySegment) glfwGetJoystickName.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickName") + MemorySegment ngetJoystickName(int jid); /** * Returns the name of the specified joystick. @@ -5061,11 +4334,9 @@ public static MemorySegment ngetJoystickName(int jid) { * is not present or an error occurred. * @see #ngetJoystickName(int) ngetJoystickName */ + @Entrypoint("glfwGetJoystickName") @Nullable - public static String getJoystickName(int jid) { - var pName = ngetJoystickName(jid); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getJoystickName(int jid); /** * Returns the SDL compatible GUID of the specified joystick. @@ -5098,13 +4369,8 @@ public static String getJoystickName(int jid) { * disconnected or the library is terminated. * @glfw.thread_safety This function must only be called from the main thread. */ - public static MemorySegment ngetJoystickGUID(int jid) { - try { - return (MemorySegment) glfwGetJoystickGUID.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickGUID") + MemorySegment ngetJoystickGUID(int jid); /** * Returns the SDL compatible GUID of the specified joystick. @@ -5114,11 +4380,9 @@ public static MemorySegment ngetJoystickGUID(int jid) { * is not present or an error occurred. * @see #ngetJoystickGUID(int) ngetJoystickGUID */ + @Entrypoint("glfwGetJoystickGUID") @Nullable - public static String getJoystickGUID(int jid) { - var pGUID = ngetJoystickGUID(jid); - return RuntimeHelper.isNullptr(pGUID) ? null : pGUID.getString(0); - } + String getJoystickGUID(int jid); /** * Sets the user pointer of the specified joystick. @@ -5137,13 +4401,8 @@ public static String getJoystickGUID(int jid) { * synchronized. * @see #getJoystickUserPointer(int) getJoystickUserPointer */ - public static void setJoystickUserPointer(int jid, MemorySegment pointer) { - try { - glfwSetJoystickUserPointer.invokeExact(jid, pointer); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetJoystickUserPointer") + void setJoystickUserPointer(int jid, MemorySegment pointer); /** * {@return the user pointer of the specified joystick} @@ -5160,13 +4419,8 @@ public static void setJoystickUserPointer(int jid, MemorySegment pointer) { * synchronized. * @see #setJoystickUserPointer(int, MemorySegment) setJoystickUserPointer */ - public static MemorySegment getJoystickUserPointer(int jid) { - try { - return (MemorySegment) glfwGetJoystickUserPointer.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetJoystickUserPointer") + MemorySegment getJoystickUserPointer(int jid); /** * Returns whether the specified joystick has a gamepad mapping. @@ -5187,13 +4441,9 @@ public static MemorySegment getJoystickUserPointer(int jid) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetGamepadState(int, MemorySegment) getGamepadState */ - public static boolean joystickIsGamepad(int jid) { - try { - return (int) glfwJoystickIsGamepad.invokeExact(jid) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwJoystickIsGamepad") + boolean joystickIsGamepad(int jid); /** * Sets the joystick configuration callback. @@ -5215,17 +4465,12 @@ 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. */ - public static MemorySegment nsetJoystickCallback(MemorySegment callback) { - try { - return (MemorySegment) glfwSetJoystickCallback.invokeExact(callback); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwSetJoystickCallback") + MemorySegment nsetJoystickCallback(MemorySegment callback); /** * Sets the joystick configuration callback. @@ -5236,8 +4481,9 @@ 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); + @Skip + default MemorySegment setJoystickCallback(@Nullable GLFWJoystickFun callback) { + return nsetJoystickCallback(callback != null ? callback.stub(Arena.ofAuto()) : MemorySegment.NULL); } /** @@ -5266,13 +4512,9 @@ public static MemorySegment setJoystickCallback(@Nullable IGLFWJoystickFun callb * @see #joystickIsGamepad(int) joystickIsGamepad * @see #ngetGamepadName(int) getGamepadName */ - public static boolean nupdateGamepadMappings(MemorySegment string) { - try { - return (int) glfwUpdateGamepadMappings.invokeExact(string) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwUpdateGamepadMappings") + boolean nupdateGamepadMappings(MemorySegment string); /** * Adds the specified SDL_GameControllerDB gamepad mappings. @@ -5282,15 +4524,9 @@ public static boolean nupdateGamepadMappings(MemorySegment string) { * error occurred. * @see #nupdateGamepadMappings(MemorySegment) nupdateGamepadMappings */ - public static boolean updateGamepadMappings(String string) { - final MemoryStack stack = MemoryStack.stackGet(); - final long stackPointer = stack.getPointer(); - try { - return nupdateGamepadMappings(stack.allocateFrom(string)); - } finally { - stack.setPointer(stackPointer); - } - } + @Convert(Type.INT) + @Entrypoint("glfwUpdateGamepadMappings") + boolean updateGamepadMappings(String string); /** * Returns the human-readable gamepad name for the specified joystick. @@ -5314,13 +4550,8 @@ public static boolean updateGamepadMappings(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #joystickIsGamepad(int) joystickIsGamepad */ - public static MemorySegment ngetGamepadName(int jid) { - try { - return (MemorySegment) glfwGetGamepadName.invokeExact(jid); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetGamepadName") + MemorySegment ngetGamepadName(int jid); /** * Returns the human-readable gamepad name for the specified joystick. @@ -5331,11 +4562,9 @@ public static MemorySegment ngetGamepadName(int jid) { * error occurred. * @see #ngetGamepadName(int) ngetGamepadName */ + @Entrypoint("glfwGetGamepadName") @Nullable - public static String getGamepadName(int jid) { - var pName = ngetGamepadName(jid); - return RuntimeHelper.isNullptr(pName) ? null : pName.getString(0); - } + String getGamepadName(int jid); /** * Retrieves the state of the specified joystick remapped as a gamepad. @@ -5366,13 +4595,9 @@ public static String getGamepadName(int jid) { * @see #nupdateGamepadMappings(MemorySegment) updateGamepadMappings * @see #joystickIsGamepad(int) joystickIsGamepad */ - public static boolean ngetGamepadState(int jid, MemorySegment state) { - try { - return (int) glfwGetGamepadState.invokeExact(jid, state) != FALSE; - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Convert(Type.INT) + @Entrypoint("glfwGetGamepadState") + boolean ngetGamepadState(int jid, MemorySegment state); /** * Retrieves the state of the specified joystick remapped as a gamepad. @@ -5384,9 +4609,9 @@ public static boolean ngetGamepadState(int jid, MemorySegment state) { * occurred. * @see #ngetGamepadState(int, MemorySegment) ngetGamepadState */ - public static boolean getGamepadState(int jid, GLFWGamepadState state) { - return ngetGamepadState(jid, state.address()); - } + @Convert(Type.INT) + @Entrypoint("glfwGetGamepadState") + boolean getGamepadState(int jid, GLFWGamepadState state); /** * Sets the clipboard to the specified string. @@ -5394,6 +4619,7 @@ public static boolean getGamepadState(int jid, GLFWGamepadState state) { * This function sets the system clipboard to the specified, UTF-8 encoded * string. * + * @param window window Deprecated. Any valid window or {@code NULL}. * @param string A UTF-8 encoded string. * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and * {@link #PLATFORM_ERROR}. @@ -5402,12 +4628,26 @@ public static boolean getGamepadState(int jid, GLFWGamepadState state) { * @glfw.thread_safety This function must only be called from the main thread. * @see #ngetClipboardString() getClipboardString */ - public static void nsetClipboardString(MemorySegment string) { - try { - glfwSetClipboardString.invokeExact(MemorySegment.NULL, string); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } + @Entrypoint("glfwSetClipboardString") + void nsetClipboardString(MemorySegment window, MemorySegment string); + + /** + * Sets the clipboard to the specified string. + *

+ * This function sets the system clipboard to the specified, UTF-8 encoded + * string. + * + * @param string A UTF-8 encoded string. + * @glfw.errors Possible errors include {@link #NOT_INITIALIZED} and + * {@link #PLATFORM_ERROR}. + * @glfw.pointer_lifetime The specified string is copied before this function + * returns. + * @glfw.thread_safety This function must only be called from the main thread. + * @see #ngetClipboardString() getClipboardString + */ + @Skip + default void nsetClipboardString(MemorySegment string) { + nsetClipboardString(MemorySegment.NULL, string); } /** @@ -5416,13 +4656,10 @@ public static void nsetClipboardString(MemorySegment string) { * @param string A UTF-8 encoded string. * @see #nsetClipboardString(MemorySegment) nsetClipboardString */ - public 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); } } @@ -5434,6 +4671,7 @@ public 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}, @@ -5446,12 +4684,33 @@ public static void setClipboardString(String string) { * @glfw.thread_safety This function must only be called from the main thread. * @see #nsetClipboardString(MemorySegment) setClipboardString */ - public static MemorySegment ngetClipboardString() { - 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); } /** @@ -5461,10 +4720,10 @@ public static MemorySegment ngetClipboardString() { * if an error occurred. * @see #ngetClipboardString() ngetClipboardString */ + @Skip @Nullable - public static String getClipboardString(@Deprecated MemorySegment window) { - var pString = ngetClipboardString(); - return RuntimeHelper.isNullptr(pString) ? null : pString.getString(0); + default String getClipboardString() { + return ngetClipboardString().getString(0L); } /** @@ -5488,13 +4747,8 @@ public static String getClipboardString(@Deprecated MemorySegment window) { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #setTime}. */ - public static double getTime() { - try { - return (double) glfwGetTime.invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } + @Entrypoint("glfwGetTime") + double getTime(); /** * Sets the GLFW time. @@ -5516,13 +4770,8 @@ public static double getTime() { * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to {@link #getTime}. */ - public static void setTime(double time) { - 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. @@ -5537,13 +4786,8 @@ public static void setTime(double time) { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerFrequency */ - public 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. @@ -5556,13 +4800,8 @@ public static long getTimerValue() { * @glfw.thread_safety This function may be called from any thread. * @see #getTimerValue */ - public 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 @@ -5600,13 +4839,8 @@ public static long getTimerFrequency() { * @glfw.thread_safety This function may be called from any thread. * @see #getCurrentContext */ - public 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. @@ -5620,13 +4854,8 @@ public static void makeContextCurrent(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #makeContextCurrent */ - public 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. @@ -5650,13 +4879,8 @@ public static MemorySegment getCurrentContext() { * @glfw.thread_safety This function may be called from any thread. * @see #swapInterval */ - public 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. @@ -5693,13 +4917,8 @@ public static void swapBuffers(MemorySegment window) { * @glfw.thread_safety This function may be called from any thread. * @see #swapBuffers */ - public static void swapInterval(int interval) { - 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. @@ -5730,13 +4949,9 @@ public static void swapInterval(int interval) { * @glfw.thread_safety This function may be called from any thread. * @see #ngetProcAddress */ - public static boolean nextensionSupported(MemorySegment extension) { - 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. @@ -5746,15 +4961,9 @@ public static boolean nextensionSupported(MemorySegment extension) { * otherwise. * @see #nextensionSupported(MemorySegment) nextensionSupported */ - public 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 @@ -5768,7 +4977,7 @@ public static boolean extensionSupported(String extension) { * without a current context will cause a {@link #NO_CURRENT_CONTEXT} error. *

* This function does not apply to Vulkan. If you are rendering with Vulkan, - * see {@link GLFWVulkan#nglfwGetInstanceProcAddress(MemorySegment, MemorySegment) glfwGetInstanceProcAddress}, + * see {@link GLFWVulkan#ngetInstanceProcAddress(MemorySegment, MemorySegment) glfwGetInstanceProcAddress}, * {@code vkGetInstanceProcAddr} and {@code vkGetDeviceProcAddr} instead. * * @param procName The ASCII encoded name of the function. @@ -5787,13 +4996,8 @@ public static boolean extensionSupported(String extension) { * @glfw.thread_safety This function may be called from any thread. * @see #nextensionSupported */ - public static MemorySegment ngetProcAddress(MemorySegment procName) { - 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 @@ -5804,15 +5008,8 @@ public static MemorySegment ngetProcAddress(MemorySegment procName) { * error occurred. * @see #ngetProcAddress(MemorySegment) ngetProcAddress */ - public 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. @@ -5824,7 +5021,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} @@ -5832,13 +5029,9 @@ public static MemorySegment getProcAddress(String procName) { * @glfw.errors Possible errors include {@link #NOT_INITIALIZED}. * @glfw.thread_safety This function may be called from any thread. */ - public static boolean vulkanSupported() { - 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. @@ -5872,13 +5065,8 @@ public static boolean vulkanSupported() { * library is terminated. * @glfw.thread_safety This function may be called from any thread. */ - public 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. @@ -5887,19 +5075,14 @@ public static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) * error occurred. * @see #ngetRequiredInstanceExtensions(MemorySegment) ngetRequiredInstanceExtensions */ - public 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 05e1b152..99d03e85 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCallbacks.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -18,8 +18,8 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * The GLFW window callbacks. @@ -28,7 +28,7 @@ * @since 0.1.0 */ public final class GLFWCallbacks { - private static final Map ARENA_MAP = new HashMap<>(); + private static final Map ARENA_MAP = new ConcurrentHashMap<>(); private GLFWCallbacks() { //no instance @@ -42,7 +42,7 @@ private GLFWCallbacks() { * @return the arena. */ public static Arena create(MemorySegment window) { - return ARENA_MAP.computeIfAbsent(window, k -> Arena.ofConfined()); + return ARENA_MAP.computeIfAbsent(window, _ -> Arena.ofConfined()); } /** @@ -52,6 +52,23 @@ public static Arena create(MemorySegment window) { */ public static void free(MemorySegment window) { if (ARENA_MAP.containsKey(window)) { + 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/IGLFWCharFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java index 63b9cb01..5b15487b 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCharFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for Unicode character callbacks. * A Unicode character callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCharFun::invoke) - * void functionName(MemorySegment window, int codepoint); + * void functionName(MemorySegment window, int codepoint); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCharFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCharFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for Unicode character callbacks. @@ -48,15 +45,11 @@ public interface IGLFWCharFun extends Callback { * @param window The window that received the event. * @param codepoint The Unicode code point of the character. */ + @Stub void invoke(MemorySegment window, int codepoint); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCharFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java index 69e7219a..169e6bce 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorEnterFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for cursor enter/leave callbacks. * A cursor enter/leave callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCursorEnterFun::invoke) - * void functionName(MemorySegment window, boolean entered); + * void functionName(MemorySegment window, boolean entered); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCursorEnterFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCursorEnterFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for cursor enter/leave callbacks. @@ -51,17 +48,20 @@ public interface IGLFWCursorEnterFun extends Callback { */ void invoke(MemorySegment window, boolean entered); + /** + * The function pointer type for cursor enter/leave callbacks. + * + * @param window The window that received the event. + * @param entered {@code true} if the cursor entered the window's content + * area, or {@code false} if it left it. + */ + @Stub default void ninvoke(MemorySegment window, int entered) { invoke(window, entered != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCursorEnterFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java similarity index 63% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java index 27dd7060..d8bba273 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWCursorPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for cursor position callbacks. A cursor * position callback function has the following signature: * {@snippet : - * @Invoker(IGLFWCursorPosFun::invoke) - * void functionName(MemorySegment window, double xpos, double ypos); + * void functionName(MemorySegment window, double xpos, double ypos); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWCursorPosFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWCursorPosFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for cursor position callbacks. @@ -49,15 +46,11 @@ public interface IGLFWCursorPosFun extends Callback { * @param xpos The new cursor x-coordinate, relative to the left edge of the content area. * @param ypos The new cursor y-coordinate, relative to the top edge of the content area. */ + @Stub void invoke(MemorySegment window, double xpos, double ypos); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWCursorPosFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java similarity index 63% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java index 6d26f956..2b13bc8c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWDropFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,22 +16,17 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; import overrungl.internal.RuntimeHelper; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for path drop callbacks. A path drop * callback function has the following signature: - * {@snippet lang=java: - * @Invoker(IGLFWDropFun::invoke) - * void functionName(MemorySegment window, String[] paths); + * {@snippet lang = java: + * void functionName(MemorySegment window, String[] paths); // @link regex="functionName" target="#invoke" * } *

Pointer lifetime

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

Pointer lifetime

* The error description string is valid until the callback @@ -43,9 +39,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWErrorFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWErrorFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for error callbacks. @@ -55,26 +53,29 @@ public interface IGLFWErrorFun extends Callback { */ void invoke(int errorCode, String description); - default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) { - invoke(errorCode, RuntimeHelper.getString(description)); + /** + * The function pointer type for error callbacks. + * + * @param errorCode An error code. + * Future releases may add more error codes. + * @param description A UTF-8 encoded string describing the error. + */ + @Stub + default void ninvoke(int errorCode, @NativeType("const char*") @SizedSeg(Unmarshal.STR_SIZE) MemorySegment description) { + invoke(errorCode, Unmarshal.unmarshalAsString(description)); } /** * 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); - } - - @Override - default FunctionDescriptor descriptor() { - return DESC; + return GLFW.INSTANCE.setErrorCallback(this); } @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWErrorFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java index 5078dbd8..2dffce53 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWFramebufferSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for framebuffer size callbacks. * A framebuffer size callback function has the following signature: * {@snippet : - * @Invoker(IGLFWFramebufferSizeFun::invoke) - * void functionName(MemorySegment window, int width, int height); + * void functionName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWFramebufferSizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWFramebufferSizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for framebuffer size callbacks. @@ -49,15 +46,11 @@ public interface IGLFWFramebufferSizeFun extends Callback { * @param width The new width, in pixels, of the framebuffer. * @param height The new height, in pixels, of the framebuffer. */ + @Stub void invoke(MemorySegment window, int width, int height); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWFramebufferSizeFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java index 0ff1095a..a7133d8b 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,81 +16,78 @@ package overrungl.glfw; -import overrungl.Struct; +import overrun.marshal.struct.Struct; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; /** * This describes the input state of a gamepad. *

Layout

*

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

Layout

*

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

Layout

*

  * struct GLFWimage {
- *     int {@link #width() width};
- *     int {@link #height() height};
- *     unsigned char* {@link #pixels() pixels};
+ *     int {@link #width};
+ *     int {@link #height};
+ *     unsigned char* {@link #pixels};
  * }
* * @author squid233 * @since 0.1.0 */ -public sealed class GLFWImage extends Struct { +public final class GLFWImage extends Struct { /** * The struct layout. */ public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_INT.withName("width"), - JAVA_INT.withName("height"), - ADDRESS.withTargetLayout(RuntimeHelper.ADDRESS_UNBOUNDED).withName("pixels") + ValueLayout.JAVA_INT.withName("width"), + ValueLayout.JAVA_INT.withName("height"), + ValueLayout.ADDRESS.withName("pixels") ); - private static final VarHandle - pWidth = LAYOUT.varHandle(PathElement.groupElement("width")), - pHeight = LAYOUT.varHandle(PathElement.groupElement("height")), - pPixels = LAYOUT.varHandle(PathElement.groupElement("pixels")); - - /** - * Create a {@code GLFWImage} instance. - * - * @param address the address. - */ - public GLFWImage(MemorySegment address) { - super(address, LAYOUT); - } - - /** - * Creates a struct instance with the given memory layout. - * - * @param address the address. - * @param layout the memory layout of this struct. - */ - protected GLFWImage(MemorySegment address, MemoryLayout layout) { - super(address, layout); - } - - /** - * {@return the elements size of this struct in bytes} - */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - - /** - * Creates a {@code GLFWImage} instance with the given allocator. - * - * @param allocator the allocator - * @return the instance - */ - public static GLFWImage create(SegmentAllocator allocator) { - return new GLFWImage(allocator.allocate(LAYOUT)); - } - - /** - * Creates a {@code GLFWImage.Buffer} instance with the given allocator and count. - * - * @param allocator the allocator - * @param count the count - * @return the instance - */ - public static Buffer create(SegmentAllocator allocator, long count) { - return new Buffer(allocator.allocate(LAYOUT, count), count); - } - /** - * Sets the image width. - * - * @param width The width, in pixels, of this image. - * @return this + * The width, in pixels, of this image. */ - public GLFWImage width(int width) { - pWidth.set(segment(), width); - return this; - } - + public final StructHandle.Int width = StructHandle.ofInt(this, "width"); /** - * Sets the image height. - * - * @param height The height, in pixels, of this image. - * @return this + * The height, in pixels, of this image. */ - public GLFWImage height(int height) { - pHeight.set(segment(), height); - return this; - } - + public final StructHandle.Int height = StructHandle.ofInt(this, "height"); /** - * Sets the image pixels address. - * - * @param pixels The pixel data address of this image, arranged left-to-right, top-to-bottom. - * @return this + * The pixel data address of this image, arranged left-to-right, top-to-bottom. */ - public GLFWImage pixels(MemorySegment pixels) { - pPixels.set(segment(), pixels); - return this; - } + public final StructHandle.Address pixels = StructHandle.ofAddress(this, "pixels"); /** - * Gets the image width. + * Creates a struct with the given layout. * - * @return The width, in pixels, of this image. + * @param segment the segment + * @param elementCount the element count */ - public int width() { - return (int) pWidth.get(segment()); + public GLFWImage(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * Gets the image height. + * Allocates a struct with the given layout. * - * @return The height, in pixels, of this image. + * @param allocator the allocator + * @param elementCount the element count */ - public int height() { - return (int) pHeight.get(segment()); + public GLFWImage(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Gets the image pixels address. + * Creates a struct with the given layout. * - * @return The pixel data address of this image, arranged left-to-right, top-to-bottom. + * @param segment the segment */ - public MemorySegment pixels() { - return (MemorySegment) pPixels.get(segment()); + public GLFWImage(MemorySegment segment) { + super(segment, LAYOUT); } /** - * This describes 2D images. + * Allocates a struct with the given layout. * - * @author squid233 - * @since 0.1.0 + * @param allocator the allocator */ - public static final class Buffer extends GLFWImage implements ArrayPointer { - private final VarHandle pWidth, pHeight, pPixels; - - /** - * Create a {@code GLFWImage.Buffer} instance. - * - * @param address the address. - * @param elementCount the element count - */ - public Buffer(MemorySegment address, long elementCount) { - super(address, MemoryLayout.sequenceLayout(elementCount, LAYOUT)); - pWidth = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("width")); - pHeight = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("height")); - pPixels = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("pixels")); - } - - /** - * Sets the image width at the given index. - * - * @param index the index - * @param width The width, in pixels, of this image. - * @return this - */ - public Buffer width(long index, int width) { - pWidth.set(segment(), index, width); - return this; - } - - /** - * Sets the image height at the given index. - * - * @param index the index - * @param height The height, in pixels, of this image. - * @return this - */ - public Buffer height(long index, int height) { - pHeight.set(segment(), index, height); - return this; - } - - /** - * Sets the image pixels address at the given index. - * - * @param index the index - * @param pixels The pixel data address of this image, arranged left-to-right, top-to-bottom. - * @return this - */ - public Buffer pixels(long index, MemorySegment pixels) { - pPixels.set(segment(), index, pixels); - return this; - } - - @Override - public Buffer width(int width) { - return width(0, width); - } - - @Override - public Buffer height(int height) { - return height(0, height); - } - - @Override - public Buffer pixels(MemorySegment pixels) { - return pixels(0, pixels); - } - - /** - * Gets the image width at the given index. - * - * @param index the index - * @return The width, in pixels, of this image. - */ - public int widthAt(long index) { - return (int) pWidth.get(segment(), index); - } - - /** - * Gets the image height at the given index. - * - * @param index the index - * @return The height, in pixels, of this image. - */ - public int heightAt(long index) { - return (int) pHeight.get(segment(), index); - } - - /** - * Gets the image pixels address at the given index. - * - * @param index the index - * @return The pixel data address of this image, arranged left-to-right, top-to-bottom. - */ - public MemorySegment pixelsAt(long index) { - return (MemorySegment) pPixels.get(segment(), index); - } - - @Override - public int width() { - return widthAt(0); - } - - @Override - public int height() { - return heightAt(0); - } - - @Override - public MemorySegment pixels() { - return pixelsAt(0); - } + public GLFWImage(SegmentAllocator allocator) { + super(allocator, LAYOUT); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java similarity index 60% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java index 169c97b7..fdfc0b20 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWJoystickFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,20 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; /** * This is the function pointer type for joystick configuration callbacks. * A joystick configuration callback function has the following signature: * {@snippet : - * @Invoker(IGLFWJoystickFun::invoke) - * void functionName(int jid, int event); + * void functionName(int jid, int event); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -37,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWJoystickFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWJoystickFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for joystick configuration callbacks. @@ -48,15 +46,11 @@ public interface IGLFWJoystickFun extends Callback { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ + @Stub void invoke(int jid, int event); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWJoystickFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java similarity index 66% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java index 06b27857..bd87b937 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWKeyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for keyboard key callbacks. A keyboard * key callback function has the following signature: * {@snippet : - * @Invoker(IGLFWKeyFun::invoke) - * void functionName(MemorySegment window, int key, int scancode, int action, int mods); + * void functionName(MemorySegment window, int key, int scancode, int action, int mods); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWKeyFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWKeyFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for keyboard key callbacks. @@ -53,15 +50,11 @@ public interface IGLFWKeyFun extends Callback { * @param mods Bit field describing which modifier keys * were held down. */ + @Stub void invoke(MemorySegment window, int key, int scancode, int action, int mods); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWKeyFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java similarity index 60% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java index f4302297..d8e36873 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMonitorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for monitor configuration callbacks. * A monitor callback function has the following signature: * {@snippet : - * @Invoker(IGLFWMonitorFun::invoke) - * void functionName(MemorySegment monitor, int event); + * void functionName(MemorySegment monitor, int event); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWMonitorFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWMonitorFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for monitor configuration callbacks. @@ -49,15 +46,11 @@ public interface IGLFWMonitorFun extends Callback { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ + @Stub void invoke(MemorySegment monitor, int event); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWMonitorFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java similarity index 65% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java index e9349481..970d5a83 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWMouseButtonFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for mouse button callback functions. * A mouse button callback function has the following signature: * {@snippet : - * @Invoker(IGLFWMouseButtonFun::invoke) - * void functionName(MemorySegment window, int button, int action, int mods); + * void functionName(MemorySegment window, int button, int action, int mods); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWMouseButtonFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWMouseButtonFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for mouse button callbacks. @@ -50,15 +47,11 @@ public interface IGLFWMouseButtonFun extends Callback { * @param action One of {@code PRESS} or {@code RELEASE}. Future releases may add more actions. * @param mods Bit field describing which modifier keys were held down. */ + @Stub void invoke(MemorySegment window, int button, int action, int mods); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWMouseButtonFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/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/IGLFWScrollFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java similarity index 61% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java index 2d8a4564..ee483d7e 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWScrollFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for scroll callbacks. A scroll callback * function has the following signature: * {@snippet : - * @Invoker(IGLFWScrollFun::invoke) - * void functionName(MemorySegment window, double xoffset, double yoffset); + * void functionName(MemorySegment window, double xoffset, double yoffset); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWScrollFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWScrollFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for scroll callbacks. @@ -49,15 +46,11 @@ public interface IGLFWScrollFun extends Callback { * @param xoffset The scroll offset along the x-axis. * @param yoffset The scroll offset along the y-axis. */ + @Stub void invoke(MemorySegment window, double xoffset, double yoffset); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWScrollFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/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/IGLFWWindowCloseFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java similarity index 58% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java index e4747f44..128d295c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowCloseFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window close callbacks. A window * close callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowCloseFun::invoke) - * void functionName(MemorySegment window); + * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,24 +33,22 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowCloseFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowCloseFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window close callbacks. * * @param window The window that the user attempted to close. */ + @Stub void invoke(MemorySegment window); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowCloseFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java index f640da18..b82ca1a3 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowContentScaleFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window content scale callbacks. * A window content scale callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowContentScaleFun::invoke) - * void functionName(MemorySegment window, float xscale, float yscale); + * void functionName(MemorySegment window, float xscale, float yscale); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowContentScaleFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowContentScaleFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window content scale callbacks. @@ -49,15 +46,11 @@ public interface IGLFWWindowContentScaleFun extends Callback { * @param xscale The new x-axis content scale of the window. * @param yscale The new y-axis content scale of the window. */ + @Stub void invoke(MemorySegment window, float xscale, float yscale); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowContentScaleFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java index 3b782ba2..be237d00 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowFocusFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window focus callbacks. A window * focus callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowFocusFun::invoke) - * void functionName(MemorySegment window, boolean focused); + * void functionName(MemorySegment window, boolean focused); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowFocusFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowFocusFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window focus callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowFocusFun extends Callback { */ void invoke(MemorySegment window, boolean focused); + /** + * The function pointer type for window focus callbacks. + * + * @param window The window that gained or lost input focus. + * @param focused {@code true} if the window was given input focus, or + * {@code false} if it lost it. + */ + @Stub default void ninvoke(MemorySegment window, int focused) { invoke(window, focused != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowFocusFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java index 2baa6750..34837046 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowIconifyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window iconify callbacks. A window * iconify callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowIconifyFun::invoke) - * void functionName(MemorySegment window, boolean iconified); + * void functionName(MemorySegment window, boolean iconified); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowIconifyFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowIconifyFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window iconify callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowIconifyFun extends Callback { */ void invoke(MemorySegment window, boolean iconified); + /** + * The function pointer type for window iconify callbacks. + * + * @param window The window that was iconified or restored. + * @param iconified {@code true} if the window was iconified, or + * {@code false} if it was restored. + */ + @Stub default void ninvoke(MemorySegment window, int iconified) { invoke(window, iconified != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowIconifyFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java index 8896c448..2d7f5b40 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowMaximizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window maximize callbacks. A window * maximize callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowMaximizeFun::invoke) - * void functionName(MemorySegment window, boolean maximized); + * void functionName(MemorySegment window, boolean maximized); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowMaximizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowMaximizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window maximize callbacks. @@ -51,17 +48,20 @@ public interface IGLFWWindowMaximizeFun extends Callback { */ void invoke(MemorySegment window, boolean maximized); + /** + * The function pointer type for window maximize callbacks. + * + * @param window The window that was maximized or restored. + * @param maximized {@code true} if the window was maximized, or + * {@code false} if it was restored. + */ + @Stub default void ninvoke(MemorySegment window, int maximized) { invoke(window, maximized != GLFW.FALSE); } @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowMaximizeFun.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java index 3dd23e53..2d6c82c9 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** - * This is the function pointer type for window position callbacks.A window - * position callback function has the following signature: + * This is the function pointer type for window position callbacks. + * A window position callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowPosFun::invoke) - * void callbackName(MemorySegment window, int xpos, int ypos); + * void callbackName(MemorySegment window, int xpos, int ypos); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowPosFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowPosFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window position callbacks. @@ -51,15 +48,11 @@ public interface IGLFWWindowPosFun extends Callback { * @param ypos The new y-coordinate, in screen coordinates, of the * upper-left corner of the content area of the window. */ + @Stub void invoke(MemorySegment window, int xpos, int ypos); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowPosFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java similarity index 59% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java index ab966963..f4c3776f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowRefreshFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window content refresh callbacks. * A window content refresh callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowRefreshFun::invoke) - * void functionName(MemorySegment window); + * void functionName(MemorySegment window); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,24 +33,22 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowRefreshFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowRefreshFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window content refresh callbacks. * * @param window The window whose content needs to be refreshed. */ + @Stub void invoke(MemorySegment window); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowRefreshFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java similarity index 62% rename from modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java rename to modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java index 9bbb49c6..05b88a99 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/IGLFWWindowSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,21 +16,16 @@ package overrungl.glfw; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.foreign.ValueLayout; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; /** * This is the function pointer type for window size callbacks. A window size * callback function has the following signature: * {@snippet : - * @Invoker(IGLFWWindowSizeFun::invoke) - * void callbackName(MemorySegment window, int width, int height); + * void callbackName(MemorySegment window, int width, int height); // @link regex="functionName" target="#invoke" * } * * @author squid233 @@ -38,9 +33,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface IGLFWWindowSizeFun extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT); - MethodType MTYPE = DESC.toMethodType(); +public interface GLFWWindowSizeFun extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * The function pointer type for window size callbacks. @@ -49,15 +46,11 @@ public interface IGLFWWindowSizeFun extends Callback { * @param width The new width, in screen coordinates, of the window. * @param height The new height, in screen coordinates, of the window. */ + @Stub void invoke(MemorySegment window, int width, int height); @Override - default FunctionDescriptor descriptor() { - return DESC; - } - - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(IGLFWWindowSizeFun.class, "invoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } 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..20a2e3f4 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/Handles.java @@ -23,7 +23,6 @@ import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; -import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; import java.lang.invoke.MethodHandle; import java.util.function.Supplier; @@ -38,7 +37,7 @@ * @since 0.1.0 */ final class Handles { - private static final SymbolLookup lookup; + static final SymbolLookup lookup; static { final Supplier lib = () -> RuntimeHelper.load("glfw", "glfw3", OverrunGL.GLFW_VERSION); @@ -163,39 +162,6 @@ final class Handles { glfwVulkanSupported = downcall("glfwVulkanSupported", I), glfwGetRequiredInstanceExtensions = downcall("glfwGetRequiredInstanceExtensions", Pp); - // GLFW Vulkan - static final MethodHandle - glfwGetInstanceProcAddress = downcall("glfwGetInstanceProcAddress", PPP), - glfwGetPhysicalDevicePresentationSupport = downcall("glfwGetPhysicalDevicePresentationSupport", PPII), - glfwCreateWindowSurface = downcall("glfwCreateWindowSurface", PPPPI); - - // GLFW Native - static final MethodHandle - glfwGetWin32Adapter = downcallNative("glfwGetWin32Adapter", Pp), - glfwGetWin32Monitor = downcallNative("glfwGetWin32Monitor", Pp), - glfwGetWin32Window = downcallNative("glfwGetWin32Window", PP), - glfwGetWGLContext = downcallNative("glfwGetWGLContext", PP), - glfwGetCocoaMonitor = downcallNative("glfwGetCocoaMonitor", fd_PI), - glfwGetCocoaWindow = downcallNative("glfwGetCocoaWindow", PP), - glfwGetNSGLContext = downcallNative("glfwGetNSGLContext", PP), - glfwGetX11Display = downcallNative("glfwGetX11Display", P), - glfwGetX11Adapter = downcallNative("glfwGetX11Adapter", PJ), - glfwGetX11Monitor = downcallNative("glfwGetX11Monitor", PJ), - glfwGetX11Window = downcallNative("glfwGetX11Window", PJ), - glfwSetX11SelectionString = downcallNative("glfwSetX11SelectionString", PV), - glfwGetX11SelectionString = downcallNative("glfwGetX11SelectionString", p), - glfwGetGLXContext = downcallNative("glfwGetGLXContext", PP), - glfwGetGLXWindow = downcallNative("glfwGetGLXWindow", PJ), - glfwGetWaylandDisplay = downcallNative("glfwGetWaylandDisplay", P), - glfwGetWaylandMonitor = downcallNative("glfwGetWaylandMonitor", PP), - glfwGetWaylandWindow = downcallNative("glfwGetWaylandWindow", PP), - glfwGetEGLDisplay = downcallNative("glfwGetEGLDisplay", P), - glfwGetEGLContext = downcallNative("glfwGetEGLContext", PP), - glfwGetEGLSurface = downcallNative("glfwGetEGLSurface", PP), - glfwGetOSMesaColorBuffer = downcallNative("glfwGetOSMesaColorBuffer", PPPPPI), - glfwGetOSMesaDepthBuffer = downcallNative("glfwGetOSMesaDepthBuffer", PPPPPI), - glfwGetOSMesaContext = downcallNative("glfwGetOSMesaContext", PP); - private Handles() { //no instance } @@ -216,9 +182,4 @@ private static MethodHandle downcallTrivial(String name, FunctionDescriptors function) { return downcall(name, function, Linker.Option.critical(false)); } - - private static MethodHandle downcallNative(String name, - FunctionDescriptors function) { - return RuntimeHelper.downcallSafe(lookup.find(name).orElse(MemorySegment.NULL), function); - } } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java new file mode 100644 index 00000000..96eef129 --- /dev/null +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.glfw; + +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; + +import java.lang.invoke.VarHandle; + +/** + * Sized array struct handle + * + * @author squid233 + * @since 0.1.0 + */ +public final class StructHandleSizedByteArray extends StructHandle { + private StructHandleSizedByteArray(VarHandle varHandle) { + super(varHandle); + } + + /** + * Creates it + * + * @param struct struct + * @param name name + * @return handle + */ + static StructHandleSizedByteArray of(Struct struct, String name) { + return new StructHandleSizedByteArray(StructHandle.ofSizedArray(struct, name)); + } + + /** + * Sets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @param value the value + */ + public void set(long index, long arrayIndex, byte value) { + varHandle.set(0L, index, arrayIndex, value); + } + + /** + * Sets the value. + * + * @param arrayIndex the array index + * @param value the value + */ + public void set(long arrayIndex, byte value) { + set(0L, arrayIndex, value); + } + + /** + * Gets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @return the value + */ + public byte get(long index, long arrayIndex) { + return (byte) varHandle.get(0L, index, arrayIndex); + } + + /** + * Gets the value. + * + * @param arrayIndex the array index + * @return the value + */ + public byte get(long arrayIndex) { + return get(0L, arrayIndex); + } +} diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java new file mode 100644 index 00000000..9424cdcc --- /dev/null +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2024 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.glfw; + +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; + +import java.lang.invoke.VarHandle; + +/** + * Sized array struct handle + * + * @author squid233 + * @since 0.1.0 + */ +public final class StructHandleSizedFloatArray extends StructHandle { + private StructHandleSizedFloatArray(VarHandle varHandle) { + super(varHandle); + } + + /** + * Creates it + * + * @param struct struct + * @param name name + * @return handle + */ + static StructHandleSizedFloatArray of(Struct struct, String name) { + return new StructHandleSizedFloatArray(StructHandle.ofSizedArray(struct, name)); + } + + /** + * Sets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @param value the value + */ + public void set(long index, long arrayIndex, float value) { + varHandle.set(0L, index, arrayIndex, value); + } + + /** + * Sets the value. + * + * @param arrayIndex the array index + * @param value the value + */ + public void set(long arrayIndex, float value) { + set(0L, arrayIndex, value); + } + + /** + * Gets the value at the given index. + * + * @param index the index + * @param arrayIndex the array index + * @return the value + */ + public float get(long index, long arrayIndex) { + return (short) varHandle.get(0L, index, arrayIndex); + } + + /** + * Gets the value. + * + * @param arrayIndex the array index + * @return the value + */ + public float get(long arrayIndex) { + return get(0L, arrayIndex); + } +} diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java index e8f5317a..5856d329 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java @@ -99,8 +99,8 @@ public static NFDNFilterItem create(SegmentAllocator allocator, Pair... final NFDNFilterItem buffer = new NFDNFilterItem(allocator.allocate(LAYOUT, items.length), items.length); for (int i = 0, len = items.length; i < len; i++) { Pair item = items[i]; - buffer._name.set(allocator, i, item.key()); - buffer._spec.set(allocator, i, item.value()); + buffer._name.set(i, allocator, item.key()); + buffer._spec.set(i, allocator, item.value()); } return buffer; } diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java index cb206a89..81a2e229 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java @@ -99,8 +99,8 @@ public static NFDU8FilterItem create(SegmentAllocator allocator, Pair... final NFDU8FilterItem buffer = new NFDU8FilterItem(allocator.allocate(LAYOUT, items.length), items.length); for (int i = 0, len = items.length; i < len; i++) { Pair item = items[i]; - buffer._name.set(allocator, i, item.key()); - buffer._spec.set(allocator, i, item.value()); + buffer._name.set(i, allocator, item.key()); + buffer._spec.set(i, allocator, item.value()); } return buffer; } diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java index 4292a3a4..cf5e508c 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWJoystickTest.java @@ -32,6 +32,7 @@ * @since 0.1.0 */ public final class GLFWJoystickTest { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -39,54 +40,53 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - GLFW.windowHint(GLFW.CLIENT_API, GLFW.NO_API); - window = GLFW.createWindow(200, 100, "Holder", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + glfw.windowHint(GLFW.CLIENT_API, GLFW.NO_API); + window = glfw.createWindow(200, 100, "Holder", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setJoystickCallback((jid, event) -> { + glfw.setJoystickCallback((jid, event) -> { switch (event) { case GLFW.CONNECTED -> { - boolean isGamepad = GLFW.joystickIsGamepad(jid); + boolean isGamepad = glfw.joystickIsGamepad(jid); var prefix = isGamepad ? "Gamepad " : "Joystick "; - System.out.println(STR."\{prefix}\{jid}: \"\{(isGamepad ? GLFW.getGamepadName(jid) : GLFW.getJoystickName(jid))}\" has connected"); + System.out.println(STR."\{prefix}\{jid}: \"\{(isGamepad ? glfw.getGamepadName(jid) : glfw.getJoystickName(jid))}\" has connected"); } case GLFW.DISCONNECTED -> System.out.println(STR."Joystick \{jid} has disconnected"); } }); - GLFW.showWindow(window); + glfw.showWindow(window); } private void loop() { var states = new GLFWGamepadState[GLFW.JOYSTICK_LAST + 1]; for (int i = 0; i < states.length; i++) { - states[i] = GLFWGamepadState.create(Arena.global()); + states[i] = new GLFWGamepadState(Arena.ofAuto()); } - while (!GLFW.windowShouldClose(window)) { -// try (var arena = Arena.openShared()) { + while (!glfw.windowShouldClose(window)) { for (int i = 0; i <= GLFW.JOYSTICK_LAST; i++) { - if (GLFW.joystickPresent(i)) { - if (GLFW.joystickIsGamepad(i)) { + if (glfw.joystickPresent(i)) { + if (glfw.joystickIsGamepad(i)) { var state = states[i]; - if (GLFW.getGamepadState(i, state)) { + if (glfw.getGamepadState(i, state)) { System.out.println(STR.""" - Get gamepad state for [jid=\{i},name=\{GLFW.getGamepadName(i)}] successful: + Get gamepad state for [jid=\{i},name=\{glfw.getGamepadName(i)}] successful: Buttons: [A(Cross)=\{state.button(GLFW.GAMEPAD_BUTTON_A)}, B(Circle)=\{state.button(GLFW.GAMEPAD_BUTTON_B)}, X(Square)=\{state.button(GLFW.GAMEPAD_BUTTON_X)}, Y(Triangle)=\{state.button(GLFW.GAMEPAD_BUTTON_Y)}, Left bumper=\{state.button(GLFW.GAMEPAD_BUTTON_LEFT_BUMPER)}, Right bumper=\{state.button(GLFW.GAMEPAD_BUTTON_RIGHT_BUMPER)}, Back=\{state.button(GLFW.GAMEPAD_BUTTON_BACK)}, Start=\{state.button(GLFW.GAMEPAD_BUTTON_START)}, Guide=\{state.button(GLFW.GAMEPAD_BUTTON_GUIDE)}, Left thumb=\{state.button(GLFW.GAMEPAD_BUTTON_LEFT_THUMB)}, Right thumb=\{state.button(GLFW.GAMEPAD_BUTTON_RIGHT_THUMB)}, @@ -97,8 +97,7 @@ private void loop() { } } } -// } - GLFW.waitEventsTimeout(3); + glfw.waitEventsTimeout(3); } } diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java index adb97763..1443f4c0 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GLFWWindowIconTest { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -50,19 +51,19 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init(Arena arena) { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); try { @@ -74,51 +75,52 @@ private void init(Arena arena) { IOUtil.ioResourceToSegment(arena, "image.png", 256), px, py, pc, STBImage.RGB_ALPHA ); - GLFW.setWindowIcon(window, GLFWImage.create(arena, 1) - .width(px.get(JAVA_INT, 0)) - .height(py.get(JAVA_INT, 0)) - .pixels(data)); + final GLFWImage image = new GLFWImage(arena); + image.width.set(px.get(JAVA_INT, 0)); + image.height.set(py.get(JAVA_INT, 0)); + image.pixels.set(data); + glfw.setWindowIcon(window, image); stbImage.free(data); } catch (IOException e) { throw new RuntimeException(e); } - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load() { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java index 4dbf2a8e..5cc93b34 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java @@ -34,6 +34,7 @@ * @since 0.1.0 */ public final class GL10Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; public void run() { @@ -42,51 +43,51 @@ public void run() { loop(); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load() { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle @@ -99,9 +100,9 @@ private void loop() { GL10.vertex2f(0.5f, -0.5f); GL10.end(); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java index 768103ba..076543de 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GL15Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int vbo, tex; @@ -54,45 +55,45 @@ public void run() { GL.deleteTexture(tex); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(640, 480, "OpenGL 1.5", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(640, 480, "OpenGL 1.5", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); GL.enable(GL.TEXTURE_2D); @@ -137,7 +138,7 @@ private void load(Arena arena) { } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle @@ -158,9 +159,9 @@ private void loop() { GL.bindBuffer(GL.ARRAY_BUFFER, 0); GL.bindTexture(GL.TEXTURE_2D, 0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java index 5d3cee9b..95200ff4 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java @@ -40,6 +40,7 @@ * @since 0.1.0 */ public final class GL30Test { + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int program; private int colorFactor; @@ -60,45 +61,45 @@ public void run() { GL.deleteTexture(tex); GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - window = GLFW.createWindow(640, 480, "OpenGL 3.0", MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + window = glfw.createWindow(640, 480, "OpenGL 3.0", MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); @@ -201,22 +202,22 @@ void main() { } private void loop() { - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); // Draw triangle GL.bindTexture(GL.TEXTURE_2D, tex); GL.useProgram(program); - GL.uniform1f(colorFactor, (float) ((Math.sin(GLFW.getTime() * 2) + 1 * 0.5) * 0.6 + 0.4)); + GL.uniform1f(colorFactor, (float) ((Math.sin(glfw.getTime() * 2) + 1 * 0.5) * 0.6 + 0.4)); GL.bindVertexArray(vao); GL.drawElements(GL.TRIANGLES, 6, GL.UNSIGNED_BYTE, MemorySegment.NULL); GL.bindVertexArray(0); GL.useProgram(0); GL.bindTexture(GL.TEXTURE_2D, 0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); } } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java index 420a0ad9..7eef2b79 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java @@ -43,6 +43,7 @@ public class GL33Test { private static final int INSTANCE_COUNT = square(10); private static final String WND_TITLE = "OpenGL 3.3"; private static final boolean VSYNC = true; + private final GLFW glfw = GLFW.INSTANCE; private MemorySegment window; private int program; private int rotationMat; @@ -68,49 +69,49 @@ public void run() { } GLFWCallbacks.free(window); - GLFW.destroyWindow(window); + glfw.destroyWindow(window); debugProc.close(); - GLFW.terminate(); - GLFW.setErrorCallback(null); + glfw.terminate(); + glfw.setErrorCallback(null); } private void init() { GLFWErrorCallback.createPrint().set(); - CheckUtil.check(GLFW.init(), "Unable to initialize GLFW"); - GLFW.defaultWindowHints(); - GLFW.windowHint(GLFW.VISIBLE, false); - GLFW.windowHint(GLFW.RESIZABLE, true); - GLFW.windowHint(GLFW.CONTEXT_VERSION_MAJOR, 3); - GLFW.windowHint(GLFW.CONTEXT_VERSION_MINOR, 3); - GLFW.windowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE); - window = GLFW.createWindow(640, 480, WND_TITLE, MemorySegment.NULL, MemorySegment.NULL); + CheckUtil.check(glfw.init(), "Unable to initialize GLFW"); + glfw.defaultWindowHints(); + glfw.windowHint(GLFW.VISIBLE, false); + glfw.windowHint(GLFW.RESIZABLE, true); + glfw.windowHint(GLFW.CONTEXT_VERSION_MAJOR, 3); + glfw.windowHint(GLFW.CONTEXT_VERSION_MINOR, 3); + glfw.windowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE); + window = glfw.createWindow(640, 480, WND_TITLE, MemorySegment.NULL, MemorySegment.NULL); CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window"); - GLFW.setKeyCallback(window, (_, key, _, action, _) -> { + glfw.setKeyCallback(window, (_, key, _, action, _) -> { if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) { - GLFW.setWindowShouldClose(window, true); + glfw.setWindowShouldClose(window, true); } }); - GLFW.setFramebufferSizeCallback(window, (_, width, height) -> + glfw.setFramebufferSizeCallback(window, (_, width, height) -> GL.viewport(0, 0, width, height)); - var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor()); + var vidMode = glfw.getVideoMode(glfw.getPrimaryMonitor()); if (vidMode != null) { - var size = GLFW.getWindowSize(window); - GLFW.setWindowPos( + var size = glfw.getWindowSize(window); + glfw.setWindowPos( window, (vidMode.width() - size.x()) / 2, (vidMode.height() - size.y()) / 2 ); } - GLFW.makeContextCurrent(window); - if (VSYNC) GLFW.swapInterval(1); + glfw.makeContextCurrent(window); + if (VSYNC) glfw.swapInterval(1); - GLFW.showWindow(window); + glfw.showWindow(window); } private void load(Arena arena) { - Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(glfw::getProcAddress, true), "Failed to load OpenGL"); debugProc = GLUtil.setupDebugMessageCallback(); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); @@ -222,9 +223,9 @@ private void loop() { var matrix = new Matrix4f(); var pRotationMat = Matrixn.allocate(Arena.ofAuto(), matrix); - var timer = Timer.ofGetter(20, GLFW::getTime); + var timer = Timer.ofGetter(20, glfw::getTime); - while (!GLFW.windowShouldClose(window)) { + while (!glfw.windowShouldClose(window)) { timer.advanceTime(); timer.performTicks(null); @@ -243,13 +244,13 @@ private void loop() { GL.bindVertexArray(0); GL.useProgram(0); - GLFW.swapBuffers(window); + glfw.swapBuffers(window); - GLFW.pollEvents(); + glfw.pollEvents(); // using lambda gets higher FPS ?? timer.calcFPS(fps -> { - GLFW.setWindowTitle(window, STR."\{WND_TITLE} FPS: \{fps}"); + glfw.setWindowTitle(window, STR."\{WND_TITLE} FPS: \{fps}"); }); } } diff --git a/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java b/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java index f2336550..089e04df 100644 --- a/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java +++ b/modules/samples/src/test/java/overrungl/demo/util/IOUtil.java @@ -69,7 +69,8 @@ public static MemorySegment ioResourceToSegment(Arena arena, String resource, lo Objects.requireNonNull(IOUtil.class.getClassLoader().getResourceAsStream(resource), STR."Failed to load resource '\{resource}'!") ) { - MemorySegment segment = arena.allocate(segmentSize); + Arena readArena = Arena.ofConfined(); + MemorySegment segment = readArena.allocate(segmentSize); // Creates a byte array to avoid creating it each loop final byte[] bytes = new byte[bufferSize]; @@ -77,13 +78,17 @@ public static MemorySegment ioResourceToSegment(Arena arena, String resource, lo int count; while ((count = is.read(bytes)) > 0) { if (pos + count >= segment.byteSize()) { - segment = resizeSegment(arena, segment, Math.ceilDiv(segment.byteSize() * 3, 2)); // 50% + Arena newArena = Arena.ofConfined(); + segment = resizeSegment(newArena, segment, Math.ceilDiv(segment.byteSize() * 3, 2)); // 50% + readArena.close(); + readArena = newArena; } MemorySegment.copy(bytes, 0, segment, ValueLayout.JAVA_BYTE, pos, count); pos += count; } + readArena.close(); - return segment.asSlice(0, pos); + return segment.asSlice(0, pos).reinterpret(arena, null); } catch (URISyntaxException e) { throw new IllegalArgumentException(STR."Illegal URI: \{resource}", e); }