diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index dd794f9d..fd3b2392 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -30,10 +30,10 @@ jobs: - name: Grant execute permission for gradlew if: ${{ runner.os != 'Windows' }} run: chmod +x gradlew - - name: Build with Gradle - uses: gradle/gradle-build-action@v2 - with: - arguments: build --no-daemon -x :samples:test + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + - name: Execute Gradle build + run: ./gradlew build --no-daemon -x :samples:test - name: Upload build reports if: ${{ runner.os == 'Linux' && matrix.java == '22-ea' && failure() }} uses: actions/upload-artifact@v4 diff --git a/build.gradle.kts b/build.gradle.kts index a2840ec7..4c957697 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,6 @@ plugins { `java-platform` `maven-publish` signing - id("me.champeau.jmh") version "0.7.2" apply false } val projGroupId: String by project @@ -127,7 +126,6 @@ artifactNameMap.forEach { (subprojectName, artifactName) -> project(subprojectName) { apply(plugin = "java-library") apply(plugin = "idea") - apply(plugin = "me.champeau.jmh") group = projGroupId version = projVersion diff --git a/gradle.properties b/gradle.properties index 7352914b..82f19517 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,5 +18,5 @@ jdkEnablePreview=true jdkEarlyAccessDoc=jdk22 kotlinTargetJdkVersion=21 -overrunMarshalVersion=0.1.0-alpha.17-jdk22 +overrunMarshalVersion=0.1.0-alpha.20-jdk22 overrunPlatformVersion=1.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e093..a80b22ce 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f..25da30db 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail 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 ca63a8bf..6bfbf956 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -17,6 +17,7 @@ package overrungl.glfw; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -40,7 +41,7 @@ * @author squid233 * @since 0.1.0 */ -public interface GLFW { +public interface GLFW extends DirectAccess { /** * The instance of GLFW. */ diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java index 5b15487b..7bb43101 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCharFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for Unicode character callbacks. @@ -37,7 +39,7 @@ public interface GLFWCharFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for Unicode character callbacks. @@ -45,7 +47,6 @@ public interface GLFWCharFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java index 169e6bce..2ddad45a 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorEnterFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for cursor enter/leave callbacks. @@ -37,7 +39,7 @@ public interface GLFWCursorEnterFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for cursor enter/leave callbacks. @@ -55,7 +57,6 @@ public interface GLFWCursorEnterFun extends Upcall { * @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); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java index d8bba273..37ba2fdf 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWCursorPosFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for cursor position callbacks. A cursor @@ -37,7 +39,7 @@ public interface GLFWCursorPosFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE)); /** * The function pointer type for cursor position callbacks. @@ -46,7 +48,6 @@ public interface GLFWCursorPosFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java index 79a742c8..d19d6c9a 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWDropFun.java @@ -20,6 +20,7 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; @@ -41,7 +42,7 @@ public interface GLFWDropFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS)); /** * The function pointer type for path drop callbacks. @@ -58,7 +59,6 @@ public interface GLFWDropFun extends Upcall { * @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, Unmarshal.unmarshalAsStringArray(paths.reinterpret(ValueLayout.ADDRESS.scale(0L, pathCount)))); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java index a8751f40..e691b158 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWErrorFun.java @@ -18,12 +18,15 @@ import overrun.marshal.Unmarshal; import overrun.marshal.Upcall; -import overrun.marshal.gen.SizedSeg; import overrungl.NativeType; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; +import static java.lang.foreign.ValueLayout.*; + /** * This is the function pointer type for error callbacks. An error callback * function has the following signature: @@ -43,7 +46,7 @@ public interface GLFWErrorFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(JAVA_INT, ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, JAVA_BYTE)))); /** * The function pointer type for error callbacks. @@ -60,8 +63,7 @@ public interface GLFWErrorFun extends Upcall { * 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) { + default void ninvoke(int errorCode, @NativeType("const char*") MemorySegment description) { invoke(errorCode, Unmarshal.unmarshalAsString(description)); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java index 2dffce53..cd567067 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWFramebufferSizeFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for framebuffer size callbacks. @@ -37,7 +39,7 @@ public interface GLFWFramebufferSizeFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for framebuffer size callbacks. @@ -46,7 +48,6 @@ public interface GLFWFramebufferSizeFun extends Upcall { * @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 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 a7133d8b..44e4f10c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java @@ -45,12 +45,12 @@ public final class GLFWGamepadState extends Struct { * The states of each gamepad button, * {@link GLFW#PRESS} or {@link GLFW#RELEASE}. */ - public final StructHandleSizedByteArray buttons = StructHandleSizedByteArray.of(this, "buttons"); + public static final StructHandleSizedByteArray buttons = StructHandleSizedByteArray.of(LAYOUT, "buttons"); /** * The states of each gamepad axis, * in the range -1.0 to 1.0 inclusive. */ - public final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(this, "axes"); + public static final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(LAYOUT, "axes"); /** * Creates a struct with the given layout. @@ -97,7 +97,7 @@ public GLFWGamepadState(SegmentAllocator allocator) { * @return the state, {@code PRESS} or {@code RELEASE} */ public boolean button(int index) { - return buttons.get(index) == GLFW.PRESS; + return buttons.get(this, index) == GLFW.PRESS; } /** @@ -107,6 +107,6 @@ public boolean button(int index) { * @return the state, in the range -1.0 to 1.0 inclusive */ public float axe(int index) { - return axes.get(index); + return axes.get(this, 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 85d8aae2..ec904d4d 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java @@ -55,19 +55,19 @@ public final class GLFWGammaRamp extends Struct { /** * An array of value describing the response of the red channel. */ - public final StructHandle.Array red = StructHandle.ofArray(this, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + public static final StructHandle.Array red = StructHandle.ofArray(LAYOUT, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** * An array of value describing the response of the green channel. */ - public final StructHandle.Array green = StructHandle.ofArray(this, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + public static final StructHandle.Array green = StructHandle.ofArray(LAYOUT, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** * An array of value describing the response of the blue channel. */ - public final StructHandle.Array blue = StructHandle.ofArray(this, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + public static final StructHandle.Array blue = StructHandle.ofArray(LAYOUT, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray); /** * The number of elements in each array. */ - public final StructHandle.Int size = StructHandle.ofInt(this, "size"); + public static final StructHandle.Int size = StructHandle.ofInt(LAYOUT, "size"); /** * Creates a struct with the given 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 b9136a8f..09736d0a 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java @@ -47,15 +47,15 @@ public final class GLFWImage extends Struct { /** * The width, in pixels, of this image. */ - public final StructHandle.Int width = StructHandle.ofInt(this, "width"); + public static final StructHandle.Int width = StructHandle.ofInt(LAYOUT, "width"); /** * The height, in pixels, of this image. */ - public final StructHandle.Int height = StructHandle.ofInt(this, "height"); + public static final StructHandle.Int height = StructHandle.ofInt(LAYOUT, "height"); /** * The pixel data address of this image, arranged left-to-right, top-to-bottom. */ - public final StructHandle.Address pixels = StructHandle.ofAddress(this, "pixels"); + public static final StructHandle.Address pixels = StructHandle.ofAddress(LAYOUT, "pixels"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java index fdfc0b20..c447e5b4 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWJoystickFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for joystick configuration callbacks. @@ -37,7 +39,7 @@ public interface GLFWJoystickFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for joystick configuration callbacks. @@ -46,7 +48,6 @@ public interface GLFWJoystickFun extends Upcall { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ - @Stub void invoke(int jid, int event); @Override diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java index bd87b937..837b8ef0 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWKeyFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for keyboard key callbacks. A keyboard @@ -37,7 +39,7 @@ public interface GLFWKeyFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for keyboard key callbacks. @@ -50,7 +52,6 @@ public interface GLFWKeyFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java index d8e36873..3ad5f3e2 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMonitorFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for monitor configuration callbacks. @@ -37,7 +39,7 @@ public interface GLFWMonitorFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for monitor configuration callbacks. @@ -46,7 +48,6 @@ public interface GLFWMonitorFun extends Upcall { * @param event One of {@code CONNECTED} or {@code DISCONNECTED}. Future * releases may add more events. */ - @Stub void invoke(MemorySegment monitor, int event); @Override diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java index 970d5a83..17ebaba9 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWMouseButtonFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for mouse button callback functions. @@ -37,7 +39,7 @@ public interface GLFWMouseButtonFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for mouse button callbacks. @@ -47,7 +49,6 @@ public interface GLFWMouseButtonFun extends Upcall { * @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 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 006fd944..ba57c945 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java @@ -17,6 +17,7 @@ package overrungl.glfw; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Convert; import overrun.marshal.gen.Entrypoint; @@ -36,7 +37,7 @@ * @author squid233 * @since 0.1.0 */ -public interface GLFWNative { +public interface GLFWNative extends DirectAccess { /** * The instance of GLFWNative. */ diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java index ee483d7e..36fc48d4 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWScrollFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for scroll callbacks. A scroll callback @@ -37,7 +39,7 @@ public interface GLFWScrollFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE)); /** * The function pointer type for scroll callbacks. @@ -46,7 +48,6 @@ public interface GLFWScrollFun extends Upcall { * @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 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 3f341976..3efec5fe 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java @@ -54,27 +54,27 @@ public final class GLFWVidMode extends Struct { /** * the width, in screen coordinates, of the video mode */ - public final StructHandle.Int width = StructHandle.ofInt(this, "width"); + public static final StructHandle.Int width = StructHandle.ofInt(LAYOUT, "width"); /** * the height, in screen coordinates, of the video mode */ - public final StructHandle.Int height = StructHandle.ofInt(this, "height"); + public static final StructHandle.Int height = StructHandle.ofInt(LAYOUT, "height"); /** * the bit depth of the red channel of the video mode */ - public final StructHandle.Int redBits = StructHandle.ofInt(this, "redBits"); + public static final StructHandle.Int redBits = StructHandle.ofInt(LAYOUT, "redBits"); /** * the bit depth of the green channel of the video mode */ - public final StructHandle.Int greenBits = StructHandle.ofInt(this, "greenBits"); + public static final StructHandle.Int greenBits = StructHandle.ofInt(LAYOUT, "greenBits"); /** * the bit depth of the blue channel of the video mode */ - public final StructHandle.Int blueBits = StructHandle.ofInt(this, "blueBits"); + public static final StructHandle.Int blueBits = StructHandle.ofInt(LAYOUT, "blueBits"); /** * the refresh rate, in Hz, of the video mode */ - public final StructHandle.Int refreshRate = StructHandle.ofInt(this, "refreshRate"); + public static final StructHandle.Int refreshRate = StructHandle.ofInt(LAYOUT, "refreshRate"); /** * Creates a struct with the given layout. @@ -118,7 +118,12 @@ public GLFWVidMode(SegmentAllocator allocator) { * {@return an immutable state of this struct} */ public Value value() { - return new Value(width.get(), height.get(), redBits.get(), greenBits.get(), blueBits.get(), refreshRate.get()); + return new Value(width.get(this), + height.get(this), + redBits.get(this), + greenBits.get(this), + blueBits.get(this), + refreshRate.get(this)); } /** 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 b7d2ad59..b2444a8f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java @@ -16,6 +16,7 @@ package overrungl.glfw; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Convert; import overrun.marshal.gen.Entrypoint; @@ -31,7 +32,7 @@ * @author squid233 * @since 0.1.0 */ -public interface GLFWVulkan { +public interface GLFWVulkan extends DirectAccess { /** * The instance of GLFWVulkan. */ diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java index 128d295c..4ec98408 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowCloseFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window close callbacks. A window @@ -37,14 +39,13 @@ public interface GLFWWindowCloseFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)); /** * The function pointer type for window close callbacks. * * @param window The window that the user attempted to close. */ - @Stub void invoke(MemorySegment window); @Override diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java index b82ca1a3..dd5256de 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowContentScaleFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window content scale callbacks. @@ -37,7 +39,7 @@ public interface GLFWWindowContentScaleFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT)); /** * The function pointer type for window content scale callbacks. @@ -46,7 +48,6 @@ public interface GLFWWindowContentScaleFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java index be237d00..bdbf30f9 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowFocusFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window focus callbacks. A window @@ -37,7 +39,7 @@ public interface GLFWWindowFocusFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for window focus callbacks. @@ -55,7 +57,6 @@ public interface GLFWWindowFocusFun extends Upcall { * @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); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java index 34837046..6884656f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowIconifyFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window iconify callbacks. A window @@ -37,7 +39,7 @@ public interface GLFWWindowIconifyFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for window iconify callbacks. @@ -55,7 +57,6 @@ public interface GLFWWindowIconifyFun extends Upcall { * @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); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java index 2d7f5b40..82f74f21 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowMaximizeFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window maximize callbacks. A window @@ -37,7 +39,7 @@ public interface GLFWWindowMaximizeFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * The function pointer type for window maximize callbacks. @@ -55,7 +57,6 @@ public interface GLFWWindowMaximizeFun extends Upcall { * @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); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java index 2d6c82c9..5d44b2f5 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowPosFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window position callbacks. @@ -37,7 +39,7 @@ public interface GLFWWindowPosFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for window position callbacks. @@ -48,7 +50,6 @@ public interface GLFWWindowPosFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java index f4c3776f..d6a498df 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowRefreshFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window content refresh callbacks. @@ -37,14 +39,13 @@ public interface GLFWWindowRefreshFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)); /** * 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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java index 05b88a99..96bbf0e7 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWWindowSizeFun.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * This is the function pointer type for window size callbacks. A window size @@ -37,7 +39,7 @@ public interface GLFWWindowSizeFun extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT)); /** * The function pointer type for window size callbacks. @@ -46,7 +48,6 @@ public interface GLFWWindowSizeFun extends Upcall { * @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 diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java index 96eef129..e4a2af8d 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java @@ -16,9 +16,11 @@ package overrungl.glfw; +import overrun.marshal.Marshal; import overrun.marshal.struct.Struct; import overrun.marshal.struct.StructHandle; +import java.lang.foreign.StructLayout; import java.lang.invoke.VarHandle; /** @@ -39,49 +41,53 @@ private StructHandleSizedByteArray(VarHandle varHandle) { * @param name name * @return handle */ - static StructHandleSizedByteArray of(Struct struct, String name) { + static StructHandleSizedByteArray of(StructLayout struct, String name) { return new StructHandleSizedByteArray(StructHandle.ofSizedArray(struct, name)); } /** * Sets the value at the given index. * + * @param struct the struct * @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); + public void set(Struct struct, long index, long arrayIndex, byte value) { + varHandle.set(Marshal.marshal(struct), 0L, index, arrayIndex, value); } /** * Sets the value. * + * @param struct the struct * @param arrayIndex the array index * @param value the value */ - public void set(long arrayIndex, byte value) { - set(0L, arrayIndex, value); + public void set(Struct struct, long arrayIndex, byte value) { + set(struct, 0L, arrayIndex, value); } /** * Gets the value at the given index. * + * @param struct the struct * @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); + public byte get(Struct struct, long index, long arrayIndex) { + return (byte) varHandle.get(Marshal.marshal(struct), 0L, index, arrayIndex); } /** * Gets the value. * + * @param struct the struct * @param arrayIndex the array index * @return the value */ - public byte get(long arrayIndex) { - return get(0L, arrayIndex); + public byte get(Struct struct, long arrayIndex) { + return get(struct, 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 index 9424cdcc..0c5aa91f 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java @@ -16,9 +16,11 @@ package overrungl.glfw; +import overrun.marshal.Marshal; import overrun.marshal.struct.Struct; import overrun.marshal.struct.StructHandle; +import java.lang.foreign.StructLayout; import java.lang.invoke.VarHandle; /** @@ -39,49 +41,53 @@ private StructHandleSizedFloatArray(VarHandle varHandle) { * @param name name * @return handle */ - static StructHandleSizedFloatArray of(Struct struct, String name) { + static StructHandleSizedFloatArray of(StructLayout struct, String name) { return new StructHandleSizedFloatArray(StructHandle.ofSizedArray(struct, name)); } /** * Sets the value at the given index. * - * @param index the index + * @param struct the struct + * @param index the index * @param arrayIndex the array index - * @param value the value + * @param value the value */ - public void set(long index, long arrayIndex, float value) { - varHandle.set(0L, index, arrayIndex, value); + public void set(Struct struct, long index, long arrayIndex, float value) { + varHandle.set(Marshal.marshal(struct), 0L, index, arrayIndex, value); } /** * Sets the value. * + * @param struct the struct * @param arrayIndex the array index - * @param value the value + * @param value the value */ - public void set(long arrayIndex, float value) { - set(0L, arrayIndex, value); + public void set(Struct struct, long arrayIndex, float value) { + set(struct, 0L, arrayIndex, value); } /** * Gets the value at the given index. * - * @param index the index + * @param struct the struct + * @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); + public float get(Struct struct, long index, long arrayIndex) { + return (short) varHandle.get(Marshal.marshal(struct), 0L, index, arrayIndex); } /** * Gets the value. * + * @param struct the struct * @param arrayIndex the array index * @return the value */ - public float get(long arrayIndex) { - return get(0L, arrayIndex); + public float get(Struct struct, long arrayIndex) { + return get(struct, 0L, arrayIndex); } } diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java index fd651642..52bd75ef 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java @@ -16,10 +16,7 @@ package overrungl.nfd; -import overrun.marshal.Downcall; -import overrun.marshal.Marshal; -import overrun.marshal.MemoryStack; -import overrun.marshal.Unmarshal; +import overrun.marshal.*; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.SizedSeg; import overrun.marshal.gen.Skip; @@ -124,7 +121,7 @@ * @author squid233 * @since 0.1.0 */ -public interface NFD { +public interface NFD extends DirectAccess { /** * The type of the path-set size ({@code long} for Windows and Mac OS X, {@code int} for others). */ @@ -132,7 +129,7 @@ public interface NFD { /** * The instance of NFD. */ - NFD INSTANCE = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, Map.of( + NFD INSTANCE = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, DowncallOption.descriptors(Map.of( "NFD_PathSet_GetPathN", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS), "NFD_PathSet_FreePathN", FunctionDescriptor.ofVoid(ADDRESS), "NFD_FreePathU8", FunctionDescriptor.ofVoid(ADDRESS), @@ -142,7 +139,7 @@ public interface NFD { "NFD_PickFolderU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS), "NFD_PathSet_GetPathU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS), "NFD_PathSet_EnumNextU8", FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS) - )); + ))); /** * {@return NFD_PathSet_GetPathN} 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 5856d329..48b31500 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java @@ -42,16 +42,16 @@ public final class NFDNFilterItem extends Struct { ValueLayout.ADDRESS.withName("name"), ValueLayout.ADDRESS.withName("spec") ); - private final StructHandle.Str _name = StructHandle.ofString(this, "name", NFDInternal.nfdCharset); - private final StructHandle.Str _spec = StructHandle.ofString(this, "spec", NFDInternal.nfdCharset); + private static final StructHandle.Str _name = StructHandle.ofString(LAYOUT, "name", NFDInternal.nfdCharset); + private static final StructHandle.Str _spec = StructHandle.ofString(LAYOUT, "spec", NFDInternal.nfdCharset); /** * name */ - public final StructHandleView.Str name = _name; + public static final StructHandleView.Str name = _name; /** * spec */ - public final StructHandleView.Str spec = _spec; + public static final StructHandleView.Str spec = _spec; /** * Create a {@code NFDNFilterItem} instance. @@ -82,8 +82,8 @@ public NFDNFilterItem(MemorySegment segment, long elementCount) { */ public static NFDNFilterItem create(SegmentAllocator allocator, String name, String spec) { final NFDNFilterItem item = new NFDNFilterItem(allocator.allocate(LAYOUT)); - item._name.set(allocator, name); - item._spec.set(allocator, spec); + _name.set(item, allocator, name); + _spec.set(item, allocator, spec); return item; } @@ -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(i, allocator, item.key()); - buffer._spec.set(i, allocator, item.value()); + _name.set(buffer, i, allocator, item.key()); + _spec.set(buffer, 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 81a2e229..9398729e 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java @@ -42,16 +42,16 @@ public final class NFDU8FilterItem extends Struct { ValueLayout.ADDRESS.withName("name"), ValueLayout.ADDRESS.withName("spec") ); - private final StructHandle.Str _name = StructHandle.ofString(this, "name"); - private final StructHandle.Str _spec = StructHandle.ofString(this, "spec"); + private static final StructHandle.Str _name = StructHandle.ofString(LAYOUT, "name"); + private static final StructHandle.Str _spec = StructHandle.ofString(LAYOUT, "spec"); /** * name */ - public final StructHandleView.Str name = _name; + public static final StructHandleView.Str name = _name; /** * spec */ - public final StructHandleView.Str spec = _spec; + public static final StructHandleView.Str spec = _spec; /** * Create a {@code NFDU8FilterItem} instance. @@ -82,8 +82,8 @@ public NFDU8FilterItem(MemorySegment segment, long elementCount) { */ public static NFDU8FilterItem create(SegmentAllocator allocator, String name, String spec) { final NFDU8FilterItem item = new NFDU8FilterItem(allocator.allocate(LAYOUT)); - item._name.set(allocator, name); - item._spec.set(allocator, spec); + _name.set(item, allocator, name); + _spec.set(item, allocator, spec); return item; } @@ -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(i, allocator, item.key()); - buffer._spec.set(i, allocator, item.value()); + _name.set(buffer, i, allocator, item.key()); + _spec.set(buffer, i, allocator, item.value()); } return buffer; } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java index a86f77c9..b7e5f3ed 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java @@ -48,19 +48,19 @@ public final class DrawArraysIndirectCommand extends Struct { /** * the count */ - public final StructHandle.Int count = StructHandle.ofInt(this, "count"); + public static final StructHandle.Int count = StructHandle.ofInt(LAYOUT, "count"); /** * the primCount */ - public final StructHandle.Int primCount = StructHandle.ofInt(this, "primCount"); + public static final StructHandle.Int primCount = StructHandle.ofInt(LAYOUT, "primCount"); /** * the first */ - public final StructHandle.Int first = StructHandle.ofInt(this, "first"); + public static final StructHandle.Int first = StructHandle.ofInt(LAYOUT, "first"); /** * the baseInstance */ - public final StructHandle.Int baseInstance = StructHandle.ofInt(this, "baseInstance"); + public static final StructHandle.Int baseInstance = StructHandle.ofInt(LAYOUT, "baseInstance"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java index ec08d704..97f6436a 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java @@ -50,23 +50,23 @@ public final class DrawElementsIndirectCommand extends Struct { /** * the count */ - public final StructHandle.Int count = StructHandle.ofInt(this, "count"); + public static final StructHandle.Int count = StructHandle.ofInt(LAYOUT, "count"); /** * the primCount */ - public final StructHandle.Int primCount = StructHandle.ofInt(this, "primCount"); + public static final StructHandle.Int primCount = StructHandle.ofInt(LAYOUT, "primCount"); /** * the firstIndex */ - public final StructHandle.Int firstIndex = StructHandle.ofInt(this, "firstIndex"); + public static final StructHandle.Int firstIndex = StructHandle.ofInt(LAYOUT, "firstIndex"); /** * the baseVertex */ - public final StructHandle.Int baseVertex = StructHandle.ofInt(this, "baseVertex"); + public static final StructHandle.Int baseVertex = StructHandle.ofInt(LAYOUT, "baseVertex"); /** * the baseInstance */ - public final StructHandle.Int baseInstance = StructHandle.ofInt(this, "baseInstance"); + public static final StructHandle.Int baseInstance = StructHandle.ofInt(LAYOUT, "baseInstance"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL.java index 716fc27f..6f8ac402 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL.java @@ -16,11 +16,18 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The latest OpenGL functions. * * @author squid233 * @since 0.1.0 */ -public non-sealed interface GL extends GL46C { +public interface GL extends + DirectAccess, + GL10C, GL11C, GL12C, GL13C, GL14C, GL15C, + GL20C, GL21C, + GL30C, GL31C, GL32C, GL33C, + GL40C, GL41C, GL42C, GL43C, GL44C, GL45C, GL46C { } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java index ff72c7d6..de5d92c1 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -34,7 +35,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL10 extends GL10C permits GLLegacy { +public interface GL10 extends DirectAccess { @Entrypoint("glAccum") default void accum(int op, float value) { throw new ContextException(); diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java index 4e3245f8..f63c78f5 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; import overrun.marshal.gen.Entrypoint; @@ -35,7 +36,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL10C permits GL10, GL11C { +public interface GL10C extends DirectAccess { int DEPTH_BUFFER_BIT = 0x00000100; int STENCIL_BUFFER_BIT = 0x00000400; int COLOR_BUFFER_BIT = 0x00004000; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11.java index d4638d95..e7499197 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.Unmarshal; import overrun.marshal.gen.Entrypoint; @@ -31,7 +32,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL11 extends GL11C permits GLLegacy { +public interface GL11 extends DirectAccess { int CURRENT_BIT = 0x00000001, POINT_BIT = 0x00000002, LINE_BIT = 0x00000004, diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java index edbc0a3b..a01d444c 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -33,7 +34,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL11C extends GL10C permits GL11, GL12C { +public interface GL11C extends DirectAccess { int COLOR_LOGIC_OP = 0x0BF2; int POLYGON_OFFSET_UNITS = 0x2A00; int POLYGON_OFFSET_POINT = 0x2A01; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12.java index fe1e25a6..d5ea0fa5 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12.java @@ -16,13 +16,15 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The OpenGL 1.2 constants. * * @author squid233 * @since 0.1.0 */ -public sealed interface GL12 extends GL12C permits GLLegacy { +public interface GL12 extends DirectAccess { int RESCALE_NORMAL = 0x803A; int LIGHT_MODEL_COLOR_CONTROL = 0x81F8, SINGLE_COLOR = 0x81F9, diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12C.java index ea487872..5bc8beed 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL12C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.gen.Entrypoint; import java.lang.foreign.MemorySegment; @@ -27,7 +28,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL12C extends GL11C permits GL12, GL13C { +public interface GL12C extends DirectAccess { int UNSIGNED_BYTE_3_3_2 = 0x8032; int UNSIGNED_SHORT_4_4_4_4 = 0x8033; int UNSIGNED_SHORT_5_5_5_1 = 0x8034; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13.java index aba8a7eb..a9ca561e 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.gen.Entrypoint; import overrungl.opengl.ext.arb.GLARBTransposeMatrix; @@ -33,7 +34,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL13 extends GL13C permits GLLegacy { +public interface GL13 extends DirectAccess { int CLIENT_ACTIVE_TEXTURE = 0x84E1; int MAX_TEXTURE_UNITS = 0x84E2; int TRANSPOSE_MODELVIEW_MATRIX = 0x84E3; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13C.java index 74bd264a..1d754e74 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL13C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.gen.Entrypoint; import overrungl.opengl.ext.arb.*; @@ -36,7 +37,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL13C extends GL12C permits GL13, GL14C { +public interface GL13C extends DirectAccess { int TEXTURE0 = 0x84C0; int TEXTURE1 = 0x84C1; int TEXTURE2 = 0x84C2; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14.java index e6b67b5e..2386bc48 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.gen.Entrypoint; import overrungl.opengl.ext.arb.GLARBWindowPos; @@ -33,7 +34,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL14 extends GL14C permits GLLegacy { +public interface GL14 extends DirectAccess { @Entrypoint("glFogCoordPointer") default void fogCoordPointer(int type, int stride, MemorySegment pointer) { throw new ContextException(); diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14C.java index 057e63fb..e9795ad9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL14C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.Skip; @@ -42,7 +43,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL14C extends GL13C permits GL14, GL15C { +public interface GL14C extends DirectAccess { int BLEND_DST_RGB = 0x80C8; int BLEND_SRC_RGB = 0x80C9; int BLEND_DST_ALPHA = 0x80CA; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15.java index 5c84f272..e9786e1d 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15.java @@ -16,13 +16,15 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The OpenGL 1.5 constants. * * @author squid233 * @since 0.1.0 */ -public sealed interface GL15 extends GL15C permits GLLegacy { +public interface GL15 extends DirectAccess { int VERTEX_ARRAY_BUFFER_BINDING = 0x8896; int NORMAL_ARRAY_BUFFER_BINDING = 0x8897; int COLOR_ARRAY_BUFFER_BINDING = 0x8898; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java index af019620..b1e76d17 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -42,7 +43,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL15C extends GL14C permits GL15, GL20C { +public interface GL15C extends DirectAccess { int BUFFER_SIZE = 0x8764; int BUFFER_USAGE = 0x8765; int QUERY_COUNTER_BITS = 0x8864; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20.java index 2f225515..dc4394f9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20.java @@ -16,13 +16,15 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The OpenGL 2.0 constants. * * @author squid233 * @since 0.1.0 */ -public sealed interface GL20 extends GL20C permits GLLegacy { +public interface GL20 extends DirectAccess { int VERTEX_PROGRAM_TWO_SIDE = 0x8643; int POINT_SPRITE = 0x8861; int COORD_REPLACE = 0x8862; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java index 9a31659d..93873157 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -47,7 +48,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL20C extends GL15C permits GL20, GL21C { +public interface GL20C extends DirectAccess { int BLEND_EQUATION_RGB = 0x8009; int VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622; int VERTEX_ATTRIB_ARRAY_SIZE = 0x8623; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21.java index 563be0f6..4e2a3d8a 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21.java @@ -16,13 +16,15 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The OpenGL 2.1 constants. * * @author squid233 * @since 0.1.0 */ -public sealed interface GL21 extends GL21C permits GLLegacy { +public interface GL21 extends DirectAccess { int CURRENT_RASTER_SECONDARY_COLOR = 0x845F; int SLUMINANCE_ALPHA = 0x8C44; int SLUMINANCE8_ALPHA8 = 0x8C45; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21C.java index f22c7f17..9e251b1a 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL21C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.Skip; import overrungl.opengl.ext.arb.GLARBPixelBufferObject; @@ -34,7 +35,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL21C extends GL20C permits GL21, GL30C { +public interface GL21C extends DirectAccess { int PIXEL_PACK_BUFFER = 0x88EB; int PIXEL_UNPACK_BUFFER = 0x88EC; int PIXEL_PACK_BUFFER_BINDING = 0x88ED; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30.java index 03f83bab..206c60b9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30.java @@ -16,13 +16,15 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** * The OpenGL 3.0 constants. * * @author squid233 * @since 0.1.0 */ -public sealed interface GL30 extends GL30C permits GLLegacy { +public interface GL30 extends DirectAccess { int CLAMP_VERTEX_COLOR = 0x891A; int CLAMP_FRAGMENT_COLOR = 0x891B; int ALPHA_INTEGER = 0x8D97; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java index 04c22a36..55bcd06e 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -48,7 +49,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL30C extends GL21C permits GL30, GL31C { +public interface GL30C extends DirectAccess { int COMPARE_REF_TO_TEXTURE = 0x884E; int CLIP_DISTANCE0 = 0x3000; int CLIP_DISTANCE1 = 0x3001; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java index 5de483c6..809f9ac8 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -41,7 +42,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL31C extends GL30C permits GL32C { +public interface GL31C extends DirectAccess { int SAMPLER_2D_RECT = 0x8B63; int SAMPLER_2D_RECT_SHADOW = 0x8B64; int SAMPLER_BUFFER = 0x8DC2; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java index a25a7ac9..bfe44bef 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -43,7 +44,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL32C extends GL31C permits GL33C { +public interface GL32C extends DirectAccess { int CONTEXT_CORE_PROFILE_BIT = 0x00000001; int CONTEXT_COMPATIBILITY_PROFILE_BIT = 0x00000002; int LINES_ADJACENCY = 0x000A; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java index 3d61f403..bba0e81e 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -44,7 +45,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL33C extends GL32C permits GL40C { +public interface GL33C extends DirectAccess { int VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE; int SRC1_COLOR = 0x88F9; int ONE_MINUS_SRC1_COLOR = 0x88FA; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java index 8d71dddd..fed58cba 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -52,7 +53,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL40C extends GL33C permits GL41C { +public interface GL40C extends DirectAccess { int SAMPLE_SHADING = 0x8C36; int MIN_SAMPLE_SHADING_VALUE = 0x8C37; int MIN_PROGRAM_TEXTURE_GATHER_OFFSET = 0x8E5E; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java index 8a1b8e06..8805c54b 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -45,7 +46,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL41C extends GL40C permits GL42C { +public interface GL41C extends DirectAccess { int FIXED = 0x140C; int IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A; int IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B; @@ -236,7 +237,7 @@ default void getProgramPipelineInfoLog(SegmentAllocator allocator, int pipeline, @Skip default String getProgramPipelineInfoLog(SegmentAllocator allocator, int pipeline) { - final int sz = getProgramPipelineiv(pipeline, INFO_LOG_LENGTH); + final int sz = getProgramPipelineiv(pipeline, GL20C.INFO_LOG_LENGTH); var pi = allocator.allocate(JAVA_BYTE, sz); getProgramPipelineInfoLog(pipeline, sz, MemorySegment.NULL, pi); return pi.getString(0); diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java index 8111edce..133a58f6 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -45,7 +46,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL42C extends GL41C permits GL43C { +public interface GL42C extends DirectAccess { int COPY_READ_BUFFER_BINDING = 0x8F36; int COPY_WRITE_BUFFER_BINDING = 0x8F37; int TRANSFORM_FEEDBACK_ACTIVE = 0x8E24; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java index 45028ca9..45676a81 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -57,7 +58,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL43C extends GL42C permits GL44C { +public interface GL43C extends DirectAccess { int NUM_SHADING_LANGUAGE_VERSIONS = 0x82E9; int VERTEX_ATTRIB_ARRAY_LONG = 0x874E; int COMPRESSED_RGB8_ETC2 = 0x9274; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL44C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL44C.java index b597e9c9..84058ceb 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL44C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL44C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.Skip; @@ -36,7 +37,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL44C extends GL43C permits GL45C { +public interface GL44C extends DirectAccess { int MAX_VERTEX_ATTRIB_STRIDE = 0x82E5; int PRIMITIVE_RESTART_FOR_PATCHES_SUPPORTED = 0x8221; int TEXTURE_BUFFER_BINDING = 0x8C2A; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java index bb512591..c61ee4d3 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java @@ -16,6 +16,7 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -47,7 +48,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL45C extends GL44C permits GL46C { +public interface GL45C extends DirectAccess { int CONTEXT_LOST = 0x0507; int NEGATIVE_ONE_TO_ONE = 0x935E; int ZERO_TO_ONE = 0x935F; @@ -931,14 +932,14 @@ default MethodHandle glMapNamedBuffer() { @Skip default MemorySegment mapNamedBuffer(int buffer, int access) { - return mapNamedBuffer(buffer, access, getNamedBufferParameteri64v(buffer, BUFFER_SIZE)); + return mapNamedBuffer(buffer, access, getNamedBufferParameteri64v(buffer, GL15C.BUFFER_SIZE)); } @Skip default MemorySegment mapNamedBuffer(int buffer, int access, long bufferSize) { try { final MemorySegment segment = ((MemorySegment) glMapNamedBuffer().invokeExact(buffer, access)).reinterpret(bufferSize); - return access == READ_ONLY ? segment.asReadOnly() : segment; + return access == GL15C.READ_ONLY ? segment.asReadOnly() : segment; } catch (Throwable e) { throw new RuntimeException(e); } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL46C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL46C.java index bfcc5fb0..e17d06ab 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL46C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL46C.java @@ -17,6 +17,7 @@ package overrungl.opengl; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Marshal; import overrun.marshal.MemoryStack; import overrun.marshal.gen.Entrypoint; @@ -44,7 +45,7 @@ * @author squid233 * @since 0.1.0 */ -public sealed interface GL46C extends GL45C permits GL { +public interface GL46C extends DirectAccess { int SHADER_BINARY_FORMAT_SPIR_V = 0x9551; int SPIR_V_BINARY = 0x9552; int PARAMETER_BUFFER = 0x80EE; diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java index b5528570..99a39641 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * The OpenGL debug message callback. @@ -32,7 +34,7 @@ public interface GLDebugProc extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)); /** * debug callback @@ -47,7 +49,6 @@ public interface GLDebugProc extends Upcall { */ void invoke(int source, int type, int id, int severity, String message, MemorySegment userParam); - @Stub default void ninvoke(int source, int type, int id, int severity, int length, MemorySegment message, MemorySegment userParam) { invoke(source, type, id, severity, message.reinterpret(length + 1).getString(0), userParam); } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLegacy.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLegacy.java index 930e347a..07091f5e 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLegacy.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLegacy.java @@ -16,11 +16,13 @@ package overrungl.opengl; +import overrun.marshal.DirectAccess; + /** - * The latest OpenGL functions, with legacy. + * The latest OpenGL functions, with legacy ones. * * @author squid233 * @since 0.1.0 */ -public non-sealed interface GLLegacy extends GL, GL10, GL11, GL12, GL13, GL14, GL15, GL20, GL21, GL30 { +public interface GLLegacy extends DirectAccess, GL, GL10, GL11, GL12, GL13, GL14, GL15, GL20, GL21, GL30 { } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java index b37146aa..0dce2c03 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java @@ -28,7 +28,7 @@ * {@snippet lang = java: * // loads OpenGL forward-compatible profile * import java.util.Objects; - * Objects.requireNonNull(GLLoader.load(glfw::getProcAddress), "Failed to load OpenGL"); + * Objects.requireNonNull(GLLoader.load(GLLoader.loadFlags(glfw::getProcAddress)), "Failed to load OpenGL"); * } * * @author squid233 diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java index 25cf0455..76b8d5d7 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java @@ -18,13 +18,15 @@ import org.jetbrains.annotations.Nullable; import overrun.marshal.Downcall; +import overrun.marshal.DowncallOption; import overrungl.opengl.ext.GLExtension; import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodHandles; import java.util.Map; +import static java.lang.foreign.ValueLayout.*; + /** * This class must be used before any OpenGL function is called. It has the following responsibilities: *
    @@ -45,10 +47,10 @@ */ public final class GLLoader { private static final Map DESCRIPTOR_MAP = Map.of( - "glMapBuffer", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT), - "glMapBufferRange", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG, ValueLayout.JAVA_INT), - "glMapNamedBuffer", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT), - "glMapNamedBufferRange", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG, ValueLayout.JAVA_INT) + "glMapBuffer", FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_INT), + "glMapBufferRange", FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_INT), + "glMapNamedBuffer", FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_INT), + "glMapNamedBufferRange", FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_INT) ); private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); @@ -70,7 +72,7 @@ public static GLFlags loadFlags(GLLoadFunc load) { */ @Nullable public static GL load(GLFlags flags) { - return flags.GL10 ? Downcall.load(LOOKUP, GL.class, flags.load.lookup(), DESCRIPTOR_MAP) : null; + return flags.GL10 ? loadContext(flags, GL.class) : null; } /** @@ -81,7 +83,7 @@ public static GL load(GLFlags flags) { */ @Nullable public static GLLegacy loadLegacy(GLFlags flags) { - return flags.GL10 ? Downcall.load(LOOKUP, GLLegacy.class, flags.load.lookup(), DESCRIPTOR_MAP) : null; + return flags.GL10 ? loadContext(flags, GLLegacy.class) : null; } /** @@ -92,6 +94,21 @@ public static GLLegacy loadLegacy(GLFlags flags) { */ @Nullable public static GLExtension loadExtension(GLFlags flags) { - return flags.foundExtension ? Downcall.load(LOOKUP, GLExtension.class, flags.load.lookup(), DESCRIPTOR_MAP) : null; + return flags.foundExtension ? loadContext(flags, GLExtension.class) : null; + } + + /** + * Loads OpenGL context with the given flags. + * + * @param flags the OpenGL flags + * @param targetClass the target class + * @param the type of the instance + * @return an instance that wraps OpenGL context + */ + public static T loadContext(GLFlags flags, Class targetClass) { + return Downcall.load(LOOKUP, + flags.load.lookup(), + DowncallOption.targetClass(targetClass), + DowncallOption.descriptors(DESCRIPTOR_MAP)); } } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLUtil.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLUtil.java index 61ec7a9b..0c5ca2b2 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLUtil.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLUtil.java @@ -18,7 +18,8 @@ import org.jetbrains.annotations.Nullable; import overrungl.OverrunGL; -import overrungl.opengl.ext.GLExtension; +import overrungl.opengl.ext.amd.GLAMDDebugOutput; +import overrungl.opengl.ext.arb.GLARBDebugOutput; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; @@ -48,14 +49,21 @@ private GLUtil() { * The callback function is returned as a {@link Arena}, that should be reset to NULL and * {@link Arena#close() closed} when no longer needed, which is often after destroying GL context. * - * @param gl the OpenGL context. - * @param flags the OpenGL flags. - * @param ext the OpenGL extension context, which is supplied when OpenGL debug function is not found in core. + * @param gl the OpenGL context. + * @param flags the OpenGL flags. + * @param fallbackARB the GLARBDebugOutput context, which is supplied when OpenGL debug function is not found in core. + * @param fallbackAMD the GLAMDDebugOutput context, which is supplied when OpenGL debug function is not found in core. * @return the arena. */ @Nullable - public static Arena setupDebugMessageCallback(GL43C gl, GLFlags flags, Supplier ext) { - return setupDebugMessageCallback(gl, flags, ext, OverrunGL.apiLogger()); + public static + Arena setupDebugMessageCallback( + T gl, + GLFlags flags, + Supplier fallbackARB, + Supplier fallbackAMD + ) { + return setupDebugMessageCallback(gl, flags, fallbackARB, fallbackAMD, OverrunGL.apiLogger()); } /** @@ -65,14 +73,22 @@ public static Arena setupDebugMessageCallback(GL43C gl, GLFlags flags, Supplier< * The callback function is returned as a {@link Arena}, that should be reset to NULL and * {@link Arena#close() closed} when no longer needed, which is often after destroying GL context. * - * @param gl the OpenGL context. - * @param flags the OpenGL flags. - * @param ext the OpenGL extension context, which is supplied when OpenGL debug function is not found in core. - * @param logger the output logger. + * @param gl the OpenGL context. + * @param flags the OpenGL flags. + * @param fallbackARB the GLARBDebugOutput context, which is supplied when OpenGL debug function is not found in core. + * @param fallbackAMD the GLAMDDebugOutput context, which is supplied when OpenGL debug function is not found in core. + * @param logger the output logger. * @return the arena. */ @Nullable - public static Arena setupDebugMessageCallback(GL43C gl, GLFlags flags, Supplier ext, Consumer logger) { + public static + Arena setupDebugMessageCallback( + T gl, + GLFlags flags, + Supplier fallbackARB, + Supplier fallbackAMD, + Consumer logger + ) { if (flags.GL43 || flags.GL_KHR_debug) { if (flags.GL43) { apiLog("[GL] Using OpenGL 4.3 for error logging."); @@ -106,7 +122,7 @@ public static Arena setupDebugMessageCallback(GL43C gl, GLFlags flags, Supplier< if (flags.GL_ARB_debug_output) { apiLog("[GL] Using ARB_debug_output for error logging."); var arena = Arena.ofConfined(); - ext.get().glDebugMessageCallbackARB(arena, (source, type, id, severity, message, _) -> { + fallbackARB.get().glDebugMessageCallbackARB(arena, (source, type, id, severity, message, _) -> { var sb = new StringBuilder(768); sb.append("[OverrunGL] ARB_debug_output message\n"); printDetail(sb, "ID", STR."0x\{Integer.toHexString(id).toUpperCase(Locale.ROOT)}"); @@ -126,7 +142,7 @@ public static Arena setupDebugMessageCallback(GL43C gl, GLFlags flags, Supplier< if (flags.GL_AMD_debug_output) { apiLog("[GL] Using AMD_debug_output for error logging."); var arena = Arena.ofConfined(); - ext.get().glDebugMessageCallbackAMD(arena, (id, category, severity, message, _) -> { + fallbackAMD.get().glDebugMessageCallbackAMD(arena, (id, category, severity, message, _) -> { var sb = new StringBuilder(768); sb.append("[OverrunGL] AMD_debug_output message\n"); printDetail(sb, "ID", STR."0x\{Integer.toHexString(id).toUpperCase(Locale.ROOT)}"); diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java index 9d21bf70..40c9b4d5 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * The OpenGL debug message callback. @@ -32,7 +34,7 @@ public interface GLDebugProcAMD extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS)); /** * debug callback @@ -46,7 +48,6 @@ public interface GLDebugProcAMD extends Upcall { */ void invoke(int id, int category, int severity, String message, MemorySegment userParam); - @Stub default void ninvoke(int id, int category, int severity, int length, MemorySegment message, MemorySegment userParam) { invoke(id, category, severity, message.reinterpret(length + 1).getString(0), userParam); } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java index 07030ec9..8fe90948 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java @@ -19,6 +19,7 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; /** @@ -32,9 +33,8 @@ public interface GLVulkanProcNV extends Upcall { /** * The type. */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid()); - @Stub void invoke(); @Override @@ -42,14 +42,11 @@ default MemorySegment stub(Arena arena) { return TYPE.of(arena, this); } - @Wrapper - static GLVulkanProcNV wrap(Arena arena, MemorySegment stub) { - return TYPE.wrap(stub, handle -> () -> { - try { - handle.invokeExact(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - }); + static void invoke(MemorySegment stub) { + try { + TYPE.downcallTarget().invokeExact(stub); + } catch (Throwable e) { + throw new RuntimeException(e); + } } } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java b/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java index 8f10297b..676949e5 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/Handles.java @@ -20,7 +20,9 @@ import overrungl.OverrunGL; import overrungl.internal.RuntimeHelper; +import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; +import java.lang.foreign.ValueLayout; import java.util.function.Supplier; /** @@ -31,11 +33,22 @@ */ final class Handles { static final SymbolLookup lookup; + static final MemorySegment stbi_write_tga_with_rle, + stbi_write_png_compression_level, + stbi_write_force_png_filter; static { final Supplier lib = () -> RuntimeHelper.load("stb", "stb", OverrunGL.STB_VERSION); final var function = Configurations.STB_SYMBOL_LOOKUP.get(); lookup = function != null ? function.apply(lib) : lib.get(); + + stbi_write_tga_with_rle = findIntOrThrow("stbi_write_tga_with_rle"); + stbi_write_png_compression_level = findIntOrThrow("stbi_write_png_compression_level"); + stbi_write_force_png_filter = findIntOrThrow("stbi_write_force_png_filter"); + } + + private static MemorySegment findIntOrThrow(String name) { + return lookup.find(name).orElseThrow().reinterpret(ValueLayout.JAVA_INT.byteSize()); } private Handles() { diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java index b22c8873..6a28f1df 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBEasyFont.java @@ -17,6 +17,7 @@ package overrungl.stb; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Entrypoint; import overrun.marshal.gen.Sized; @@ -55,7 +56,7 @@ * @author squid233 * @since 0.1.0 */ -interface STBEasyFont { +public interface STBEasyFont extends DirectAccess { /** * The instance of STBEasyFont. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java index e7eac67b..90c78fc2 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java @@ -47,15 +47,15 @@ public final class STBIIoCallbacks extends Struct { /** * the read callback */ - public final StructHandle.Upcall read = StructHandle.ofUpcall(this, "read", Read::wrap); + public static final StructHandle.Upcall read = StructHandle.ofUpcall(LAYOUT, "read", Read::wrap); /** * the skip callback */ - public final StructHandle.Upcall skip = StructHandle.ofUpcall(this, "skip", Skip::wrap); + public static final StructHandle.Upcall skip = StructHandle.ofUpcall(LAYOUT, "skip", Skip::wrap); /** * the eof callback */ - public final StructHandle.Upcall eof = StructHandle.ofUpcall(this, "eof", Eof::wrap); + public static final StructHandle.Upcall eof = StructHandle.ofUpcall(LAYOUT, "eof", Eof::wrap); /** * Creates a struct with the given layout. @@ -106,7 +106,7 @@ public interface Read extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * Fill {@code data} with {@code size} bytes. @@ -125,7 +125,6 @@ public interface Read extends Upcall { * @param size byte size to fill * @return number of bytes actually read */ - @Stub default int ninvoke(MemorySegment user, MemorySegment data, int size) { return invoke(user, data.reinterpret(size)); } @@ -135,15 +134,16 @@ default MemorySegment stub(Arena arena) { return TYPE.of(arena, this); } - @Wrapper - static Read wrap(Arena arena, MemorySegment stub) { - return TYPE.wrap(stub, handle -> (user, data) -> { - try { - return (int) handle.invokeExact(user, data, Math.toIntExact(data.byteSize())); - } catch (Throwable e) { - throw new RuntimeException(e); - } - }); + static int invoke(MemorySegment stub, MemorySegment user, MemorySegment data, int size) { + try { + return (int) TYPE.downcallTarget().invokeExact(stub, user, data, size); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + static Read wrap(MemorySegment stub) { + return (user, data) -> invoke(stub, user, data, Math.toIntExact(data.byteSize())); } } @@ -158,7 +158,7 @@ public interface Skip extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); /** * Skip the next {@code n} bytes, or “unget” the last {@code -n} bytes if negative @@ -166,7 +166,6 @@ public interface Skip extends Upcall { * @param user userdata * @param n byte size to skip */ - @Stub void invoke(MemorySegment user, int n); @@ -175,15 +174,16 @@ default MemorySegment stub(Arena arena) { return TYPE.of(arena, this); } - @Wrapper - static Skip wrap(Arena arena, MemorySegment stub) { - return TYPE.wrap(stub, handle -> (user, n) -> { - try { - handle.invokeExact(user, n); - } catch (Throwable e) { - throw new RuntimeException(e); - } - }); + static void invoke(MemorySegment stub, MemorySegment user, int n) { + try { + TYPE.downcallTarget().invokeExact(stub, user, n); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + static Skip wrap(MemorySegment stub) { + return (user, n) -> invoke(stub, user, n); } } @@ -198,14 +198,13 @@ public interface Eof extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS)); /** * {@return nonzero if we are at end of file/data} * * @param user userdata */ - @Stub int invoke(MemorySegment user); @Override @@ -213,15 +212,16 @@ default MemorySegment stub(Arena arena) { return TYPE.of(arena, this); } - @Wrapper - static Eof wrap(Arena arena, MemorySegment segment) { - return TYPE.wrap(segment, handle -> user -> { - try { - return (int) handle.invokeExact(user); - } catch (Throwable e) { - throw new RuntimeException(e); - } - }); + static int invoke(MemorySegment stub, MemorySegment user) { + try { + return (int) TYPE.downcallTarget().invokeExact(stub, user); + } catch (Throwable e) { + throw new RuntimeException(e); + } + } + + static Eof wrap(MemorySegment stub) { + return user -> invoke(stub, user); } } } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRInputCallback.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRInputCallback.java index 1871fd31..58acf4cb 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRInputCallback.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRInputCallback.java @@ -20,7 +20,9 @@ import overrungl.NativeType; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * INPUT CALLBACK: this callback is used for input scanlines @@ -67,10 +69,9 @@ public interface STBIRInputCallback extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS)); @NativeType("void const *") - @Stub MemorySegment invoke(@NativeType("void *") MemorySegment optional_output, @NativeType("void const *") MemorySegment input_ptr, int num_pixels, int x, int y, @NativeType("void *") MemorySegment context); @Override diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRKernelCallback.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRKernelCallback.java index 242c7f82..670e8af1 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRKernelCallback.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRKernelCallback.java @@ -20,7 +20,9 @@ import overrungl.NativeType; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * callbacks for user installed filters @@ -33,10 +35,9 @@ public interface STBIRKernelCallback extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.of(ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT, ValueLayout.ADDRESS)); // centered at zero - @Stub float invoke(float x, float scale, @NativeType("void *") MemorySegment user_data); @Override diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIROutputCallback.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIROutputCallback.java index 95b86874..6a7199b2 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIROutputCallback.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIROutputCallback.java @@ -20,7 +20,9 @@ import overrungl.NativeType; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * OUTPUT CALLBACK: this callback is used for output scanlines @@ -44,9 +46,8 @@ public interface STBIROutputCallback extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT, ValueLayout.ADDRESS)); - @Stub void invoke(@NativeType("void const *") MemorySegment output_ptr, int num_pixels, int y, @NativeType("void *") MemorySegment context); @Override diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRSupportCallback.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRSupportCallback.java index 97c3fd8d..7c172f60 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRSupportCallback.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRSupportCallback.java @@ -20,7 +20,9 @@ import overrungl.NativeType; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * callbacks for user installed filters @@ -33,10 +35,9 @@ public interface STBIRSupportCallback extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("invoke", FunctionDescriptor.of(ValueLayout.JAVA_FLOAT, ValueLayout.JAVA_FLOAT, ValueLayout.ADDRESS)); // centered at zero - @Stub float invoke(float scale, @NativeType("void *") MemorySegment user_data); @Override diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIWriteFunc.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIWriteFunc.java index 7590654c..0f844ef2 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIWriteFunc.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIWriteFunc.java @@ -19,7 +19,9 @@ import overrun.marshal.Upcall; import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; /** * The write-callback. @@ -32,11 +34,10 @@ public interface STBIWriteFunc extends Upcall { /** * the type */ - Type TYPE = Upcall.type(); + Type TYPE = Upcall.type("ninvoke", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT)); void invoke(MemorySegment context, MemorySegment data); - @Stub default void ninvoke(MemorySegment context, MemorySegment data, int size) { invoke(context, data.reinterpret(size)); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java index d4dd52b9..57a89b77 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java @@ -17,6 +17,7 @@ package overrungl.stb; import org.jetbrains.annotations.Nullable; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.MemoryStack; import overrun.marshal.Unmarshal; @@ -33,7 +34,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBImage { +public interface STBImage extends DirectAccess { /** * The instance of STBImage. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize2.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize2.java index 97ea9dc6..7ab45d98 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize2.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageResize2.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Entrypoint; import overrungl.NativeType; @@ -29,7 +30,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBImageResize2 { +public interface STBImageResize2 extends DirectAccess { /** * The instance of STBImageResize2. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java index 22ccf7f2..251c1263 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImageWrite.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Convert; import overrun.marshal.gen.Entrypoint; @@ -25,6 +26,7 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; +import java.lang.foreign.ValueLayout; import java.lang.invoke.MethodHandles; /** @@ -33,30 +35,41 @@ * @author squid233 * @since 0.1.0 */ -public interface STBImageWrite { +public interface STBImageWrite extends DirectAccess { /** * The instance of STBImageWrite. */ STBImageWrite INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup); - @Convert(Type.INT) - @Entrypoint("stbi_get_write_tga_with_rle") - boolean getWriteTgaWithRle(); + @Skip + default boolean getWriteTgaWithRle() { + return Handles.stbi_write_tga_with_rle.get(ValueLayout.JAVA_INT, 0L) != 0; + } - @Entrypoint("stbi_get_write_png_compression_level") - int getWritePngCompressionLevel(); + @Skip + default void setWriteTgaWithRle(boolean rle) { + Handles.stbi_write_tga_with_rle.set(ValueLayout.JAVA_INT, 0L, rle ? 1 : 0); + } - @Entrypoint("stbi_get_write_force_png_filter") - int getWriteForcePngFilter(); + @Skip + default int getWritePngCompressionLevel() { + return Handles.stbi_write_png_compression_level.get(ValueLayout.JAVA_INT, 0L); + } - @Entrypoint("stbi_set_write_tga_with_rle") - void setWriteTgaWithRle(@Convert(Type.INT) boolean rle); + @Skip + default void setWritePngCompressionLevel(int level) { + Handles.stbi_write_png_compression_level.set(ValueLayout.JAVA_INT, 0L, level); + } - @Entrypoint("stbi_set_write_png_compression_level") - void setWritePngCompressionLevel(int level); + @Skip + default int getWriteForcePngFilter() { + return Handles.stbi_write_force_png_filter.get(ValueLayout.JAVA_INT, 0L); + } - @Entrypoint("stbi_set_write_force_png_filter") - void setWriteForcePngFilter(int filter); + @Skip + default void setWriteForcePngFilter(int filter) { + Handles.stbi_write_force_png_filter.set(ValueLayout.JAVA_INT, 0L, filter); + } @Convert(Type.INT) @Entrypoint("stbi_write_png") diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java index 170d7469..b0d87840 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBPerlin.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Entrypoint; @@ -27,7 +28,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBPerlin { +public interface STBPerlin extends DirectAccess { /** * The instance of STBPerlin. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java index 035edd10..dc15235c 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java @@ -42,21 +42,21 @@ public final class STBRPRect extends Struct { /** * reserved for your use */ - public final StructHandle.Int id = StructHandle.ofInt(this, "id"); + public static final StructHandle.Int id = StructHandle.ofInt(LAYOUT, "id"); /** * input */ - public final StructHandle.Int w = StructHandle.ofInt(this, "w"), - h = StructHandle.ofInt(this, "h"); + public static final StructHandle.Int w = StructHandle.ofInt(LAYOUT, "w"), + h = StructHandle.ofInt(LAYOUT, "h"); /** * output */ - public final StructHandle.Int x = StructHandle.ofInt(this, "x"), - y = StructHandle.ofInt(this, "y"), + public static final StructHandle.Int x = StructHandle.ofInt(LAYOUT, "x"), + y = StructHandle.ofInt(LAYOUT, "y"), /** * non-zero if valid packing */ - wasPacked = StructHandle.ofInt(this, "was_packed"); + wasPacked = StructHandle.ofInt(LAYOUT, "was_packed"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRectPack.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRectPack.java index 9bad8938..4367a587 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRectPack.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRectPack.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Entrypoint; @@ -30,7 +31,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBRectPack { +public interface STBRectPack extends DirectAccess { /** * The instance of STBRectPack. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java index 39b9cc69..cba629bb 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java @@ -56,17 +56,17 @@ public final class STBTTAlignedQuad extends Struct { /** * top-left */ - public final StructHandle.Float x0 = StructHandle.ofFloat(this, "x0"), - y0 = StructHandle.ofFloat(this, "y0"), - s0 = StructHandle.ofFloat(this, "s0"), - t0 = StructHandle.ofFloat(this, "t0"); + public static final StructHandle.Float x0 = StructHandle.ofFloat(LAYOUT, "x0"), + y0 = StructHandle.ofFloat(LAYOUT, "y0"), + s0 = StructHandle.ofFloat(LAYOUT, "s0"), + t0 = StructHandle.ofFloat(LAYOUT, "t0"); /** * bottom-right */ - public final StructHandle.Float x1 = StructHandle.ofFloat(this, "x1"), - y1 = StructHandle.ofFloat(this, "y1"), - s1 = StructHandle.ofFloat(this, "s1"), - t1 = StructHandle.ofFloat(this, "t1"); + public static final StructHandle.Float x1 = StructHandle.ofFloat(LAYOUT, "x1"), + y1 = StructHandle.ofFloat(LAYOUT, "y1"), + s1 = StructHandle.ofFloat(LAYOUT, "s1"), + t1 = StructHandle.ofFloat(LAYOUT, "t1"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java index 157d5c5b..3f9df4ed 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java @@ -55,22 +55,22 @@ public final class STBTTBakedChar extends Struct { /** * coordinates of bbox in bitmap */ - public final StructHandle.Short x0 = StructHandle.ofShort(this, "x0"), - y0 = StructHandle.ofShort(this, "y0"), - x1 = StructHandle.ofShort(this, "x1"), - y1 = StructHandle.ofShort(this, "y1"); + public static final StructHandle.Short x0 = StructHandle.ofShort(LAYOUT, "x0"), + y0 = StructHandle.ofShort(LAYOUT, "y0"), + x1 = StructHandle.ofShort(LAYOUT, "x1"), + y1 = StructHandle.ofShort(LAYOUT, "y1"); /** * xoff */ - public final StructHandle.Float xoff = StructHandle.ofFloat(this, "xoff"); + public static final StructHandle.Float xoff = StructHandle.ofFloat(LAYOUT, "xoff"); /** * yoff */ - public final StructHandle.Float yoff = StructHandle.ofFloat(this, "yoff"); + public static final StructHandle.Float yoff = StructHandle.ofFloat(LAYOUT, "yoff"); /** * xadvance */ - public final StructHandle.Float xadvance = StructHandle.ofFloat(this, "xadvance"); + public static final StructHandle.Float xadvance = StructHandle.ofFloat(LAYOUT, "xadvance"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java index f70499c0..b9af8e27 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java @@ -47,15 +47,15 @@ public final class STBTTKerningEntry extends Struct { /** * use stbtt_FindGlyphIndex */ - public final StructHandle.Int glyph1 = StructHandle.ofInt(this, "glyph1"); + public static final StructHandle.Int glyph1 = StructHandle.ofInt(LAYOUT, "glyph1"); /** * glyph2 */ - public final StructHandle.Int glyph2 = StructHandle.ofInt(this, "glyph2"); + public static final StructHandle.Int glyph2 = StructHandle.ofInt(LAYOUT, "glyph2"); /** * advance */ - public final StructHandle.Int advance = StructHandle.ofInt(this, "advance"); + public static final StructHandle.Int advance = StructHandle.ofInt(LAYOUT, "advance"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java index 30873563..f65299cb 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java @@ -64,29 +64,29 @@ public final class STBTTPackRange extends Struct { /** * font_size */ - public final StructHandle.Float fontSize = StructHandle.ofFloat(this, "font_size"); + public static final StructHandle.Float fontSize = StructHandle.ofFloat(LAYOUT, "font_size"); /** * if non-zero, then the chars are continuous, and this is the first codepoint */ - public final StructHandle.Int firstUnicodeCodepointInRange = StructHandle.ofInt(this, "first_unicode_codepoint_in_range"); + public static final StructHandle.Int firstUnicodeCodepointInRange = StructHandle.ofInt(LAYOUT, "first_unicode_codepoint_in_range"); /** * if non-zero, then this is an array of unicode codepoints */ - public final StructHandle.Array arrayOfUnicodeCodepoints = StructHandle.ofArray(this, "array_of_unicode_codepoints", Marshal::marshal, Unmarshal::unmarshalAsIntArray); + public static final StructHandle.Array arrayOfUnicodeCodepoints = StructHandle.ofArray(LAYOUT, "array_of_unicode_codepoints", Marshal::marshal, Unmarshal::unmarshalAsIntArray); /** * num_chars */ - public final StructHandle.Int numChars = StructHandle.ofInt(this, "num_chars"); + public static final StructHandle.Int numChars = StructHandle.ofInt(LAYOUT, "num_chars"); /** * output */ - public final StructHandle.Array chardataForRange = StructHandle.ofArray(this, "chardata_for_range", Marshal::marshal, + public static final StructHandle.Array chardataForRange = StructHandle.ofArray(LAYOUT, "chardata_for_range", Marshal::marshal, segment -> Unmarshal.unmarshal(ADDRESS, segment, STBTTPackedChar[]::new, s -> new STBTTPackedChar(s.get(ADDRESS.withTargetLayout(STBTTPackedChar.LAYOUT), 0L), 1L))); /** * don't set these, they're used internally */ - public final StructHandleView.Byte hOversample = StructHandle.ofByte(this, "h_oversample"), - vOversample = StructHandle.ofByte(this, "v_oversample"); + public static final StructHandleView.Byte hOversample = StructHandle.ofByte(LAYOUT, "h_oversample"), + vOversample = StructHandle.ofByte(LAYOUT, "v_oversample"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java index a5b62e91..270285da 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java @@ -58,30 +58,30 @@ public final class STBTTPackedChar extends Struct { /** * coordinates of bbox in bitmap */ - public final StructHandle.Short x0 = StructHandle.ofShort(this, "x0"), - y0 = StructHandle.ofShort(this, "y0"), - x1 = StructHandle.ofShort(this, "x1"), - y1 = StructHandle.ofShort(this, "y1"); + public static final StructHandle.Short x0 = StructHandle.ofShort(LAYOUT, "x0"), + y0 = StructHandle.ofShort(LAYOUT, "y0"), + x1 = StructHandle.ofShort(LAYOUT, "x1"), + y1 = StructHandle.ofShort(LAYOUT, "y1"); /** * xoff */ - public final StructHandle.Float xoff = StructHandle.ofFloat(this, "xoff"); + public static final StructHandle.Float xoff = StructHandle.ofFloat(LAYOUT, "xoff"); /** * yoff */ - public final StructHandle.Float yoff = StructHandle.ofFloat(this, "yoff"); + public static final StructHandle.Float yoff = StructHandle.ofFloat(LAYOUT, "yoff"); /** * xadvance */ - public final StructHandle.Float xadvance = StructHandle.ofFloat(this, "xadvance"); + public static final StructHandle.Float xadvance = StructHandle.ofFloat(LAYOUT, "xadvance"); /** * xoff2 */ - public final StructHandle.Float xoff2 = StructHandle.ofFloat(this, "xoff2"); + public static final StructHandle.Float xoff2 = StructHandle.ofFloat(LAYOUT, "xoff2"); /** * yoff2 */ - public final StructHandle.Float yoff2 = StructHandle.ofFloat(this, "yoff2"); + public static final StructHandle.Float yoff2 = StructHandle.ofFloat(LAYOUT, "yoff2"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java index ad2c4c67..49ad67bf 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java @@ -58,35 +58,35 @@ public final class STBTTVertex extends Struct { /** * x */ - public final StructHandle.Short x = StructHandle.ofShort(this, "x"); + public static final StructHandle.Short x = StructHandle.ofShort(LAYOUT, "x"); /** * y */ - public final StructHandle.Short y = StructHandle.ofShort(this, "y"); + public static final StructHandle.Short y = StructHandle.ofShort(LAYOUT, "y"); /** * cx */ - public final StructHandle.Short cx = StructHandle.ofShort(this, "cx"); + public static final StructHandle.Short cx = StructHandle.ofShort(LAYOUT, "cx"); /** * cy */ - public final StructHandle.Short cy = StructHandle.ofShort(this, "cy"); + public static final StructHandle.Short cy = StructHandle.ofShort(LAYOUT, "cy"); /** * cx1 */ - public final StructHandle.Short cx1 = StructHandle.ofShort(this, "cx1"); + public static final StructHandle.Short cx1 = StructHandle.ofShort(LAYOUT, "cx1"); /** * cy1 */ - public final StructHandle.Short cy1 = StructHandle.ofShort(this, "cy1"); + public static final StructHandle.Short cy1 = StructHandle.ofShort(LAYOUT, "cy1"); /** * type */ - public final StructHandle.Byte type = StructHandle.ofByte(this, "type"); + public static final StructHandle.Byte type = StructHandle.ofByte(LAYOUT, "type"); /** * padding */ - public final StructHandle.Byte padding = StructHandle.ofByte(this, "padding"); + public static final StructHandle.Byte padding = StructHandle.ofByte(LAYOUT, "padding"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java index 79477e59..a37ead16 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Convert; import overrun.marshal.gen.Entrypoint; @@ -309,7 +310,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBTrueType { +public interface STBTrueType extends DirectAccess { /** * The instance of STBTrueType. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbis.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbis.java index 898a3e08..450d1acb 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbis.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbis.java @@ -16,6 +16,7 @@ package overrungl.stb; +import overrun.marshal.DirectAccess; import overrun.marshal.Downcall; import overrun.marshal.gen.Entrypoint; import overrun.marshal.struct.ByValue; @@ -52,7 +53,7 @@ * @author squid233 * @since 0.1.0 */ -public interface STBVorbis { +public interface STBVorbis extends DirectAccess { /** * The instance of STBVorbis. */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java index f3a132cf..b3c71d3c 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java @@ -69,11 +69,11 @@ public final class STBVorbisAlloc extends Struct { /** * alloc_buffer */ - public final StructHandle.Address allocBuffer = StructHandle.ofAddress(this, "alloc_buffer"); + public static final StructHandle.Address allocBuffer = StructHandle.ofAddress(LAYOUT, "alloc_buffer"); /** * alloc_buffer_length_in_bytes */ - public final StructHandle.Int allocBufferLengthInBytes = StructHandle.ofInt(this, "alloc_buffer_length_in_bytes"); + public static final StructHandle.Int allocBufferLengthInBytes = StructHandle.ofInt(LAYOUT, "alloc_buffer_length_in_bytes"); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java index ea364879..91e430a3 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java @@ -55,15 +55,15 @@ public final class STBVorbisComment extends Struct { /** * vendor */ - public final StructHandle.Array vendor = StructHandle.ofArray(this, "vendor", Marshal::marshal, Unmarshal::unmarshalAsByteArray); + public static final StructHandle.Array vendor = StructHandle.ofArray(LAYOUT, "vendor", Marshal::marshal, Unmarshal::unmarshalAsByteArray); /** * comment_list_length */ - public final StructHandle.Int commentListLength = StructHandle.ofInt(this, "comment_list_length"); + public static final StructHandle.Int commentListLength = StructHandle.ofInt(LAYOUT, "comment_list_length"); /** * comment_list */ - public final StructHandle.Array commentList = StructHandle.ofArray(this, "comment_list", Marshal::marshal, Unmarshal::unmarshalAsStringArray); + public static final StructHandle.Array commentList = StructHandle.ofArray(LAYOUT, "comment_list", Marshal::marshal, Unmarshal::unmarshalAsStringArray); /** * Creates a struct with the given layout. diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java index 32778b44..90630566 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java @@ -60,27 +60,27 @@ public final class STBVorbisInfo extends Struct { /** * sample_rate */ - public final StructHandle.Int sampleRate = StructHandle.ofInt(this, "sample_rate"); + public static final StructHandle.Int sampleRate = StructHandle.ofInt(LAYOUT, "sample_rate"); /** * channels */ - public final StructHandle.Int channels = StructHandle.ofInt(this, "channels"); + public static final StructHandle.Int channels = StructHandle.ofInt(LAYOUT, "channels"); /** * setup_memory_required */ - public final StructHandle.Int setupMemoryRequired = StructHandle.ofInt(this, "setup_memory_required"); + public static final StructHandle.Int setupMemoryRequired = StructHandle.ofInt(LAYOUT, "setup_memory_required"); /** * setup_temp_memory_required */ - public final StructHandle.Int setupTempMemoryRequired = StructHandle.ofInt(this, "setup_temp_memory_required"); + public static final StructHandle.Int setupTempMemoryRequired = StructHandle.ofInt(LAYOUT, "setup_temp_memory_required"); /** * temp_memory_required */ - public final StructHandle.Int tempMemoryRequired = StructHandle.ofInt(this, "temp_memory_required"); + public static final StructHandle.Int tempMemoryRequired = StructHandle.ofInt(LAYOUT, "temp_memory_required"); /** * max_frame_size */ - public final StructHandle.Int maxFrameSize = StructHandle.ofInt(this, "max_frame_size"); + public static final StructHandle.Int maxFrameSize = StructHandle.ofInt(LAYOUT, "max_frame_size"); /** * Creates a struct with the given layout. diff --git a/modules/samples/build.gradle.kts b/modules/samples/build.gradle.kts index 251eab64..7f91bfd1 100644 --- a/modules/samples/build.gradle.kts +++ b/modules/samples/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("me.champeau.jmh") version "0.7.2" +} + val projModules: String by project dependencies { @@ -12,6 +16,6 @@ dependencies { implementation(project(":$it")) } testImplementation("io.github.over-run:timer:0.3.0") - jmh("org.openjdk.jmh:jmh-core:1.36") - jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.36") + jmh("org.openjdk.jmh:jmh-core:1.37") + jmhAnnotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.37") } diff --git a/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java b/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java index d518eff7..09488302 100644 --- a/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java +++ b/modules/samples/src/jmh/java/overrungl/demo/mem/MemoryUtilTest.java @@ -16,10 +16,6 @@ package overrungl.demo.mem; -import java.lang.foreign.Arena; -import java.lang.foreign.MemorySegment; -import java.util.concurrent.TimeUnit; - import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.results.format.ResultFormatType; import org.openjdk.jmh.runner.Runner; @@ -27,6 +23,10 @@ import org.openjdk.jmh.runner.options.OptionsBuilder; import overrungl.util.MemoryUtil; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.util.concurrent.TimeUnit; + /** * Tests memory util * 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 191fb2a2..fc19c51e 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -77,9 +77,9 @@ private void init(Arena arena) { px, py, pc, STBImage.RGB_ALPHA ); 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); + GLFWImage.width.set(image, px.get(JAVA_INT, 0)); + GLFWImage.height.set(image, py.get(JAVA_INT, 0)); + GLFWImage.pixels.set(image, data); glfw.setWindowIcon(window, image); stbImage.free(data); } catch (IOException e) { 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 8bf74611..85185d94 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java @@ -27,6 +27,8 @@ import overrungl.opengl.GLFlags; import overrungl.opengl.GLLoader; import overrungl.opengl.GLUtil; +import overrungl.opengl.ext.amd.GLAMDDebugOutput; +import overrungl.opengl.ext.arb.GLARBDebugOutput; import java.lang.foreign.Arena; import java.lang.foreign.MemoryLayout; @@ -113,7 +115,10 @@ private void load(Arena arena) { final GLFlags flags = GLLoader.loadFlags(glfw::getProcAddress); gl = Objects.requireNonNull(GLLoader.load(flags), "Failed to load OpenGL"); - debugProc = GLUtil.setupDebugMessageCallback(gl, flags, () -> GLLoader.loadExtension(flags)); + debugProc = GLUtil.setupDebugMessageCallback(gl, + flags, + () -> GLLoader.loadContext(flags, GLARBDebugOutput.class), + () -> GLLoader.loadContext(flags, GLAMDDebugOutput.class)); gl.clearColor(0.4f, 0.6f, 0.9f, 1.0f); program = gl.createProgram(); int vsh = gl.createShader(GL.VERTEX_SHADER);