diff --git a/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt b/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt index 6350f685..797bc1f5 100644 --- a/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt +++ b/buildSrc/src/main/kotlin/myproject.java-conventions.gradle.kt @@ -90,9 +90,9 @@ enum class Artifact( "Single-file public domain libraries for fonts, images, ogg vorbis files and more.", ":stb", "Stb", NativeBinding.STB ), - VULKAN("overrungl-vulkan", "OverrunGL - Vulkan bindings", - "A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.", - ":vulkan", "Vulkan", null), +// VULKAN("overrungl-vulkan", "OverrunGL - Vulkan bindings", +// "A new generation graphics and compute API that provides high-efficiency, cross-platform access to modern GPUs used in a wide variety of devices from PCs and consoles to mobile phones and embedded platforms.", +// ":vulkan", "Vulkan", null), ; fun nativeFileName(platform: NativePlatform): String? { diff --git a/gradle.properties b/gradle.properties index ed4e9901..82a1615b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,5 +19,5 @@ jdkEnablePreview=true #jdkEarlyAccessDoc=jdk22 kotlinTargetJdkVersion=21 -overrunMarshalVersion=0.1.0-alpha.24-jdk22 +overrunMarshalVersion=0.1.0-alpha.26-jdk22 overrunPlatformVersion=1.0.0 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 91a30d24..ac39a8ea 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -1953,7 +1953,7 @@ default MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { return null; } final int count = pCount.get(JAVA_INT, 0); - return new GLFWVidMode(pModes.reinterpret(GLFWVidMode.LAYOUT.scale(0L, count)), count); + return GLFWVidMode.OF.of(pModes.reinterpret(GLFWVidMode.OF.layout().scale(0L, count)), count); } } @@ -1988,10 +1988,10 @@ default MemorySegment setMonitorCallback(@Nullable GLFWMonitorFun callback) { */ @Nullable @Skip - default GLFWVidMode.Value getVideoMode(MemorySegment monitor) { + default GLFWVidMode getVideoMode(MemorySegment monitor) { var pMode = ngetVideoMode(monitor); if (Unmarshal.isNullPointer(pMode)) return null; - return new GLFWVidMode(pMode.reinterpret(GLFWVidMode.LAYOUT.byteSize())).value(); + return GLFWVidMode.OF.of(pMode.reinterpret(GLFWVidMode.OF.layout().byteSize())); } /** diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWAllocator.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWAllocator.java index 4dd1e564..34fdf0ed 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWAllocator.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWAllocator.java @@ -16,10 +16,14 @@ package overrungl.glfw; +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Marshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; +import java.lang.invoke.MethodHandles; /** * Custom heap memory allocator. @@ -31,72 +35,127 @@ * @see GLFW#initAllocator * @since 0.1.0 */ -public final class GLFWAllocator extends Struct { +public interface GLFWAllocator extends Struct { /** - * The layout of this struct. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withName("allocate"), - ValueLayout.ADDRESS.withName("reallocate"), - ValueLayout.ADDRESS.withName("deallocate"), - ValueLayout.ADDRESS.withName("user") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("allocate") + .cAddress("reallocate") + .cAddress("deallocate") + .cAddress("user") + .build() ); + /** - * The memory allocation function. See {@link GLFWAllocateFun} for details about - * allocation function. + * {@return the memory allocation function} + * See {@link GLFWAllocateFun} for details about allocation function. */ - public static final StructHandle.Upcall allocate = StructHandle.ofUpcall(LAYOUT, "allocate", GLFWAllocateFun::wrap); + MemorySegment allocate(); + /** - * The memory reallocation function. See {@link GLFWReallocateFun} for details about - * reallocation function. + * Sets {@link #allocate()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Upcall reallocate = StructHandle.ofUpcall(LAYOUT, "reallocate", GLFWReallocateFun::wrap); + GLFWAllocator allocate(MemorySegment val); + + /** + * {@return the memory reallocation function} + * See {@link GLFWReallocateFun} for details about reallocation function. + */ + MemorySegment reallocate(); + /** - * The memory deallocation function. See {@link GLFWDeallocateFun} for details about - * deallocation function. + * Sets {@link #reallocate()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Upcall deallocate = StructHandle.ofUpcall(LAYOUT, "deallocate", GLFWDeallocateFun::wrap); + GLFWAllocator reallocate(MemorySegment val); + /** - * The user pointer for this custom allocator. This value will be passed to the - * allocator functions. + * {@return the memory deallocation function} + * See {@link GLFWDeallocateFun} for details about deallocation function. */ - public static final StructHandle.Address user = StructHandle.ofAddress(LAYOUT, "user"); + MemorySegment deallocate(); /** - * Creates a struct with the given layout. + * Sets {@link #deallocate()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this */ - public GLFWAllocator(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + GLFWAllocator deallocate(MemorySegment val); + + /** + * {@return the user pointer for this custom allocator} + * This value will be passed to the allocator functions. + */ + MemorySegment user(); + + /** + * Sets {@link #user()}. + * + * @param val the value + * @return this + */ + GLFWAllocator user(MemorySegment val); + + /** + * {@return {@link #allocate()}} + */ + default GLFWAllocateFun javaAllocate() { + return GLFWAllocateFun.wrap(allocate()); } /** - * Allocates a struct with the given layout. + * Sets {@link #allocate()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param arena the arena + * @param val the value + * @return this */ - public GLFWAllocator(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); + default GLFWAllocator javaAllocate(Arena arena, GLFWAllocateFun val) { + return allocate(Marshal.marshal(arena, val)); } /** - * Creates a struct with the given layout. + * {@return {@link #reallocate()}} + */ + default GLFWReallocateFun javaReallocate() { + return GLFWReallocateFun.wrap(reallocate()); + } + + /** + * Sets {@link #reallocate()}. * - * @param segment the segment + * @param arena the arena + * @param val the value + * @return this + */ + default GLFWAllocator javaReallocate(Arena arena, GLFWReallocateFun val) { + return reallocate(Marshal.marshal(arena, val)); + } + + /** + * {@return {@link #deallocate()}} */ - public GLFWAllocator(MemorySegment segment) { - super(segment, LAYOUT); + default GLFWDeallocateFun javaDeallocate() { + return GLFWDeallocateFun.wrap(deallocate()); } /** - * Allocates a struct with the given layout. + * Sets {@link #deallocate()}. * - * @param allocator the allocator + * @param arena the arena + * @param val the value + * @return this */ - public GLFWAllocator(SegmentAllocator allocator) { - super(allocator, LAYOUT); + default GLFWAllocator javaDeallocate(Arena arena, GLFWDeallocateFun val) { + return deallocate(Marshal.marshal(arena, val)); } } 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 44e4f10c..4c4fcdca 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGamepadState.java @@ -16,9 +16,12 @@ package overrungl.glfw; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * This describes the input state of a gamepad. @@ -32,63 +35,35 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFWGamepadState extends Struct { +public interface GLFWGamepadState extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - MemoryLayout.sequenceLayout(15, ValueLayout.JAVA_BYTE).withName("buttons"), - MemoryLayout.paddingLayout(1L), - MemoryLayout.sequenceLayout(6, ValueLayout.JAVA_FLOAT).withName("axes") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cArray("buttons", 15, ValueLayout.JAVA_BYTE) + .cArray("axes", 6, ValueLayout.JAVA_FLOAT) + .build() ); + /** * The states of each gamepad button, * {@link GLFW#PRESS} or {@link GLFW#RELEASE}. - */ - 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 static final StructHandleSizedFloatArray axes = StructHandleSizedFloatArray.of(LAYOUT, "axes"); - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count - */ - public GLFWGamepadState(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count - */ - public GLFWGamepadState(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } - - /** - * Creates a struct with the given layout. * - * @param segment the segment + * @param index the index + * @return the state */ - public GLFWGamepadState(MemorySegment segment) { - super(segment, LAYOUT); - } + byte buttons(long index); /** - * Allocates a struct with the given layout. + * The states of each gamepad axis, + * in the range -1.0 to 1.0 inclusive. * - * @param allocator the allocator + * @param index the index + * @return the state */ - public GLFWGamepadState(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + float axes(long index); /** * Gets the button state at the given index. @@ -96,8 +71,8 @@ public GLFWGamepadState(SegmentAllocator allocator) { * @param index the index * @return the state, {@code PRESS} or {@code RELEASE} */ - public boolean button(int index) { - return buttons.get(this, index) == GLFW.PRESS; + default boolean button(int index) { + return buttons(index) == GLFW.PRESS; } /** @@ -106,7 +81,7 @@ public boolean button(int index) { * @param index the index * @return the state, in the range -1.0 to 1.0 inclusive */ - public float axe(int index) { - return axes.get(this, index); + default float axe(int index) { + return axes(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 ec904d4d..2acc49ab 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWGammaRamp.java @@ -16,14 +16,16 @@ package overrungl.glfw; +import overrun.marshal.LayoutBuilder; import overrun.marshal.Marshal; import overrun.marshal.Unmarshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.SegmentAllocator; +import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandles; /** * This describes the gamma ramp for a monitor. @@ -41,69 +43,129 @@ * @see GLFW#setGammaRamp * @since 0.1.0 */ -public final class GLFWGammaRamp extends Struct { - private static final AddressLayout SHORT_ARRAY = ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, JAVA_SHORT)); +public interface GLFWGammaRamp extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - SHORT_ARRAY.withName("red"), - SHORT_ARRAY.withName("green"), - SHORT_ARRAY.withName("blue"), - JAVA_INT.withName("size") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("red") + .cAddress("green") + .cAddress("blue") + .cInt("size") + .build() ); + /** - * An array of value describing the response of the red channel. + * {@return an array of value describing the response of the red channel} */ - public static final StructHandle.Array red = StructHandle.ofArray(LAYOUT, "red", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + MemorySegment red(); + /** - * An array of value describing the response of the green channel. + * Sets {@link #red()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Array green = StructHandle.ofArray(LAYOUT, "green", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + GLFWGammaRamp red(MemorySegment val); + /** - * An array of value describing the response of the blue channel. + * {@return an array of value describing the response of the green channel} + */ + MemorySegment green(); + + /** + * Sets {@link #green()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Array blue = StructHandle.ofArray(LAYOUT, "blue", Marshal::marshal, Unmarshal::unmarshalAsShortArray); + GLFWGammaRamp green(MemorySegment val); + + /** + * {@return an array of value describing the response of the blue channel} + */ + MemorySegment blue(); + + /** + * Sets {@link #blue()}. + * + * @param val the value + * @return this + */ + GLFWGammaRamp blue(MemorySegment val); + /** - * The number of elements in each array. + * {@return the number of elements in each array} */ - public static final StructHandle.Int size = StructHandle.ofInt(LAYOUT, "size"); + int size(); /** - * Creates a struct with the given layout. + * Sets {@link #size()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this */ - public GLFWGammaRamp(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + GLFWGammaRamp size(int val); + + /** + * {@return {@link #red()}} + * + * @param size the size + */ + default short[] javaRed(int size) { + return Unmarshal.unmarshalAsShortArray(red().reinterpret(ValueLayout.JAVA_SHORT.scale(0L, size))); + } + + /** + * Sets {@link #red()}. + * + * @param allocator the allocator + * @param val the value + * @return this + */ + default GLFWGammaRamp javaRed(SegmentAllocator allocator, short[] val) { + return red(Marshal.marshal(allocator, val)); + } + + /** + * {@return {@link #green()}} + * + * @param size the size + */ + default short[] javaGreen(int size) { + return Unmarshal.unmarshalAsShortArray(green().reinterpret(ValueLayout.JAVA_SHORT.scale(0L, size))); } /** - * Allocates a struct with the given layout. + * Sets {@link #green()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param allocator the allocator + * @param val the value + * @return this */ - public GLFWGammaRamp(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); + default GLFWGammaRamp javaGreen(SegmentAllocator allocator, short[] val) { + return green(Marshal.marshal(allocator, val)); } /** - * Creates a struct with the given layout. + * {@return {@link #blue()}} * - * @param segment the segment + * @param size the size */ - public GLFWGammaRamp(MemorySegment segment) { - super(segment, LAYOUT); + default short[] javaBlue(int size) { + return Unmarshal.unmarshalAsShortArray(blue().reinterpret(ValueLayout.JAVA_SHORT.scale(0L, size))); } /** - * Allocates a struct with the given layout. + * Sets {@link #blue()}. * * @param allocator the allocator + * @param val the value + * @return this */ - public GLFWGammaRamp(SegmentAllocator allocator) { - super(allocator, LAYOUT); + default GLFWGammaRamp javaBlue(SegmentAllocator allocator, short[] val) { + return blue(Marshal.marshal(allocator, val)); } } 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 09736d0a..9d991c29 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWImage.java @@ -16,10 +16,12 @@ package overrungl.glfw; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.foreign.MemorySegment; +import java.lang.invoke.MethodHandles; /** * This describes a single 2D image. See the documentation for each related @@ -35,63 +37,55 @@ * @author squid233 * @since 0.1.0 */ -public final class GLFWImage extends Struct { +public interface GLFWImage extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("width"), - ValueLayout.JAVA_INT.withName("height"), - ValueLayout.ADDRESS.withName("pixels") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("width") + .cInt("height") + .cAddress("pixels") + .build() ); + /** - * The width, in pixels, of this image. - */ - public static final StructHandle.Int width = StructHandle.ofInt(LAYOUT, "width"); - /** - * The height, in pixels, of this image. + * {@return the width, in pixels, of this image} */ - public static final StructHandle.Int height = StructHandle.ofInt(LAYOUT, "height"); + int width(); + /** - * The pixel data address of this image, arranged left-to-right, top-to-bottom. + * Sets {@link #width()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Address pixels = StructHandle.ofAddress(LAYOUT, "pixels"); + GLFWImage width(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return the height, in pixels, of this image} */ - public GLFWImage(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int height(); /** - * Allocates a struct with the given layout. + * Sets {@link #height()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public GLFWImage(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + GLFWImage height(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment + * {@return the pixel data address of this image, arranged left-to-right, top-to-bottom} */ - public GLFWImage(MemorySegment segment) { - super(segment, LAYOUT); - } + MemorySegment pixels(); /** - * Allocates a struct with the given layout. + * Sets {@link #pixels()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public GLFWImage(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + GLFWImage pixels(MemorySegment val); } 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 3efec5fe..23da2c78 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVidMode.java @@ -16,10 +16,11 @@ package overrungl.glfw; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * This describes a single video mode. @@ -39,112 +40,49 @@ * @see GLFW#getVideoModes * @since 0.1.0 */ -public final class GLFWVidMode extends Struct { +public interface GLFWVidMode extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("width"), - ValueLayout.JAVA_INT.withName("height"), - ValueLayout.JAVA_INT.withName("redBits"), - ValueLayout.JAVA_INT.withName("greenBits"), - ValueLayout.JAVA_INT.withName("blueBits"), - ValueLayout.JAVA_INT.withName("refreshRate") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("width") + .cInt("height") + .cInt("redBits") + .cInt("greenBits") + .cInt("blueBits") + .cInt("refreshRate") + .build() ); - /** - * the width, in screen coordinates, of the video mode - */ - public static final StructHandle.Int width = StructHandle.ofInt(LAYOUT, "width"); - /** - * the height, in screen coordinates, of the video mode - */ - public static final StructHandle.Int height = StructHandle.ofInt(LAYOUT, "height"); - /** - * the bit depth of the red channel of the video mode - */ - public static final StructHandle.Int redBits = StructHandle.ofInt(LAYOUT, "redBits"); - /** - * the bit depth of the green channel of the video mode - */ - public static final StructHandle.Int greenBits = StructHandle.ofInt(LAYOUT, "greenBits"); - /** - * the bit depth of the blue channel of the video mode - */ - public static final StructHandle.Int blueBits = StructHandle.ofInt(LAYOUT, "blueBits"); - /** - * the refresh rate, in Hz, of the video mode - */ - public static final StructHandle.Int refreshRate = StructHandle.ofInt(LAYOUT, "refreshRate"); /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return the width, in screen coordinates, of the video mode} */ - public GLFWVidMode(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int width(); /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count + * {@return the height, in screen coordinates, of the video mode} */ - public GLFWVidMode(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + int height(); /** - * Creates a struct with the given layout. - * - * @param segment the segment + * {@return the bit depth of the red channel of the video mode} */ - public GLFWVidMode(MemorySegment segment) { - super(segment, LAYOUT); - } + int redBits(); /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator + * {@return the bit depth of the green channel of the video mode} */ - public GLFWVidMode(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + int greenBits(); /** - * {@return an immutable state of this struct} + * {@return the bit depth of the blue channel of the video mode} */ - public Value value() { - return new Value(width.get(this), - height.get(this), - redBits.get(this), - greenBits.get(this), - blueBits.get(this), - refreshRate.get(this)); - } + int blueBits(); /** - * The immutable state of {@link GLFWVidMode}. - * - * @param width the width, in screen coordinates, of the video mode - * @param height the height, in screen coordinates, of the video mode - * @param redBits the bit depth of the red channel, of the video mode - * @param greenBits the bit depth of the green channel, of the video mode - * @param blueBits the bit depth of the blue channel, of the video mode - * @param refreshRate the refresh rate, in Hz, of the video mode - * @author squid233 - * @since 0.1.0 + * {@return the refresh rate, in Hz, of the video mode} */ - public /* value */ record Value( - int width, - int height, - int redBits, - int greenBits, - int blueBits, - int refreshRate - ) { - } + int refreshRate(); } diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java deleted file mode 100644 index e4a2af8d..00000000 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedByteArray.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.glfw; - -import overrun.marshal.Marshal; -import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; - -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -/** - * Sized array struct handle - * - * @author squid233 - * @since 0.1.0 - */ -public final class StructHandleSizedByteArray extends StructHandle { - private StructHandleSizedByteArray(VarHandle varHandle) { - super(varHandle); - } - - /** - * Creates it - * - * @param struct struct - * @param name name - * @return handle - */ - static StructHandleSizedByteArray of(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(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(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(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(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 deleted file mode 100644 index 0c5aa91f..00000000 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/StructHandleSizedFloatArray.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2024 Overrun Organization - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - */ - -package overrungl.glfw; - -import overrun.marshal.Marshal; -import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; - -import java.lang.foreign.StructLayout; -import java.lang.invoke.VarHandle; - -/** - * Sized array struct handle - * - * @author squid233 - * @since 0.1.0 - */ -public final class StructHandleSizedFloatArray extends StructHandle { - private StructHandleSizedFloatArray(VarHandle varHandle) { - super(varHandle); - } - - /** - * Creates it - * - * @param struct struct - * @param name name - * @return handle - */ - static StructHandleSizedFloatArray of(StructLayout struct, String name) { - return new StructHandleSizedFloatArray(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(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 - */ - public void set(Struct struct, long arrayIndex, float 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 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(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 25b3ddc6..8807c440 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java @@ -620,7 +620,7 @@ default NFDResult nopenDialogU8(@NativeType("nfdu8char_t**") MemorySegment outPa } catch (Throwable e) { throw new AssertionError("should not reach here", e); } - } else return nopenDialogN(outPath, new NFDNFilterItem(filterList.segment()), filterCount, defaultPath); + } else return nopenDialogN(outPath, NFDNFilterItem.OF.of(filterList.segment()), filterCount, defaultPath); } /** @@ -668,7 +668,7 @@ default NFDResult nopenDialogMultipleU8(@NativeType("const nfdpathset_t**") Memo throw new AssertionError("should not reach here", e); } } else - return nopenDialogMultipleN(outPaths, new NFDNFilterItem(filterList.segment()), filterCount, defaultPath); + return nopenDialogMultipleN(outPaths, NFDNFilterItem.OF.of(filterList.segment()), filterCount, defaultPath); } /** @@ -711,7 +711,7 @@ default NFDResult nsaveDialogU8(@NativeType("nfdu8char_t**") MemorySegment outPa throw new AssertionError("should not reach here", e); } } else - return nsaveDialogN(outPath, new NFDNFilterItem(filterList.segment()), filterCount, defaultPath, defaultName); + return nsaveDialogN(outPath, NFDNFilterItem.OF.of(filterList.segment()), filterCount, defaultPath, defaultName); } /** diff --git a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java index fa6c8a42..1288c957 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDEnumerator.java @@ -18,12 +18,13 @@ import org.jetbrains.annotations.NotNull; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; import overrungl.util.value.Tuple2; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; +import java.lang.invoke.MethodHandles; import java.util.Iterator; import java.util.NoSuchElementException; @@ -36,11 +37,17 @@ * @see NFD#pathSetGetEnum(MemorySegment, MemorySegment) * @since 0.1.0 */ -public final class NFDEnumerator extends Struct implements Iterable, AutoCloseable { - /** - * The struct layout. - */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout(ADDRESS.withName("ptr")); +public final class NFDEnumerator implements Iterable, AutoCloseable { + private interface Segment extends Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + MemoryLayout.structLayout(ADDRESS.withName("ptr")) + ); + } + private static final Iterator EMPTY_ITERATOR = new Iterator<>() { @Override public boolean hasNext() { @@ -54,10 +61,11 @@ public String next() { }; private final NFD nfd = NFD.INSTANCE; private final Kind kind; + private final Segment segment; - private NFDEnumerator(Kind kind, MemorySegment address) { - super(address, LAYOUT); + private NFDEnumerator(Kind kind, Segment segment) { this.kind = kind; + this.segment = segment; } /** @@ -101,8 +109,8 @@ public String next() { } String[] s = new String[1]; final NFDResult result = switch (kind) { - case N -> nfd.pathSetEnumNextN(segment(), s); - case U8 -> nfd.pathSetEnumNextU8(segment(), s); + case N -> nfd.pathSetEnumNextN(segment.segment(), s); + case U8 -> nfd.pathSetEnumNextU8(segment.segment(), s); }; if (result == NFDResult.ERROR) throw errorIterating(nfd); nextPath = s[0]; @@ -115,7 +123,7 @@ private static Tuple2 fromPathSet(Kind kind, SegmentAl final NFDResult result = NFD.INSTANCE.pathSetGetEnum(pathSet, seg); return new Tuple2<>(result, result == NFDResult.OKAY ? - new NFDEnumerator(kind, seg) : + new NFDEnumerator(kind, Segment.OF.of(seg)) : null); } @@ -151,8 +159,8 @@ public Iterator iterator() { // TODO: 2023/7/6 Value object String[] s = new String[1]; final NFDResult result = switch (kind) { - case N -> nfd.pathSetEnumNextN(segment(), s); - case U8 -> nfd.pathSetEnumNextU8(segment(), s); + case N -> nfd.pathSetEnumNextN(segment.segment(), s); + case U8 -> nfd.pathSetEnumNextU8(segment.segment(), s); }; final String path = s[0]; if (path == null || result != NFDResult.OKAY) { @@ -166,6 +174,6 @@ public Iterator iterator() { @Override public void close() { - nfd.pathSetFreeEnum(segment()); + nfd.pathSetFreeEnum(segment.segment()); } } 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 48b31500..baa6d15d 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDNFilterItem.java @@ -16,12 +16,15 @@ package overrungl.nfd; +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Marshal; +import overrun.marshal.Unmarshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; -import overrun.marshal.struct.StructHandleView; +import overrun.marshal.struct.StructAllocator; import overrungl.util.value.Pair; import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -34,42 +37,67 @@ * @author squid233 * @since 0.1.0 */ -public final class NFDNFilterItem extends Struct { +public interface NFDNFilterItem> extends Struct { /** * The struct layout. */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withName("name"), - ValueLayout.ADDRESS.withName("spec") - ); - private static final StructHandle.Str _name = StructHandle.ofString(LAYOUT, "name", NFDInternal.nfdCharset); - private static final StructHandle.Str _spec = StructHandle.ofString(LAYOUT, "spec", NFDInternal.nfdCharset); + StructLayout LAYOUT = LayoutBuilder.struct() + .cAddress("name", MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, ValueLayout.JAVA_BYTE)) + .cAddress("spec", MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, ValueLayout.JAVA_BYTE)) + .build(); /** - * name + * The allocator */ - public static final StructHandleView.Str name = _name; + StructAllocator> OF = new StructAllocator<>(MethodHandles.lookup(), LAYOUT); + /** - * spec + * Mutable */ - public static final StructHandleView.Str spec = _spec; + interface Mutable extends NFDNFilterItem, Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>(MethodHandles.lookup(), LAYOUT); + + /** + * Sets {@link #name()}. + * + * @param val the value + * @return this + */ + Mutable name(MemorySegment val); + + /** + * Sets {@link #spec()}. + * + * @param val the value + * @return this + */ + Mutable spec(MemorySegment val); + } /** - * Create a {@code NFDNFilterItem} instance. - * - * @param address the address. + * {@return name} + */ + MemorySegment name(); + + /** + * {@return spec} + */ + MemorySegment spec(); + + /** + * {@return {@link #name()}} */ - public NFDNFilterItem(MemorySegment address) { - super(address, LAYOUT); + default String javaName() { + return Unmarshal.unmarshalAsString(name(), NFDInternal.nfdCharset); } /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return {@link #spec()}} */ - public NFDNFilterItem(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + default String javaSpec() { + return Unmarshal.unmarshalAsString(spec(), NFDInternal.nfdCharset); } /** @@ -80,11 +108,10 @@ public NFDNFilterItem(MemorySegment segment, long elementCount) { * @param spec the specification of the filter * @return the instance */ - public static NFDNFilterItem create(SegmentAllocator allocator, String name, String spec) { - final NFDNFilterItem item = new NFDNFilterItem(allocator.allocate(LAYOUT)); - _name.set(item, allocator, name); - _spec.set(item, allocator, spec); - return item; + static NFDNFilterItem create(SegmentAllocator allocator, String name, String spec) { + return Mutable.OF.of(allocator) + .name(Marshal.marshal(allocator, name)) + .spec(Marshal.marshal(allocator, spec)); } /** @@ -95,12 +122,13 @@ public static NFDNFilterItem create(SegmentAllocator allocator, String name, Str * @return the instance */ @SafeVarargs - public static NFDNFilterItem create(SegmentAllocator allocator, Pair... items) { - final NFDNFilterItem buffer = new NFDNFilterItem(allocator.allocate(LAYOUT, items.length), items.length); + static NFDNFilterItem create(SegmentAllocator allocator, Pair... items) { + final var buffer = Mutable.OF.of(allocator, items.length); for (int i = 0, len = items.length; i < len; i++) { - Pair item = items[i]; - _name.set(buffer, i, allocator, item.key()); - _spec.set(buffer, i, allocator, item.value()); + var item = items[i]; + buffer.slice(i) + .name(Marshal.marshal(allocator, item.key())) + .spec(Marshal.marshal(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 9398729e..ea714b9c 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFDU8FilterItem.java @@ -16,12 +16,15 @@ package overrungl.nfd; +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Marshal; +import overrun.marshal.Unmarshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; -import overrun.marshal.struct.StructHandleView; +import overrun.marshal.struct.StructAllocator; import overrungl.util.value.Pair; import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -34,42 +37,67 @@ * @author squid233 * @since 0.1.0 */ -public final class NFDU8FilterItem extends Struct { +public interface NFDU8FilterItem> extends Struct { /** * The struct layout. */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withName("name"), - ValueLayout.ADDRESS.withName("spec") - ); - private static final StructHandle.Str _name = StructHandle.ofString(LAYOUT, "name"); - private static final StructHandle.Str _spec = StructHandle.ofString(LAYOUT, "spec"); + StructLayout LAYOUT = LayoutBuilder.struct() + .cAddress("name", MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, ValueLayout.JAVA_BYTE)) + .cAddress("spec", MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, ValueLayout.JAVA_BYTE)) + .build(); /** - * name + * The allocator */ - public static final StructHandleView.Str name = _name; + StructAllocator> OF = new StructAllocator<>(MethodHandles.lookup(), LAYOUT); + /** - * spec + * Mutable */ - public static final StructHandleView.Str spec = _spec; + interface Mutable extends NFDU8FilterItem, Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>(MethodHandles.lookup(), LAYOUT); + + /** + * Sets {@link #name()}. + * + * @param val the value + * @return this + */ + Mutable name(MemorySegment val); + + /** + * Sets {@link #spec()}. + * + * @param val the value + * @return this + */ + Mutable spec(MemorySegment val); + } /** - * Create a {@code NFDU8FilterItem} instance. - * - * @param address the address. + * {@return name} + */ + MemorySegment name(); + + /** + * {@return spec} + */ + MemorySegment spec(); + + /** + * {@return {@link #name()}} */ - public NFDU8FilterItem(MemorySegment address) { - super(address, LAYOUT); + default String javaName() { + return Unmarshal.unmarshalAsString(name()); } /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return {@link #spec()}} */ - public NFDU8FilterItem(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + default String javaSpec() { + return Unmarshal.unmarshalAsString(spec()); } /** @@ -80,11 +108,10 @@ public NFDU8FilterItem(MemorySegment segment, long elementCount) { * @param spec the specification of the filter * @return the instance */ - public static NFDU8FilterItem create(SegmentAllocator allocator, String name, String spec) { - final NFDU8FilterItem item = new NFDU8FilterItem(allocator.allocate(LAYOUT)); - _name.set(item, allocator, name); - _spec.set(item, allocator, spec); - return item; + static NFDU8FilterItem create(SegmentAllocator allocator, String name, String spec) { + return Mutable.OF.of(allocator) + .name(Marshal.marshal(allocator, name)) + .spec(Marshal.marshal(allocator, spec)); } /** @@ -95,12 +122,13 @@ public static NFDU8FilterItem create(SegmentAllocator allocator, String name, St * @return the instance */ @SafeVarargs - public static NFDU8FilterItem create(SegmentAllocator allocator, Pair... items) { - final NFDU8FilterItem buffer = new NFDU8FilterItem(allocator.allocate(LAYOUT, items.length), items.length); + static NFDU8FilterItem create(SegmentAllocator allocator, Pair... items) { + final var buffer = Mutable.OF.of(allocator, items.length); for (int i = 0, len = items.length; i < len; i++) { - Pair item = items[i]; - _name.set(buffer, i, allocator, item.key()); - _spec.set(buffer, i, allocator, item.value()); + var item = items[i]; + buffer.slice(i) + .name(Marshal.marshal(allocator, item.key())) + .spec(Marshal.marshal(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 b7e5f3ed..a1289bcb 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java @@ -16,10 +16,11 @@ package overrungl.opengl; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * The OpenGL 4.2 draw arrays indirect command. @@ -35,68 +36,69 @@ * @author squid233 * @since 0.1.0 */ -public final class DrawArraysIndirectCommand extends Struct { +public interface DrawArraysIndirectCommand extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("count"), - ValueLayout.JAVA_INT.withName("primCount"), - ValueLayout.JAVA_INT.withName("first"), - ValueLayout.JAVA_INT.withName("baseInstance") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("count") + .cInt("primCount") + .cInt("first") + .cInt("baseInstance") + .build() ); + /** - * the count + * {@return count} */ - public static final StructHandle.Int count = StructHandle.ofInt(LAYOUT, "count"); + int count(); + /** - * the primCount + * Sets {@link #count()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int primCount = StructHandle.ofInt(LAYOUT, "primCount"); + DrawArraysIndirectCommand count(int val); + /** - * the first + * {@return primCount} */ - public static final StructHandle.Int first = StructHandle.ofInt(LAYOUT, "first"); + int primCount(); + /** - * the baseInstance + * Sets {@link #primCount()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int baseInstance = StructHandle.ofInt(LAYOUT, "baseInstance"); + DrawArraysIndirectCommand primCount(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return first} */ - public DrawArraysIndirectCommand(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int first(); /** - * Allocates a struct with the given layout. + * Sets {@link #first()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public DrawArraysIndirectCommand(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + DrawArraysIndirectCommand first(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment + * {@return baseInstance} */ - public DrawArraysIndirectCommand(MemorySegment segment) { - super(segment, LAYOUT); - } + int baseInstance(); /** - * Allocates a struct with the given layout. + * Sets {@link #baseInstance()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public DrawArraysIndirectCommand(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + DrawArraysIndirectCommand baseInstance(int val); } 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 97f6436a..797b9978 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java @@ -16,10 +16,11 @@ package overrungl.opengl; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * The OpenGL 4.2 draw elements indirect command. @@ -36,73 +37,83 @@ * @author squid233 * @since 0.1.0 */ -public final class DrawElementsIndirectCommand extends Struct { +public interface DrawElementsIndirectCommand extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("count"), - ValueLayout.JAVA_INT.withName("primCount"), - ValueLayout.JAVA_INT.withName("firstIndex"), - ValueLayout.JAVA_INT.withName("baseVertex"), - ValueLayout.JAVA_INT.withName("baseInstance") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("count") + .cInt("primCount") + .cInt("firstIndex") + .cInt("baseVertex") + .cInt("baseInstance") + .build() ); + /** - * the count + * {@return count} */ - public static final StructHandle.Int count = StructHandle.ofInt(LAYOUT, "count"); + int count(); + /** - * the primCount + * Sets {@link #count()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int primCount = StructHandle.ofInt(LAYOUT, "primCount"); + DrawElementsIndirectCommand count(int val); + /** - * the firstIndex + * {@return primCount} */ - public static final StructHandle.Int firstIndex = StructHandle.ofInt(LAYOUT, "firstIndex"); + int primCount(); + /** - * the baseVertex + * Sets {@link #primCount()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int baseVertex = StructHandle.ofInt(LAYOUT, "baseVertex"); + DrawElementsIndirectCommand primCount(int val); + /** - * the baseInstance + * {@return firstIndex} */ - public static final StructHandle.Int baseInstance = StructHandle.ofInt(LAYOUT, "baseInstance"); + int firstIndex(); /** - * Creates a struct with the given layout. + * Sets {@link #firstIndex()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this */ - public DrawElementsIndirectCommand(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + DrawElementsIndirectCommand firstIndex(int val); /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count + * {@return baseVertex} */ - public DrawElementsIndirectCommand(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + int baseVertex(); /** - * Creates a struct with the given layout. + * Sets {@link #baseVertex()}. * - * @param segment the segment + * @param val the value + * @return this + */ + DrawElementsIndirectCommand baseVertex(int val); + + /** + * {@return baseInstance} */ - public DrawElementsIndirectCommand(MemorySegment segment) { - super(segment, LAYOUT); - } + int baseInstance(); /** - * Allocates a struct with the given layout. + * Sets {@link #baseInstance()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public DrawElementsIndirectCommand(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + DrawElementsIndirectCommand baseInstance(int val); } 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 90c78fc2..cd6edf8f 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIIoCallbacks.java @@ -16,11 +16,17 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; +import overrun.marshal.Marshal; import overrun.marshal.Upcall; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.foreign.Arena; +import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.MemorySegment; +import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandles; /** * The IO callback of STB image. @@ -35,64 +41,107 @@ * @author squid233 * @since 0.1.0 */ -public final class STBIIoCallbacks extends Struct { +public interface STBIIoCallbacks extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withName("read"), - ValueLayout.ADDRESS.withName("skip"), - ValueLayout.ADDRESS.withName("eof") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("read") + .cAddress("skip") + .cAddress("eof") + .build() ); + + /** + * {@return the read callback} + */ + MemorySegment read(); + /** - * the read callback + * Sets {@link #read()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Upcall read = StructHandle.ofUpcall(LAYOUT, "read", Read::wrap); + STBIIoCallbacks read(MemorySegment val); + /** - * the skip callback + * {@return the skip callback} */ - public static final StructHandle.Upcall skip = StructHandle.ofUpcall(LAYOUT, "skip", Skip::wrap); + MemorySegment skip(); + + /** + * Sets {@link #skip()}. + * + * @param val the value + * @return this + */ + STBIIoCallbacks skip(MemorySegment val); + /** - * the eof callback + * {@return the eof callback} */ - public static final StructHandle.Upcall eof = StructHandle.ofUpcall(LAYOUT, "eof", Eof::wrap); + MemorySegment eof(); /** - * Creates a struct with the given layout. + * Sets {@link #eof()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this */ - public STBIIoCallbacks(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + STBIIoCallbacks eof(MemorySegment val); + + /** + * {@return the read callback} + */ + default Read javaRead() { + return Read.wrap(read()); } /** - * Allocates a struct with the given layout. + * Sets {@link #read()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBIIoCallbacks(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); + default STBIIoCallbacks javaRead(Arena arena, Read val) { + return read(Marshal.marshal(arena, val)); } /** - * Creates a struct with the given layout. + * {@return the skip callback} + */ + default Skip javaSkip() { + return Skip.wrap(skip()); + } + + /** + * Sets {@link #skip()}. * - * @param segment the segment + * @param val the value + * @return this + */ + default STBIIoCallbacks javaSkip(Arena arena, Skip val) { + return skip(Marshal.marshal(arena, val)); + } + + /** + * {@return the eof callback} */ - public STBIIoCallbacks(MemorySegment segment) { - super(segment, LAYOUT); + default Eof javaEof() { + return Eof.wrap(eof()); } /** - * Allocates a struct with the given layout. + * Sets {@link #eof()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBIIoCallbacks(SegmentAllocator allocator) { - super(allocator, LAYOUT); + default STBIIoCallbacks javaEof(Arena arena, Eof val) { + return eof(Marshal.marshal(arena, val)); } /** @@ -102,7 +151,7 @@ public STBIIoCallbacks(SegmentAllocator allocator) { * @since 0.1.0 */ @FunctionalInterface - public interface Read extends Upcall { + interface Read extends Upcall { /** * the type */ @@ -154,7 +203,7 @@ static Read wrap(MemorySegment stub) { * @since 0.1.0 */ @FunctionalInterface - public interface Skip extends Upcall { + interface Skip extends Upcall { /** * the type */ @@ -194,7 +243,7 @@ static Skip wrap(MemorySegment stub) { * @since 0.1.0 */ @FunctionalInterface - public interface Eof extends Upcall { + interface Eof extends Upcall { /** * the type */ diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRRESIZE.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRRESIZE.java index 88540f6e..2312b219 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRRESIZE.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBIRRESIZE.java @@ -16,11 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.invoke.MethodHandles; /** * {@code STBIR_RESIZE} @@ -28,84 +28,49 @@ * @author squid233 * @since 0.1.0 */ -public final class STBIRRESIZE extends Struct { +public interface STBIRRESIZE extends Struct { /** - * Layout + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ADDRESS.withName("user_data"), - ADDRESS.withName("input_pixels"), - JAVA_INT.withName("input_w"), - JAVA_INT.withName("input_h"), - JAVA_DOUBLE.withName("input_s0"), - JAVA_DOUBLE.withName("input_t0"), - JAVA_DOUBLE.withName("input_s1"), - JAVA_DOUBLE.withName("input_t1"), - ADDRESS.withName("input_cb"), - ADDRESS.withName("output_pixels"), - JAVA_INT.withName("output_w"), - JAVA_INT.withName("output_h"), - JAVA_INT.withName("output_subx"), - JAVA_INT.withName("output_suby"), - JAVA_INT.withName("output_subw"), - JAVA_INT.withName("output_subh"), - ADDRESS.withName("output_cb"), - JAVA_INT.withName("input_stride_in_bytes"), - JAVA_INT.withName("output_stride_in_bytes"), - JAVA_INT.withName("splits"), - JAVA_INT.withName("fast_alpha"), - JAVA_INT.withName("needs_rebuild"), - JAVA_INT.withName("called_alloc"), - JAVA_INT.withName("input_pixel_layout_public"), - JAVA_INT.withName("output_pixel_layout_public"), - JAVA_INT.withName("input_data_type"), - JAVA_INT.withName("output_data_type"), - JAVA_INT.withName("horizontal_filter"), - JAVA_INT.withName("vertical_filter"), - JAVA_INT.withName("horizontal_edge"), - JAVA_INT.withName("vertical_edge"), - ADDRESS.withName("horizontal_filter_kernel"), - ADDRESS.withName("horizontal_filter_support"), - ADDRESS.withName("vertical_filter_kernel"), - ADDRESS.withName("vertical_filter_support"), - ADDRESS.withName("samplers") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("user_data") + .cAddress("input_pixels") + .cInt("input_w") + .cInt("input_h") + .cDouble("input_s0") + .cDouble("input_t0") + .cDouble("input_s1") + .cDouble("input_t1") + .cAddress("input_cb") + .cAddress("output_pixels") + .cInt("output_w") + .cInt("output_h") + .cInt("output_subx") + .cInt("output_suby") + .cInt("output_subw") + .cInt("output_subh") + .cAddress("output_cb") + .cInt("input_stride_in_bytes") + .cInt("output_stride_in_bytes") + .cInt("splits") + .cInt("fast_alpha") + .cInt("needs_rebuild") + .cInt("called_alloc") + .cInt("input_pixel_layout_public") + .cInt("output_pixel_layout_public") + .cInt("input_data_type") + .cInt("output_data_type") + .cInt("horizontal_filter") + .cInt("vertical_filter") + .cInt("horizontal_edge") + .cInt("vertical_edge") + .cAddress("horizontal_filter_kernel") + .cAddress("horizontal_filter_support") + .cAddress("vertical_filter_kernel") + .cAddress("vertical_filter_support") + .cAddress("samplers") + .build() ); - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count - */ - public STBIRRESIZE(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count - */ - public STBIRRESIZE(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - */ - public STBIRRESIZE(MemorySegment segment) { - super(segment, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - */ - public STBIRRESIZE(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPContext.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPContext.java index 45f5773b..84de6800 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPContext.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPContext.java @@ -16,67 +16,35 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * the details of the following structures don't matter to you, but they must * be visible so you can handle the memory allocations for them + * * @author squid233 * @since 0.1.0 */ -public final class STBRPContext extends Struct { +public interface STBRPContext extends Struct { /** - * The layout. + * The allocator */ - public static final StructLayout LAYOUT= MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("width"), - ValueLayout.JAVA_INT.withName("height"), - ValueLayout.JAVA_INT.withName("align"), - ValueLayout.JAVA_INT.withName("init_mode"), - ValueLayout.JAVA_INT.withName("heuristic"), - ValueLayout.JAVA_INT.withName("num_nodes"), - ValueLayout.ADDRESS.withName("active_head").withTargetLayout(MemoryLayout.sequenceLayout(0L, STBRPNode.LAYOUT)), - ValueLayout.ADDRESS.withName("free_head").withTargetLayout(MemoryLayout.sequenceLayout(0L, STBRPNode.LAYOUT)), - MemoryLayout.sequenceLayout(2L, STBRPNode.LAYOUT) + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("width") + .cInt("height") + .cInt("align") + .cInt("init_mode") + .cInt("heuristic") + .cInt("num_nodes") + .cAddress("active_head") + .cAddress("free_head") + .cArray("extra", 2, STBRPNode.OF.layout()) + .build() ); - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count - */ - public STBRPContext(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count - */ - public STBRPContext(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - */ - public STBRPContext(MemorySegment segment) { - super(segment, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - */ - public STBRPContext(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPNode.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPNode.java index 695ccdcf..7e89e954 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPNode.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPNode.java @@ -16,9 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * the details of the following structures don't matter to you, but they must @@ -27,51 +29,16 @@ * @author squid233 * @since 0.1.0 */ -public final class STBRPNode extends Struct { +public interface STBRPNode extends Struct { /** - * The layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("x"), - ValueLayout.JAVA_INT.withName("y"), - ValueLayout.ADDRESS.withName("next") // self-reference + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("x") + .cInt("y") + .cAddress("next") + .build() ); - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count - */ - public STBRPNode(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count - */ - public STBRPNode(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - */ - public STBRPNode(MemorySegment segment) { - super(segment, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - */ - public STBRPNode(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } } 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 dc15235c..30492cf5 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBRPRect.java @@ -16,10 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** * 16 bytes, nominally @@ -27,72 +28,111 @@ * @author squid233 * @since 0.1.0 */ -public final class STBRPRect extends Struct { +public interface STBRPRect extends Struct { /** - * The layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("id"), - ValueLayout.JAVA_INT.withName("w"), - ValueLayout.JAVA_INT.withName("h"), - ValueLayout.JAVA_INT.withName("x"), - ValueLayout.JAVA_INT.withName("y"), - ValueLayout.JAVA_INT.withName("was_packed") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("id") + .cInt("w") + .cInt("h") + .cInt("x") + .cInt("y") + .cInt("was_packed") + .build() ); + /** * reserved for your use + * + * @return id + */ + int id(); + + /** + * Sets {@link #id()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int id = StructHandle.ofInt(LAYOUT, "id"); + STBRPRect id(int val); + /** * input + * + * @return w */ - public static final StructHandle.Int w = StructHandle.ofInt(LAYOUT, "w"), - h = StructHandle.ofInt(LAYOUT, "h"); + int w(); + + /** + * Sets {@link #w()}. + * + * @param val the value + * @return this + */ + STBRPRect w(int val); + + /** + * input + * + * @return h + */ + int h(); + + /** + * Sets {@link #h()}. + * + * @param val the value + * @return this + */ + STBRPRect h(int val); + /** * output + * + * @return x */ - public static final StructHandle.Int x = StructHandle.ofInt(LAYOUT, "x"), - y = StructHandle.ofInt(LAYOUT, "y"), + int x(); + /** - * non-zero if valid packing + * Sets {@link #x()}. + * + * @param val the value + * @return this */ - wasPacked = StructHandle.ofInt(LAYOUT, "was_packed"); + STBRPRect x(int val); /** - * Creates a struct with the given layout. + * output * - * @param segment the segment - * @param elementCount the element count + * @return y */ - public STBRPRect(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int y(); /** - * Allocates a struct with the given layout. + * Sets {@link #y()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBRPRect(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBRPRect y(int val); /** - * Creates a struct with the given layout. + * output + *

+ * non-zero if valid packing * - * @param segment the segment + * @return was_packed */ - public STBRPRect(MemorySegment segment) { - super(segment, LAYOUT); - } + int was_packed(); /** - * Allocates a struct with the given layout. + * Sets {@link #was_packed()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBRPRect(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBRPRect was_packed(int val); } 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 cba629bb..7ed5f055 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTAlignedQuad.java @@ -16,15 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.JAVA_FLOAT; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -39,70 +35,141 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTAlignedQuad extends Struct { - /** - * The struct layout. - */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_FLOAT.withName("x0"), - JAVA_FLOAT.withName("y0"), - JAVA_FLOAT.withName("s0"), - JAVA_FLOAT.withName("t0"), - JAVA_FLOAT.withName("x1"), - JAVA_FLOAT.withName("y1"), - JAVA_FLOAT.withName("s1"), - JAVA_FLOAT.withName("t1") +public interface STBTTAlignedQuad extends Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cFloat("x0") + .cFloat("y0") + .cFloat("s0") + .cFloat("t0") + .cFloat("x1") + .cFloat("y1") + .cFloat("s1") + .cFloat("t1") + .build() ); + /** + * {@return x0} + *

* top-left */ - 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"); + float x0(); + + /** + * Sets {@link #x0()}. + * + * @param val the value + * @return this + */ + STBTTAlignedQuad x0(float val); + /** + * {@return y0} + *

+ * top-left + */ + float y0(); + + /** + * Sets {@link #y0()}. + * + * @param val the value + * @return this + */ + STBTTAlignedQuad y0(float val); + + /** + * {@return s0} + *

+ * top-left + */ + float s0(); + + /** + * Sets {@link #s0()}. + * + * @param val the value + * @return this + */ + STBTTAlignedQuad s0(float val); + + /** + * {@return t0} + *

+ * top-left + */ + float t0(); + + /** + * Sets {@link #t0()}. + * + * @param val the value + * @return this + */ + STBTTAlignedQuad t0(float val); + + /** + * {@return x1} + *

* bottom-right */ - 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"); + float x1(); /** - * Creates a struct with the given layout. + * Sets {@link #x1()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this + */ + STBTTAlignedQuad x1(float val); + + /** + * {@return y1} + *

+ * bottom-right */ - public STBTTAlignedQuad(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + float y1(); /** - * Allocates a struct with the given layout. + * Sets {@link #y1()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBTTAlignedQuad(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBTTAlignedQuad y1(float val); /** - * Creates a struct with the given layout. + * {@return s1} + *

+ * bottom-right + */ + float s1(); + + /** + * Sets {@link #s1()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBTTAlignedQuad s1(float val); + + /** + * {@return t1} + *

+ * bottom-right */ - public STBTTAlignedQuad(MemorySegment segment) { - super(segment, LAYOUT); - } + float t1(); /** - * Allocates a struct with the given layout. + * Sets {@link #t1()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTAlignedQuad(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBTTAlignedQuad t1(float val); } 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 3f9df4ed..e3468bb7 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBakedChar.java @@ -16,15 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -39,74 +35,119 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTBakedChar extends Struct { +public interface STBTTBakedChar extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_SHORT.withName("x0"), - JAVA_SHORT.withName("y0"), - JAVA_SHORT.withName("x1"), - JAVA_SHORT.withName("y1"), - JAVA_FLOAT.withName("xoff"), - JAVA_FLOAT.withName("yoff"), - JAVA_FLOAT.withName("xadvance") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cShort("x0") + .cShort("y0") + .cShort("x1") + .cShort("y1") + .cFloat("xoff") + .cFloat("yoff") + .cFloat("xadvance") + .build() ); + /** * coordinates of bbox in bitmap + * + * @return x0 */ - 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"); + short x0(); + /** - * xoff + * Sets {@link #x0()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Float xoff = StructHandle.ofFloat(LAYOUT, "xoff"); + STBTTBakedChar x0(short val); + /** - * yoff + * coordinates of bbox in bitmap + * + * @return y0 */ - public static final StructHandle.Float yoff = StructHandle.ofFloat(LAYOUT, "yoff"); + short y0(); + /** - * xadvance + * Sets {@link #y0()}. + * + * @param val the value + * @return this + */ + STBTTBakedChar y0(short val); + + /** + * coordinates of bbox in bitmap + * + * @return x1 */ - public static final StructHandle.Float xadvance = StructHandle.ofFloat(LAYOUT, "xadvance"); + short x1(); /** - * Creates a struct with the given layout. + * Sets {@link #x1()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this */ - public STBTTBakedChar(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + STBTTBakedChar x1(short val); /** - * Allocates a struct with the given layout. + * coordinates of bbox in bitmap * - * @param allocator the allocator - * @param elementCount the element count + * @return y1 */ - public STBTTBakedChar(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + short y1(); /** - * Creates a struct with the given layout. + * Sets {@link #y1()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBTTBakedChar y1(short val); + + /** + * {@return xoff} + */ + float xoff(); + + /** + * Sets {@link #xoff()}. + * + * @param val the value + * @return this + */ + STBTTBakedChar xoff(float val); + + /** + * {@return yoff} + */ + float yoff(); + + /** + * Sets {@link #yoff()}. + * + * @param val the value + * @return this + */ + STBTTBakedChar yoff(float val); + + /** + * {@return xadvance} */ - public STBTTBakedChar(MemorySegment segment) { - super(segment, LAYOUT); - } + float xadvance(); /** - * Allocates a struct with the given layout. + * Sets {@link #xadvance()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTBakedChar(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBTTBakedChar xadvance(float val); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBuf.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBuf.java index b609ff80..a864461d 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBuf.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTBuf.java @@ -16,9 +16,9 @@ package overrungl.stb; -import java.lang.foreign.MemoryLayout; +import overrun.marshal.LayoutBuilder; + import java.lang.foreign.StructLayout; -import java.lang.foreign.ValueLayout; /** * private structure @@ -30,9 +30,9 @@ public final class STBTTBuf { /** * The layout. */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.ADDRESS.withName("data"), - ValueLayout.JAVA_INT.withName("cursor"), - ValueLayout.JAVA_INT.withName("size") - ); + public static final StructLayout LAYOUT = LayoutBuilder.struct() + .cAddress("data") + .cInt("cursor") + .cInt("size") + .build(); } diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTFontInfo.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTFontInfo.java index 3fecb34c..ac502a4d 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTFontInfo.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTFontInfo.java @@ -16,15 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.ADDRESS; -import static java.lang.foreign.ValueLayout.JAVA_INT; +import java.lang.invoke.MethodHandles; /** * The following structure is defined publicly so you can declare one on @@ -33,68 +29,33 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTFontInfo extends Struct { +public interface STBTTFontInfo extends Struct { /** - * The layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ADDRESS.withName("userdata"), - ADDRESS.withName("data"), - JAVA_INT.withName("fontstart"), - JAVA_INT.withName("numGlyphs"), - JAVA_INT.withName("loca"), - JAVA_INT.withName("head"), - JAVA_INT.withName("glyf"), - JAVA_INT.withName("hhea"), - JAVA_INT.withName("hmtx"), - JAVA_INT.withName("kern"), - JAVA_INT.withName("gpos"), - JAVA_INT.withName("svg"), - JAVA_INT.withName("index_map"), - JAVA_INT.withName("indexToLocFormat"), - STBTTBuf.LAYOUT.withName("cff"), - STBTTBuf.LAYOUT.withName("charstrings"), - STBTTBuf.LAYOUT.withName("gsubrs"), - STBTTBuf.LAYOUT.withName("subrs"), - STBTTBuf.LAYOUT.withName("fontdicts"), - STBTTBuf.LAYOUT.withName("fdselect") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("userdata") + .cAddress("data") + .cInt("fontstart") + .cInt("numGlyphs") + .cInt("loca") + .cInt("head") + .cInt("glyf") + .cInt("hhea") + .cInt("hmtx") + .cInt("kern") + .cInt("gpos") + .cInt("svg") + .cInt("index_map") + .cInt("indexToLocFormat") + .cStruct("cff", STBTTBuf.LAYOUT) + .cStruct("charstrings", STBTTBuf.LAYOUT) + .cStruct("gsubrs", STBTTBuf.LAYOUT) + .cStruct("subrs", STBTTBuf.LAYOUT) + .cStruct("fontdicts", STBTTBuf.LAYOUT) + .cStruct("fdselect", STBTTBuf.LAYOUT) + .build() ); - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count - */ - public STBTTFontInfo(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - * @param elementCount the element count - */ - public STBTTFontInfo(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } - - /** - * Creates a struct with the given layout. - * - * @param segment the segment - */ - public STBTTFontInfo(MemorySegment segment) { - super(segment, LAYOUT); - } - - /** - * Allocates a struct with the given layout. - * - * @param allocator the allocator - */ - public STBTTFontInfo(SegmentAllocator allocator) { - super(allocator, 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 b9af8e27..870900a0 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTKerningEntry.java @@ -16,10 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.*; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -35,63 +36,57 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTKerningEntry extends Struct { +public interface STBTTKerningEntry extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ValueLayout.JAVA_INT.withName("glyph1"), - ValueLayout.JAVA_INT.withName("glyph2"), - ValueLayout.JAVA_INT.withName("advance") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("glyph1") + .cInt("glyph2") + .cInt("advance") + .build() ); + /** * use stbtt_FindGlyphIndex + * + * @return glyph1 */ - public static final StructHandle.Int glyph1 = StructHandle.ofInt(LAYOUT, "glyph1"); - /** - * glyph2 - */ - public static final StructHandle.Int glyph2 = StructHandle.ofInt(LAYOUT, "glyph2"); + int glyph1(); + /** - * advance + * Sets {@link #glyph1()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int advance = StructHandle.ofInt(LAYOUT, "advance"); + STBTTKerningEntry glyph1(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return glyph2} */ - public STBTTKerningEntry(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int glyph2(); /** - * Allocates a struct with the given layout. + * Sets {@link #glyph2()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBTTKerningEntry(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBTTKerningEntry glyph2(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment + * {@return advance} */ - public STBTTKerningEntry(MemorySegment segment) { - super(segment, LAYOUT); - } + int advance(); /** - * Allocates a struct with the given layout. + * Sets {@link #advance()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTKerningEntry(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBTTKerningEntry advance(int val); } 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 f65299cb..9d38f2e5 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackRange.java @@ -16,113 +16,170 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.Marshal; import overrun.marshal.Unmarshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; -import overrun.marshal.struct.StructHandleView; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandles; /** *

Layout

*

  * typedef struct
  * {
- *    float {@link #fontSize font_size};
- *    int {@link #firstUnicodeCodepointInRange first_unicode_codepoint_in_range};  // if non-zero, then the chars are continuous, and this is the first codepoint
- *    int *{@link #arrayOfUnicodeCodepoints array_of_unicode_codepoints};       // if non-zero, then this is an array of unicode codepoints
- *    int {@link #numChars num_chars};
- *    stbtt_packedchar *{@link #chardataForRange chardata_for_range}; // output
- *    unsigned char {@link #hOversample h_oversample}, {@link #vOversample v_oversample}; // don't set these, they're used internally
+ *    float {@link #font_size};
+ *    int {@link #first_unicode_codepoint_in_range}; // if non-zero, then the chars are continuous, and this is the first codepoint
+ *    int *{@link #array_of_unicode_codepoints};     // if non-zero, then this is an array of unicode codepoints
+ *    int {@link #num_chars};
+ *    stbtt_packedchar *{@link #chardata_for_range}; // output
+ *    unsigned char {@link #h_oversample}, {@link #v_oversample}; // don't set these, they're used internally
  * } stbtt_pack_range;
  * 
* * @author squid233 * @since 0.1.0 */ -public final class STBTTPackRange extends Struct { - /** - * The struct layout. - */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_FLOAT.withName("font_size"), - JAVA_INT.withName("first_unicode_codepoint_in_range"), - ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, JAVA_INT)).withName("array_of_unicode_codepoints"), - JAVA_INT.withName("num_chars"), - MemoryLayout.paddingLayout(4L), - ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, STBTTPackedChar.LAYOUT)).withName("chardata_for_range"), - JAVA_BYTE.withName("h_oversample"), - JAVA_BYTE.withName("v_oversample"), - MemoryLayout.paddingLayout(6L) +public interface STBTTPackRange extends Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cFloat("font_size") + .cInt("first_unicode_codepoint_in_range") + .cAddress("array_of_unicode_codepoints") + .cInt("num_chars") + .cAddress("chardata_for_range") + .cByte("h_oversample") + .cByte("v_oversample") + .build() ); + /** - * font_size + * {@return font_size} */ - public static final StructHandle.Float fontSize = StructHandle.ofFloat(LAYOUT, "font_size"); + float font_size(); + /** - * if non-zero, then the chars are continuous, and this is the first codepoint + * Sets {@link #font_size()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int firstUnicodeCodepointInRange = StructHandle.ofInt(LAYOUT, "first_unicode_codepoint_in_range"); + STBTTPackRange font_size(float val); + /** - * if non-zero, then this is an array of unicode codepoints + * if non-zero, then the chars are continuous, and this is the first codepoint + * + * @return first_unicode_codepoint_in_range */ - public static final StructHandle.Array arrayOfUnicodeCodepoints = StructHandle.ofArray(LAYOUT, "array_of_unicode_codepoints", Marshal::marshal, Unmarshal::unmarshalAsIntArray); + int first_unicode_codepoint_in_range(); + /** - * num_chars + * Sets {@link #first_unicode_codepoint_in_range()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int numChars = StructHandle.ofInt(LAYOUT, "num_chars"); + STBTTPackRange first_unicode_codepoint_in_range(int val); + /** - * output + * if non-zero, then this is an array of unicode codepoints + * + * @return array_of_unicode_codepoints */ - 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))); + MemorySegment array_of_unicode_codepoints(); + /** - * don't set these, they're used internally + * Sets {@link #array_of_unicode_codepoints()}. + * + * @param val the value + * @return this */ - public static final StructHandleView.Byte hOversample = StructHandle.ofByte(LAYOUT, "h_oversample"), - vOversample = StructHandle.ofByte(LAYOUT, "v_oversample"); + STBTTPackRange array_of_unicode_codepoints(MemorySegment val); /** - * Creates a struct with the given layout. + * {@return {@link #array_of_unicode_codepoints()}} * - * @param segment the segment - * @param elementCount the element count + * @param size the size */ - public STBTTPackRange(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + default int[] javaArrayOfUnicodeCodepoints(int size) { + return Unmarshal.unmarshalAsIntArray(array_of_unicode_codepoints().reinterpret(ValueLayout.JAVA_INT.scale(0L, size))); } /** - * Allocates a struct with the given layout. + * Sets {@link #array_of_unicode_codepoints()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTPackRange(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); + default STBTTPackRange javaArrayOfUnicodeCodepoints(SegmentAllocator allocator, int[] val) { + return array_of_unicode_codepoints(Marshal.marshal(allocator, val)); } /** - * Creates a struct with the given layout. + * {@return num_chars} + */ + int num_chars(); + + /** + * Sets {@link #num_chars()}. * - * @param segment the segment + * @param val the value + * @return this */ - public STBTTPackRange(MemorySegment segment) { - super(segment, LAYOUT); + STBTTPackRange num_chars(int val); + + /** + * output + * + * @return chardata_for_range + */ + MemorySegment chardata_for_range(); + + /** + * Sets {@link #chardata_for_range()}. + * + * @param val the value + * @return this + */ + STBTTPackRange chardata_for_range(MemorySegment val); + + /** + * {@return {@link #chardata_for_range()}} + */ + default STBTTPackedChar javaChardataForRange() { + return STBTTPackedChar.OF.of(chardata_for_range().reinterpret(STBTTPackedChar.OF.layout().scale(0L, num_chars()))); } /** - * Allocates a struct with the given layout. + * Sets {@link #chardata_for_range()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTPackRange(SegmentAllocator allocator) { - super(allocator, LAYOUT); + default STBTTPackRange javaChardataForRange(STBTTPackedChar val) { + return chardata_for_range(Marshal.marshal(val)); } + + /** + * don't set these, they're used internally + * + * @return h_oversample + */ + byte h_oversample(); + + /** + * don't set these, they're used internally + * + * @return v_oversample + */ + byte v_oversample(); } 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 270285da..78f7a244 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTPackedChar.java @@ -16,15 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -40,84 +36,147 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTPackedChar extends Struct { - /** - * The struct layout. - */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_SHORT.withName("x0"), - JAVA_SHORT.withName("y0"), - JAVA_SHORT.withName("x1"), - JAVA_SHORT.withName("y1"), - JAVA_FLOAT.withName("xoff"), - JAVA_FLOAT.withName("yoff"), - JAVA_FLOAT.withName("xadvance"), - JAVA_FLOAT.withName("xoff2"), - JAVA_FLOAT.withName("yoff2") +public interface STBTTPackedChar extends Struct { + /** + * The allocator + */ + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cShort("x0") + .cShort("y0") + .cShort("x1") + .cShort("y1") + .cFloat("xoff") + .cFloat("yoff") + .cFloat("xadvance") + .cFloat("xoff2") + .cFloat("yoff2") + .build() ); + /** * coordinates of bbox in bitmap + * + * @return x0 */ - 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"); + short x0(); + /** - * xoff + * Sets {@link #x0()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Float xoff = StructHandle.ofFloat(LAYOUT, "xoff"); + STBTTPackedChar x0(short val); + /** - * yoff + * coordinates of bbox in bitmap + * + * @return y0 */ - public static final StructHandle.Float yoff = StructHandle.ofFloat(LAYOUT, "yoff"); + short y0(); + /** - * xadvance + * Sets {@link #y0()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Float xadvance = StructHandle.ofFloat(LAYOUT, "xadvance"); + STBTTPackedChar y0(short val); + /** - * xoff2 + * coordinates of bbox in bitmap + * + * @return x1 */ - public static final StructHandle.Float xoff2 = StructHandle.ofFloat(LAYOUT, "xoff2"); + short x1(); + /** - * yoff2 + * Sets {@link #x1()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Float yoff2 = StructHandle.ofFloat(LAYOUT, "yoff2"); + STBTTPackedChar x1(short val); /** - * Creates a struct with the given layout. + * coordinates of bbox in bitmap * - * @param segment the segment - * @param elementCount the element count + * @return y1 */ - public STBTTPackedChar(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + short y1(); /** - * Allocates a struct with the given layout. + * Sets {@link #y1()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBTTPackedChar(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBTTPackedChar y1(short val); /** - * Creates a struct with the given layout. + * {@return xoff} + */ + float xoff(); + + /** + * Sets {@link #xoff()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBTTPackedChar xoff(float val); + + /** + * {@return yoff} + */ + float yoff(); + + /** + * Sets {@link #yoff()}. + * + * @param val the value + * @return this + */ + STBTTPackedChar yoff(float val); + + /** + * {@return xadvance} + */ + float xadvance(); + + /** + * Sets {@link #xadvance()}. + * + * @param val the value + * @return this + */ + STBTTPackedChar xadvance(float val); + + /** + * {@return xoff2} + */ + float xoff2(); + + /** + * Sets {@link #xoff2()}. + * + * @param val the value + * @return this + */ + STBTTPackedChar xoff2(float val); + + /** + * {@return yoff2} */ - public STBTTPackedChar(MemorySegment segment) { - super(segment, LAYOUT); - } + float yoff2(); /** - * Allocates a struct with the given layout. + * Sets {@link #yoff2()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTPackedChar(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBTTPackedChar yoff2(float val); } 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 49ad67bf..7f5d65c1 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTTVertex.java @@ -16,16 +16,11 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.JAVA_BYTE; -import static java.lang.foreign.ValueLayout.JAVA_SHORT; +import java.lang.invoke.MethodHandles; /** *

Layout

@@ -40,89 +35,125 @@ * @author squid233 * @since 0.1.0 */ -public final class STBTTVertex extends Struct { +public interface STBTTVertex extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_SHORT.withName("x"), - JAVA_SHORT.withName("y"), - JAVA_SHORT.withName("cx"), - JAVA_SHORT.withName("cy"), - JAVA_SHORT.withName("cx1"), - JAVA_SHORT.withName("cy1"), - JAVA_BYTE.withName("type"), - JAVA_BYTE.withName("padding") - + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cShort("x") + .cShort("y") + .cShort("cx") + .cShort("cy") + .cShort("cx1") + .cShort("cy1") + .cByte("type") + .cByte("padding") + .build() ); + /** - * x + * {@return x} */ - public static final StructHandle.Short x = StructHandle.ofShort(LAYOUT, "x"); + short x(); + /** - * y + * Sets {@link #x()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Short y = StructHandle.ofShort(LAYOUT, "y"); + STBTTVertex x(short val); + /** - * cx + * {@return y} */ - public static final StructHandle.Short cx = StructHandle.ofShort(LAYOUT, "cx"); + short y(); + /** - * cy + * Sets {@link #y()}. + * + * @param val the value + * @return this + */ + STBTTVertex y(short val); + + /** + * {@return cx} */ - public static final StructHandle.Short cy = StructHandle.ofShort(LAYOUT, "cy"); + short cx(); + /** - * cx1 + * Sets {@link #cx()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Short cx1 = StructHandle.ofShort(LAYOUT, "cx1"); + STBTTVertex cx(short val); + /** - * cy1 + * {@return cy} */ - public static final StructHandle.Short cy1 = StructHandle.ofShort(LAYOUT, "cy1"); + short cy(); + /** - * type + * Sets {@link #cy()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Byte type = StructHandle.ofByte(LAYOUT, "type"); + STBTTVertex cy(short val); + /** - * padding + * {@return cx1} */ - public static final StructHandle.Byte padding = StructHandle.ofByte(LAYOUT, "padding"); + short cx1(); /** - * Creates a struct with the given layout. + * Sets {@link #cx1()}. * - * @param segment the segment - * @param elementCount the element count + * @param val the value + * @return this + */ + STBTTVertex cx1(short val); + + /** + * {@return cy1} */ - public STBTTVertex(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + short cy1(); /** - * Allocates a struct with the given layout. + * Sets {@link #cy1()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBTTVertex(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBTTVertex cy1(short val); /** - * Creates a struct with the given layout. + * {@return type} + */ + byte type(); + + /** + * Sets {@link #type()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBTTVertex type(byte val); + + /** + * {@return padding} */ - public STBTTVertex(MemorySegment segment) { - super(segment, LAYOUT); - } + byte padding(); /** - * Allocates a struct with the given layout. + * Sets {@link #padding()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBTTVertex(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBTTVertex padding(byte val); } 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 9e6a3eb1..e2a42f1f 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBTrueType.java @@ -158,7 +158,7 @@ * STBTrueType stbtt = STBTrueType.INSTANCE; * Arena arena = Arena.ofAuto(); * - * STBTTBakedChar cdata = new STBTTBakedChar(arena, 96); + * STBTTBakedChar cdata = STBTTBakedChar.OF.of(arena, 96); * int ftex = 0; * * void my_stbtt_initfont() { @@ -185,17 +185,17 @@ * gl.bindTexture(GL.TEXTURE_2D, ftex); * gl.begin(GL.QUADS); * try (var stack = MemoryStack.stackPush()) { - * var q = new STBTTAlignedQuad(stack); + * var q = STBTTAlignedQuad.OF.of(stack); * var px = stack.floats(x); * var py = stack.floats(y); * for (int i = 0, c = text.codePointCount(0, text.length()); i < c; i++) { * int p = text.codePointAt(i); * if (p >= 32 && p < 128) { * stbtt.getBakedQuad(cdata, 512, 512, p - 32, px, py, q, true); //true=opengl & d3d10+,false=d3d9 - * gl.texCoord2f(q.s0.get(), q.t0.get()); gl.vertex2f(q.x0.get(), q.y0.get()); - * gl.texCoord2f(q.s1.get(), q.t0.get()); gl.vertex2f(q.x1.get(), q.y0.get()); - * gl.texCoord2f(q.s1.get(), q.t1.get()); gl.vertex2f(q.x1.get(), q.y1.get()); - * gl.texCoord2f(q.s0.get(), q.t1.get()); gl.vertex2f(q.x0.get(), q.y1.get()); + * gl.texCoord2f(q.s0(), q.t0()); gl.vertex2f(q.x0(), q.y0()); + * gl.texCoord2f(q.s1(), q.t0()); gl.vertex2f(q.x1(), q.y0()); + * gl.texCoord2f(q.s1(), q.t1()); gl.vertex2f(q.x1(), q.y1()); + * gl.texCoord2f(q.s0(), q.t1()); gl.vertex2f(q.x0(), q.y1()); * } * } * } @@ -221,7 +221,7 @@ * var stbtt = STBTrueType.INSTANCE; * var arena = Arena.ofAuto(); * - * var font = new STBTTFontInfo(arena); + * var font = STBTTFontInfo.OF.of(arena); * int c = (args.length > 0 ? Integer.parseInt(args[0]) : 'a'); * int s = (args.length > 1 ? Integer.parseInt(args[1]) : 20); * 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 b3c71d3c..feea987d 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisAlloc.java @@ -16,15 +16,12 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.invoke.MethodHandles; /** * normally stb_vorbis uses malloc() to allocate memory at startup, @@ -50,66 +47,49 @@ *

  * typedef struct
  * {
- *    char *{@link #allocBuffer alloc_buffer};
- *    int   {@link #allocBufferLengthInBytes alloc_buffer_length_in_bytes};
+ *    char *{@link #alloc_buffer};
+ *    int   {@link #alloc_buffer_length_in_bytes};
  * } stb_vorbis_alloc;
  * 
* * @author squid233 * @since 0.1.0 */ -public final class STBVorbisAlloc extends Struct { +public interface STBVorbisAlloc extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, JAVA_BYTE)).withName("alloc_buffer"), - JAVA_INT.withName("alloc_buffer_length_in_bytes") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("alloc_buffer") + .cInt("alloc_buffer_length_in_bytes") + .build() ); - /** - * alloc_buffer - */ - public static final StructHandle.Address allocBuffer = StructHandle.ofAddress(LAYOUT, "alloc_buffer"); - /** - * 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. - * - * @param segment the segment - * @param elementCount the element count + * {@return alloc_buffer} */ - public STBVorbisAlloc(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + MemorySegment alloc_buffer(); /** - * Allocates a struct with the given layout. + * Sets {@link #alloc_buffer()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBVorbisAlloc(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBVorbisAlloc alloc_buffer(MemorySegment val); /** - * Creates a struct with the given layout. - * - * @param segment the segment + * {@return alloc_buffer_length_in_bytes} */ - public STBVorbisAlloc(MemorySegment segment) { - super(segment, LAYOUT); - } + int alloc_buffer_length_in_bytes(); /** - * Allocates a struct with the given layout. + * Sets {@link #alloc_buffer_length_in_bytes()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBVorbisAlloc(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBVorbisAlloc alloc_buffer_length_in_bytes(int val); } 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 91e430a3..92ab6532 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisComment.java @@ -16,90 +16,118 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.Marshal; import overrun.marshal.Unmarshal; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.*; +import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandles; /** *

Layout

*

  * typedef struct
  * {
- *    char *{@link #vendor vendor};
+ *    char *{@link #vendor};
  *
- *    int {@link #commentListLength comment_list_length};
- *    char **{@link #commentList comment_list};
+ *    int {@link #comment_list_length};
+ *    char **{@link #comment_list};
  * } stb_vorbis_comment;
  * 
* * @author squid233 * @since 0.1.0 */ -public final class STBVorbisComment extends Struct { +public interface STBVorbisComment extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(0L, JAVA_BYTE)).withName("vendor"), - JAVA_INT.withName("comment_list_length"), - ADDRESS.withTargetLayout(ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, JAVA_BYTE))).withName("comment_list") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cAddress("vendor", MemoryLayout.sequenceLayout(Unmarshal.STR_SIZE, ValueLayout.JAVA_BYTE)) + .cInt("comment_list_length") + .cAddress("comment_list", ValueLayout.ADDRESS) + .build() ); + /** - * vendor + * {@return vendor} */ - public static final StructHandle.Array vendor = StructHandle.ofArray(LAYOUT, "vendor", Marshal::marshal, Unmarshal::unmarshalAsByteArray); + MemorySegment vendor(); + /** - * comment_list_length + * Sets {@link #vendor()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int commentListLength = StructHandle.ofInt(LAYOUT, "comment_list_length"); + STBVorbisComment vendor(MemorySegment val); + /** - * comment_list + * {@return {@link #vendor()}} */ - public static final StructHandle.Array commentList = StructHandle.ofArray(LAYOUT, "comment_list", Marshal::marshal, Unmarshal::unmarshalAsStringArray); + default String javaVendor() { + return Unmarshal.unmarshalAsString(vendor()); + } /** - * Creates a struct with the given layout. + * Sets {@link #vendor()}. * - * @param segment the segment - * @param elementCount the element count + * @param allocator the allocator + * @param val the value + * @return this */ - public STBVorbisComment(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); + default STBVorbisComment javaVendor(SegmentAllocator allocator, String val) { + return vendor(Marshal.marshal(allocator, val)); } /** - * Allocates a struct with the given layout. + * {@return comment_list_length} + */ + int comment_list_length(); + + /** + * Sets {@link #comment_list_length()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this */ - public STBVorbisComment(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + STBVorbisComment comment_list_length(int val); + + /** + * {@return comment_list} + */ + MemorySegment comment_list(); /** - * Creates a struct with the given layout. + * Sets {@link #comment_list()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBVorbisComment comment_list(MemorySegment val); + + /** + * {@return {@link #comment_list()}} */ - public STBVorbisComment(MemorySegment segment) { - super(segment, LAYOUT); + default String[] javaCommentList() { + return Unmarshal.unmarshalAsStringArray(comment_list().reinterpret(ValueLayout.ADDRESS.scale(0L, comment_list_length()))); } /** - * Allocates a struct with the given layout. + * Sets {@link #comment_list()}. * * @param allocator the allocator + * @param val the value + * @return this */ - public STBVorbisComment(SegmentAllocator allocator) { - super(allocator, LAYOUT); + default STBVorbisComment javaCommentList(SegmentAllocator allocator, String[] val) { + return comment_list(Marshal.marshal(allocator, val)); } } 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 90630566..c96738dd 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBVorbisInfo.java @@ -16,107 +16,122 @@ package overrungl.stb; +import overrun.marshal.LayoutBuilder; import overrun.marshal.struct.Struct; -import overrun.marshal.struct.StructHandle; +import overrun.marshal.struct.StructAllocator; -import java.lang.foreign.MemoryLayout; -import java.lang.foreign.MemorySegment; -import java.lang.foreign.SegmentAllocator; -import java.lang.foreign.StructLayout; - -import static java.lang.foreign.ValueLayout.JAVA_INT; +import java.lang.invoke.MethodHandles; /** *

Layout

*

  * typedef struct
  * {
- *    unsigned int {@link #sampleRate sample_rate};
- *    int {@link #channels channels};
+ *    unsigned int {@link #sample_rate};
+ *    int {@link #channels};
  *
- *    unsigned int {@link #setupMemoryRequired setup_memory_required};
- *    unsigned int {@link #setupTempMemoryRequired setup_temp_memory_required};
- *    unsigned int {@link #tempMemoryRequired temp_memory_required};
+ *    unsigned int {@link #setup_memory_required};
+ *    unsigned int {@link #setup_temp_memory_required};
+ *    unsigned int {@link #temp_memory_required};
  *
- *    int {@link #maxFrameSize max_frame_size};
+ *    int {@link #max_frame_size};
  * } stb_vorbis_info;
  * 
* * @author squid233 * @since 0.1.0 */ -public final class STBVorbisInfo extends Struct { +public interface STBVorbisInfo extends Struct { /** - * The struct layout. + * The allocator */ - public static final StructLayout LAYOUT = MemoryLayout.structLayout( - JAVA_INT.withName("sample_rate"), - JAVA_INT.withName("channels"), - JAVA_INT.withName("setup_memory_required"), - JAVA_INT.withName("setup_temp_memory_required"), - JAVA_INT.withName("temp_memory_required"), - JAVA_INT.withName("max_frame_size") + StructAllocator OF = new StructAllocator<>( + MethodHandles.lookup(), + LayoutBuilder.struct() + .cInt("sample_rate") + .cInt("channels") + .cInt("setup_memory_required") + .cInt("setup_temp_memory_required") + .cInt("temp_memory_required") + .cInt("max_frame_size") + .build() ); + /** - * sample_rate + * {@return sample_rate} */ - public static final StructHandle.Int sampleRate = StructHandle.ofInt(LAYOUT, "sample_rate"); + int sample_rate(); + /** - * channels + * Sets {@link #sample_rate()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int channels = StructHandle.ofInt(LAYOUT, "channels"); + STBVorbisInfo sample_rate(int val); + /** - * setup_memory_required + * {@return channels} */ - public static final StructHandle.Int setupMemoryRequired = StructHandle.ofInt(LAYOUT, "setup_memory_required"); + int channels(); + /** - * setup_temp_memory_required + * Sets {@link #channels()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int setupTempMemoryRequired = StructHandle.ofInt(LAYOUT, "setup_temp_memory_required"); + STBVorbisInfo channels(int val); + /** - * temp_memory_required + * {@return setup_memory_required} */ - public static final StructHandle.Int tempMemoryRequired = StructHandle.ofInt(LAYOUT, "temp_memory_required"); + int setup_memory_required(); + /** - * max_frame_size + * Sets {@link #setup_memory_required()}. + * + * @param val the value + * @return this */ - public static final StructHandle.Int maxFrameSize = StructHandle.ofInt(LAYOUT, "max_frame_size"); + STBVorbisInfo setup_memory_required(int val); /** - * Creates a struct with the given layout. - * - * @param segment the segment - * @param elementCount the element count + * {@return setup_temp_memory_required} */ - public STBVorbisInfo(MemorySegment segment, long elementCount) { - super(segment, elementCount, LAYOUT); - } + int setup_temp_memory_required(); /** - * Allocates a struct with the given layout. + * Sets {@link #setup_temp_memory_required()}. * - * @param allocator the allocator - * @param elementCount the element count + * @param val the value + * @return this + */ + STBVorbisInfo setup_temp_memory_required(int val); + + /** + * {@return temp_memory_required} */ - public STBVorbisInfo(SegmentAllocator allocator, long elementCount) { - super(allocator, elementCount, LAYOUT); - } + int temp_memory_required(); /** - * Creates a struct with the given layout. + * Sets {@link #temp_memory_required()}. * - * @param segment the segment + * @param val the value + * @return this + */ + STBVorbisInfo temp_memory_required(int val); + + /** + * {@return max_frame_size} */ - public STBVorbisInfo(MemorySegment segment) { - super(segment, LAYOUT); - } + int max_frame_size(); /** - * Allocates a struct with the given layout. + * Sets {@link #max_frame_size()}. * - * @param allocator the allocator + * @param val the value + * @return this */ - public STBVorbisInfo(SegmentAllocator allocator) { - super(allocator, LAYOUT); - } + STBVorbisInfo max_frame_size(int val); } diff --git a/modules/samples/src/main/java/overrungl/demo/glfw/GLFWJoystickTest.java b/modules/samples/src/main/java/overrungl/demo/glfw/GLFWJoystickTest.java index 14e3e0dd..711c9336 100644 --- a/modules/samples/src/main/java/overrungl/demo/glfw/GLFWJoystickTest.java +++ b/modules/samples/src/main/java/overrungl/demo/glfw/GLFWJoystickTest.java @@ -77,7 +77,7 @@ private void init() { private void loop() { var states = new GLFWGamepadState[GLFW.JOYSTICK_LAST + 1]; for (int i = 0; i < states.length; i++) { - states[i] = new GLFWGamepadState(Arena.ofAuto()); + states[i] = GLFWGamepadState.OF.of(Arena.ofAuto()); } while (!glfw.windowShouldClose(window)) { for (int i = 0; i <= GLFW.JOYSTICK_LAST; i++) { diff --git a/modules/samples/src/main/java/overrungl/demo/glfw/GLFWWindowIconTest.java b/modules/samples/src/main/java/overrungl/demo/glfw/GLFWWindowIconTest.java index fc19c51e..9835fe55 100644 --- a/modules/samples/src/main/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/main/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -76,11 +76,10 @@ private void init(Arena arena) { IOUtil.ioResourceToSegment(arena, "image.png"), px, py, pc, STBImage.RGB_ALPHA ); - final GLFWImage image = new GLFWImage(arena); - 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); + glfw.setWindowIcon(window, GLFWImage.OF.of(arena) + .width(px.get(JAVA_INT, 0)) + .height(py.get(JAVA_INT, 0)) + .pixels(data)); stbImage.free(data); } catch (IOException e) { throw new RuntimeException(e);