diff --git a/build.gradle.kts b/build.gradle.kts index 3bc534f8..0e6decf0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -202,7 +202,7 @@ subprojects { tasks.register("assembleJavadocArgs") { group = "build" - val mspFile = Path("${rootProject.buildDir}/tmp/modulesourcepath.args") + val mspFile = Path("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args") outputs.file(mspFile) doLast { @@ -222,13 +222,13 @@ tasks.register("aggregateJavadoc") { val projectsToDoc = Artifact.values().map { project(it.subprojectName) } dependsOn(projectsToDoc.map { it.getTasksByName("classes", true) }) source(projectsToDoc.map { it.sourceSets["main"].java }) - destinationDir = File("$buildDir/docs/javadoc") + destinationDir = File("${layout.buildDirectory.get().asFile}/docs/javadoc") classpath = files(projectsToDoc.map { it.configurations["compileClasspath"].files }) executable = project.findProperty("javadocExecutable") as String? - options.optionFiles = listOf(File("${rootProject.buildDir}/tmp/modulesourcepath.args")) + options.optionFiles = listOf(File("${rootProject.layout.buildDirectory.get().asFile}/tmp/modulesourcepath.args")) } allprojects { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9f4197d5..ac72c34e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java b/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java index dd82127e..a4afe4c2 100644 --- a/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java +++ b/modules/overrungl.core/src/main/java/overrungl/FunctionDescriptors.java @@ -16,7 +16,7 @@ package overrungl; -import overrungl.internal.RuntimeHelper; +import overrungl.util.MemoryUtil; import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.ValueLayout; @@ -122,7 +122,7 @@ public static ValueLayout ofValue(char c) throws IllegalArgumentException { case 'F' -> JAVA_FLOAT; case 'D' -> JAVA_DOUBLE; case 'P' -> ADDRESS; - case 'p' -> RuntimeHelper.ADDRESS_UNBOUNDED; + case 'p' -> MemoryUtil.ADDRESS_UNBOUNDED; default -> throw new IllegalArgumentException( STR."Invalid argument c: expected one of B, S, I, J, C, Z, F, D, P or p; got '\{c}'" diff --git a/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java b/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java index cef3861e..058d20c3 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/CheckUtil.java @@ -107,43 +107,4 @@ public static void checkNotNullptr(MemorySegment segment, Supplier messa public static void checkNotNullptr(MemorySegment segment, String message) throws IllegalStateException { if (MemoryUtil.isNullptr(segment)) throw new IllegalStateException(message); } - - /** - * Checks whether the given object is not {@code null}. - * - * @param o the object. - * @throws IllegalStateException if {@code object} is {@code null}. - * @see #checkNotNull(Object, Supplier) - * @see #checkNotNull(Object, String) - */ - public static void checkNotNull(Object o) throws IllegalStateException { - checkNotNull(o, "condition == false"); - } - - /** - * Checks whether the given object is not {@code null}. The message of the exception is wrapped in a supplier - * to avoid side effect. - * - * @param o the object. - * @param messageSupplier the message supplier of the exception. - * @throws IllegalStateException if {@code object} is {@code null}. - * @see #checkNotNull(Object) - * @see #checkNotNull(Object, String) - */ - public static void checkNotNull(Object o, Supplier messageSupplier) throws IllegalStateException { - if (o == null) throw new IllegalStateException(messageSupplier.get()); - } - - /** - * Checks whether the given object is not {@code null}. - * - * @param o the object. - * @param message the message of the exception. - * @throws IllegalStateException if {@code object} is {@code null}. - * @see #checkNotNull(Object) - * @see #checkNotNull(Object, Supplier) - */ - public static void checkNotNull(Object o, String message) throws IllegalStateException { - if (o == null) throw new IllegalStateException(message); - } } diff --git a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java index d7cff750..c9fdb7c8 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/MemoryStack.java @@ -16,7 +16,6 @@ package overrungl.util; -import org.jetbrains.annotations.Nullable; import overrungl.Configurations; import overrungl.OverrunGL; import overrungl.Pointer; @@ -40,7 +39,7 @@ * @see Configurations#DEBUG_STACK * @since 0.1.0 */ -public sealed class MemoryStack extends Pointer implements SegmentAllocator, AutoCloseable { +public sealed class MemoryStack extends Pointer implements Arena { private static final boolean DEBUG = Configurations.DEBUG.get(); private static final boolean DEBUG_STACK = Configurations.DEBUG_STACK.get(); private static final long DEFAULT_STACK_SIZE = Configurations.STACK_SIZE.get() * 1024; @@ -52,10 +51,6 @@ public sealed class MemoryStack extends Pointer implements SegmentAllocator, Aut CheckUtil.check(DEFAULT_STACK_FRAMES > 0, "Invalid stack frames."); } - @SuppressWarnings({"FieldCanBeLocal", "unused"}) - @Nullable - private final MemorySegment container; - private final long size; private long pointer; @@ -68,13 +63,11 @@ public sealed class MemoryStack extends Pointer implements SegmentAllocator, Aut * *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

* - * @param container the backing memory buffer, may be null - * @param address the backing memory address - * @param size the backing memory size + * @param address the backing memory address + * @param size the backing memory size */ - protected MemoryStack(@Nullable MemorySegment container, MemorySegment address, long size) { + protected MemoryStack(MemorySegment address, long size) { super(address); - this.container = container; this.size = size; this.pointer = size; @@ -124,22 +117,8 @@ public static MemoryStack create(long capacity, Arena arena) { */ public static MemoryStack create(MemorySegment buffer, long size) { return DEBUG_STACK - ? new DebugMemoryStack(buffer, buffer, size) - : new MemoryStack(buffer, buffer, size); - } - - /** - * Creates a new {@code MemoryStack} backed by the specified memory region. - * - *

In the initial state, there is no active stack frame. The {@link #push} method must be used before any allocations.

- * - * @param address the backing memory address - * @param size the backing memory size - */ - public static MemoryStack ncreate(MemorySegment address, long size) { - return DEBUG_STACK - ? new DebugMemoryStack(null, address, size) - : new MemoryStack(null, address, size); + ? new DebugMemoryStack(buffer, size) + : new MemoryStack(buffer, size); } /** @@ -183,6 +162,11 @@ public MemoryStack pop() { return this; } + @Override + public MemorySegment.Scope scope() { + return address().scope(); + } + /** * Calls {@link #pop} on this {@code MemoryStack}. * @@ -202,8 +186,8 @@ public void close() { private static final class DebugMemoryStack extends MemoryStack { private Object[] debugFrames; - DebugMemoryStack(@Nullable MemorySegment buffer, MemorySegment address, long size) { - super(buffer, address, size); + DebugMemoryStack(MemorySegment address, long size) { + super(address, size); debugFrames = new Object[DEFAULT_STACK_FRAMES]; } @@ -326,7 +310,11 @@ private void checkPointer(long pointer) { * @param size the allocation size * @return the memory address on the stack for the requested allocation */ - public MemorySegment nmalloc(long alignment, long size) { + public MemorySegment malloc(long alignment, long size) { + if (DEBUG) { + MemoryUtil.checkAlignment(alignment); + } + // Align address to the specified alignment long rawLong = address().address(); long address = (rawLong + pointer - size) & -alignment; @@ -349,35 +337,22 @@ public MemorySegment nmalloc(long alignment, long size) { * @return the memory address on the stack for the requested allocation */ public MemorySegment ncalloc(long alignment, long num, long size) { + if (DEBUG) { + MemoryUtil.checkAlignment(alignment); + } + long bytes = num * size; - var address = nmalloc(alignment, bytes); + var address = malloc(alignment, bytes); address.fill((byte) 0); return address; } // ------------------------------------------------- - /** - * Allocates an aligned {@link MemorySegment} on the stack. - * - * @param alignment the required buffer alignment - * @param size the number of elements in the buffer - * @return the allocated buffer - */ - public MemorySegment malloc(long alignment, long size) { - if (DEBUG) { - MemoryUtil.checkAlignment(alignment); - } - return nmalloc(alignment, size); - } - /** * Calloc version of {@link #malloc(long, long)}. */ public MemorySegment calloc(long alignment, long size) { - if (DEBUG) { - MemoryUtil.checkAlignment(alignment); - } return ncalloc(alignment, 1, size); } @@ -388,28 +363,200 @@ public MemorySegment calloc(long alignment, long size) { * @return the memory address on the stack for the requested allocation */ public MemorySegment malloc(long size) { - return nmalloc(ADDRESS.byteSize(), size); + return malloc(ADDRESS.byteAlignment(), size); + } + + public MemorySegment malloc(MemoryLayout layout, long num) { + return malloc(layout.byteAlignment(), num * layout.byteSize()); } public MemorySegment malloc(MemoryLayout layout) { - return malloc(layout.byteSize()); + return malloc(layout.byteAlignment(), layout.byteSize()); } /** * Calloc version of {@link #malloc(long)}. */ public MemorySegment calloc(long size) { - return ncalloc(ADDRESS.byteSize(), 1, size); + return ncalloc(ADDRESS.byteAlignment(), 1, size); } public MemorySegment calloc(MemoryLayout layout, long num) { - return ncalloc(ADDRESS.byteSize(), num, layout.byteSize()); + return ncalloc(layout.byteAlignment(), num, layout.byteSize()); } public MemorySegment calloc(MemoryLayout layout) { return calloc(layout, 1); } + /** + * Short version of {@link #malloc(long)}. + */ + public MemorySegment mallocShort(long size) { + return malloc(JAVA_SHORT, size); + } + + /** + * Short version of {@link #calloc(long)}. + */ + public MemorySegment callocShort(long size) { + return calloc(JAVA_SHORT, size); + } + + /** + * Int version of {@link #malloc(long)}. + */ + public MemorySegment mallocInt(long size) { + return malloc(JAVA_INT, size); + } + + /** + * Int version of {@link #calloc(long)}. + */ + public MemorySegment callocInt(long size) { + return calloc(JAVA_INT, size); + } + + /** + * Long version of {@link #malloc(long)}. + */ + public MemorySegment mallocLong(long size) { + return malloc(JAVA_LONG, size); + } + + /** + * Long version of {@link #calloc(long)}. + */ + public MemorySegment callocLong(long size) { + return calloc(JAVA_LONG, size); + } + + /** + * Float version of {@link #malloc(long)}. + */ + public MemorySegment mallocFloat(long size) { + return malloc(JAVA_FLOAT, size); + } + + /** + * Float version of {@link #calloc(long)}. + */ + public MemorySegment callocFloat(long size) { + return calloc(JAVA_FLOAT, size); + } + + /** + * Double version of {@link #malloc(long)}. + */ + public MemorySegment mallocDouble(long size) { + return malloc(JAVA_DOUBLE, size); + } + + /** + * Double version of {@link #calloc(long)}. + */ + public MemorySegment callocDouble(long size) { + return calloc(JAVA_DOUBLE, size); + } + + /** + * Pointer version of {@link #malloc(long)}. + */ + public MemorySegment mallocPointer(long size) { + return malloc(ADDRESS, size); + } + + /** + * Pointer version of {@link #calloc(long)}. + */ + public MemorySegment callocPointer(long size) { + return calloc(ADDRESS, size); + } + + /** + * Short version of {@link #malloc(long)}. + */ + public MemorySegment mallocShort() { + return malloc(JAVA_SHORT, 1); + } + + /** + * Short version of {@link #calloc(long)}. + */ + public MemorySegment callocShort() { + return calloc(JAVA_SHORT, 1); + } + + /** + * Int version of {@link #malloc(long)}. + */ + public MemorySegment mallocInt() { + return malloc(JAVA_INT, 1); + } + + /** + * Int version of {@link #calloc(long)}. + */ + public MemorySegment callocInt() { + return calloc(JAVA_INT, 1); + } + + /** + * Long version of {@link #malloc(long)}. + */ + public MemorySegment mallocLong() { + return malloc(JAVA_LONG, 1); + } + + /** + * Long version of {@link #calloc(long)}. + */ + public MemorySegment callocLong() { + return calloc(JAVA_LONG, 1); + } + + /** + * Float version of {@link #malloc(long)}. + */ + public MemorySegment mallocFloat() { + return malloc(JAVA_FLOAT, 1); + } + + /** + * Float version of {@link #calloc(long)}. + */ + public MemorySegment callocFloat() { + return calloc(JAVA_FLOAT, 1); + } + + /** + * Double version of {@link #malloc(long)}. + */ + public MemorySegment mallocDouble() { + return malloc(JAVA_DOUBLE, 1); + } + + /** + * Double version of {@link #calloc(long)}. + */ + public MemorySegment callocDouble() { + return calloc(JAVA_DOUBLE, 1); + } + + /** + * Pointer version of {@link #malloc(long)}. + */ + public MemorySegment mallocPointer() { + return malloc(ADDRESS, 1); + } + + /** + * Pointer version of {@link #calloc(long)}. + */ + public MemorySegment callocPointer() { + return calloc(ADDRESS, 1); + } + @Override public MemorySegment allocate(long byteSize, long byteAlignment) throws IllegalArgumentException { MemoryUtil.checkByteSize(byteSize); @@ -818,10 +965,10 @@ public static MemoryStack stackPop() { } /** - * Thread-local version of {@link #nmalloc(long, long)}. + * Thread-local version of {@link #malloc(long, long)}. */ - public static MemorySegment nstackMalloc(long alignment, long size) { - return stackGet().nmalloc(alignment, size); + public static MemorySegment stackMalloc(long alignment, long size) { + return stackGet().malloc(alignment, size); } /** diff --git a/modules/overrungl.core/src/main/java/overrungl/util/MemoryUtil.java b/modules/overrungl.core/src/main/java/overrungl/util/MemoryUtil.java index 7f1d60d0..569cc35b 100644 --- a/modules/overrungl.core/src/main/java/overrungl/util/MemoryUtil.java +++ b/modules/overrungl.core/src/main/java/overrungl/util/MemoryUtil.java @@ -34,6 +34,10 @@ * @since 0.1.0 */ public final class MemoryUtil { + /** + * An unbounded address layout. + */ + public static final AddressLayout ADDRESS_UNBOUNDED = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE)); private static final SymbolLookup LOOKUP = RuntimeHelper.LINKER.defaultLookup(); private static final MethodHandle m_malloc = downcall("malloc", JP), @@ -48,10 +52,6 @@ public final class MemoryUtil { * The address of {@code NULL}. */ public static final long NULL = 0x0L; - /** - * An unbounded address layout. - */ - public static final AddressLayout ADDRESS_UNBOUNDED = ValueLayout.ADDRESS.withTargetLayout(MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE)); private static MethodHandle downcall(String name, FunctionDescriptors function) { return RuntimeHelper.downcallThrow(LOOKUP.find(name), function); @@ -61,17 +61,6 @@ private MemoryUtil() { throw new IllegalStateException("Do not construct instance"); } - /** - * {@return a segment allocator of this} - * The returned memory must be released explicitly by {@link #free(MemorySegment)}. - */ - public static SegmentAllocator segmentAllocator() { - class Holder { - private static final SegmentAllocator ALLOCATOR = (byteSize, byteAlignment) -> calloc(byteSize / byteAlignment, byteAlignment); - } - return Holder.ALLOCATOR; - } - /** * {@return {@code true} if {@code segment} is a null pointer} * 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 4011e222..bfc4465a 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFW.java @@ -26,6 +26,7 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; +import java.lang.invoke.VarHandle; import static java.lang.foreign.ValueLayout.*; import static overrungl.glfw.Handles.*; @@ -1007,9 +1008,9 @@ public static void getVersion(int @Nullable [] major, int @Nullable [] minor, in var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pMajor = major != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pMinor = minor != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pRev = rev != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var pMajor = major != null ? stack.callocInt() : MemorySegment.NULL; + var pMinor = minor != null ? stack.callocInt() : MemorySegment.NULL; + var pRev = rev != null ? stack.callocInt() : MemorySegment.NULL; ngetVersion(pMajor, pMinor, pRev); if (major != null && major.length > 0) { major[0] = pMajor.get(JAVA_INT, 0); @@ -1035,9 +1036,9 @@ public static Triplet.OfInt getVersion() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pMajor = stack.calloc(JAVA_INT); - var pMinor = stack.calloc(JAVA_INT); - var pRev = stack.calloc(JAVA_INT); + var pMajor = stack.callocInt(); + var pMinor = stack.callocInt(); + var pRev = stack.callocInt(); ngetVersion(pMajor, pMinor, pRev); return new Triplet.OfInt(pMajor.get(JAVA_INT, 0), pMinor.get(JAVA_INT, 0), @@ -1122,7 +1123,7 @@ public static int getError(String @Nullable [] description) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = description != null ? stack.malloc(ADDRESS) : MemorySegment.NULL; + final MemorySegment seg = description != null ? stack.mallocPointer() : MemorySegment.NULL; final int err = ngetError(seg); if (description != null && description.length > 0) { description[0] = RuntimeHelper.unboundPointerString(seg); @@ -1143,7 +1144,7 @@ public static Tuple2.OfObjInt getError() { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.malloc(ADDRESS); + final MemorySegment seg = stack.mallocPointer(); final int err = ngetError(seg); return new Tuple2.OfObjInt<>(RuntimeHelper.unboundPointerString(seg), err); } finally { @@ -1235,7 +1236,7 @@ public static MemorySegment ngetMonitors(MemorySegment count) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); var pMonitors = ngetMonitors(pCount); return RuntimeHelper.isNullptr(pMonitors) ? null : @@ -1303,8 +1304,8 @@ public static void getMonitorPos(MemorySegment monitor, int @Nullable [] xpos, i var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xpos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var py = ypos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; + var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; ngetMonitorPos(monitor, px, py); if (xpos != null && xpos.length > 0) { xpos[0] = px.get(JAVA_INT, 0); @@ -1328,8 +1329,8 @@ public static Pair.OfInt getMonitorPos(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); ngetMonitorPos(monitor, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); } finally { @@ -1381,10 +1382,10 @@ public static void getMonitorWorkarea(MemorySegment monitor, int @Nullable [] xp var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xpos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var py = ypos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pw = width != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var ph = height != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; + var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; + var pw = width != null ? stack.callocInt() : MemorySegment.NULL; + var ph = height != null ? stack.callocInt() : MemorySegment.NULL; ngetMonitorWorkarea(monitor, px, py, pw, ph); if (xpos != null && xpos.length > 0) { xpos[0] = px.get(JAVA_INT, 0); @@ -1414,10 +1415,10 @@ public static Quad.OfInt getMonitorWorkarea(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pw = stack.calloc(JAVA_INT); - var ph = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pw = stack.callocInt(); + var ph = stack.callocInt(); ngetMonitorWorkarea(monitor, px, py, pw, ph); return new Quad.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0), @@ -1474,8 +1475,8 @@ public static void getMonitorPhysicalSize(MemorySegment monitor, int @Nullable [ var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = widthMM != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var ph = heightMM != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var pw = widthMM != null ? stack.callocInt() : MemorySegment.NULL; + var ph = heightMM != null ? stack.callocInt() : MemorySegment.NULL; ngetMonitorPhysicalSize(monitor, pw, ph); if (widthMM != null && widthMM.length > 0) { widthMM[0] = pw.get(JAVA_INT, 0); @@ -1499,8 +1500,8 @@ public static Pair.OfInt getMonitorPhysicalSize(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = stack.calloc(JAVA_INT); - var ph = stack.calloc(JAVA_INT); + var pw = stack.callocInt(); + var ph = stack.callocInt(); ngetMonitorPhysicalSize(monitor, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); } finally { @@ -1551,8 +1552,8 @@ public static void getMonitorContentScale(MemorySegment monitor, float @Nullable var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xscale != null ? stack.calloc(JAVA_FLOAT) : MemorySegment.NULL; - var py = yscale != null ? stack.calloc(JAVA_FLOAT) : MemorySegment.NULL; + var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; + var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; ngetMonitorContentScale(monitor, px, py); if (xscale != null && xscale.length > 0) { xscale[0] = px.get(JAVA_FLOAT, 0); @@ -1576,8 +1577,8 @@ public static Pair.OfFloat getMonitorContentScale(MemorySegment monitor) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_FLOAT); - var py = stack.calloc(JAVA_FLOAT); + var px = stack.callocFloat(); + var py = stack.callocFloat(); ngetMonitorContentScale(monitor, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); } finally { @@ -1752,7 +1753,7 @@ public static MemorySegment ngetVideoModes(MemorySegment monitor, MemorySegment var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); var pModes = ngetVideoModes(monitor, pCount); return RuntimeHelper.isNullptr(pModes) ? null : @@ -2453,8 +2454,8 @@ public static void getWindowPos(MemorySegment window, int @Nullable [] xpos, int var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xpos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var py = ypos != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var px = xpos != null ? stack.callocInt() : MemorySegment.NULL; + var py = ypos != null ? stack.callocInt() : MemorySegment.NULL; ngetWindowPos(window, px, py); if (xpos != null && xpos.length > 1) { xpos[0] = px.get(JAVA_INT, 0); @@ -2477,8 +2478,8 @@ public static Pair.OfInt getWindowPos(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); ngetWindowPos(window, px, py); return new Pair.OfInt(px.get(JAVA_INT, 0), py.get(JAVA_INT, 0)); } finally { @@ -2561,8 +2562,8 @@ public static void getWindowSize(MemorySegment window, int @Nullable [] width, i var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = width != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var ph = height != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var pw = width != null ? stack.callocInt() : MemorySegment.NULL; + var ph = height != null ? stack.callocInt() : MemorySegment.NULL; ngetWindowSize(window, pw, ph); if (width != null && width.length > 0) { width[0] = pw.get(JAVA_INT, 0); @@ -2586,8 +2587,8 @@ public static Pair.OfInt getWindowSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = stack.calloc(JAVA_INT); - var ph = stack.calloc(JAVA_INT); + var pw = stack.callocInt(); + var ph = stack.callocInt(); ngetWindowSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); } finally { @@ -2758,8 +2759,8 @@ public static void getFramebufferSize(MemorySegment window, int @Nullable [] wid var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = width != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var ph = height != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var pw = width != null ? stack.callocInt() : MemorySegment.NULL; + var ph = height != null ? stack.callocInt() : MemorySegment.NULL; ngetFramebufferSize(window, pw, ph); if (width != null && width.length > 0) { width[0] = pw.get(JAVA_INT, 0); @@ -2783,8 +2784,8 @@ public static Pair.OfInt getFramebufferSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pw = stack.calloc(JAVA_INT); - var ph = stack.calloc(JAVA_INT); + var pw = stack.callocInt(); + var ph = stack.callocInt(); ngetFramebufferSize(window, pw, ph); return new Pair.OfInt(pw.get(JAVA_INT, 0), ph.get(JAVA_INT, 0)); } finally { @@ -2847,10 +2848,10 @@ public static void getWindowFrameSize(MemorySegment window, int @Nullable [] lef var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pl = left != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pt = top != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pr = right != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pb = bottom != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + var pl = left != null ? stack.callocInt() : MemorySegment.NULL; + var pt = top != null ? stack.callocInt() : MemorySegment.NULL; + var pr = right != null ? stack.callocInt() : MemorySegment.NULL; + var pb = bottom != null ? stack.callocInt() : MemorySegment.NULL; ngetWindowFrameSize(window, pl, pt, pr, pb); if (left != null && left.length > 0) { left[0] = pl.get(JAVA_INT, 0); @@ -2881,10 +2882,10 @@ public static Quad.OfInt getWindowFrameSize(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pl = stack.calloc(JAVA_INT); - var pt = stack.calloc(JAVA_INT); - var pr = stack.calloc(JAVA_INT); - var pb = stack.calloc(JAVA_INT); + var pl = stack.callocInt(); + var pt = stack.callocInt(); + var pr = stack.callocInt(); + var pb = stack.callocInt(); ngetWindowFrameSize(window, pl, pt, pr, pb); return new Quad.OfInt(pl.get(JAVA_INT, 0), pt.get(JAVA_INT, 0), @@ -2939,8 +2940,8 @@ public static void getWindowContentScale(MemorySegment window, float @Nullable [ var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xscale != null ? stack.calloc(JAVA_FLOAT) : MemorySegment.NULL; - var py = yscale != null ? stack.calloc(JAVA_FLOAT) : MemorySegment.NULL; + var px = xscale != null ? stack.callocFloat() : MemorySegment.NULL; + var py = yscale != null ? stack.callocFloat() : MemorySegment.NULL; ngetWindowContentScale(window, px, py); if (xscale != null && xscale.length > 0) { xscale[0] = px.get(JAVA_FLOAT, 0); @@ -2964,8 +2965,8 @@ public static Pair.OfFloat getWindowContentScale(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_FLOAT); - var py = stack.calloc(JAVA_FLOAT); + var px = stack.callocFloat(); + var py = stack.callocFloat(); ngetWindowContentScale(window, px, py); return new Pair.OfFloat(px.get(JAVA_FLOAT, 0), py.get(JAVA_FLOAT, 0)); } finally { @@ -4270,8 +4271,8 @@ public static void getCursorPos(MemorySegment window, double @Nullable [] xpos, var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = xpos != null ? stack.calloc(JAVA_DOUBLE) : MemorySegment.NULL; - var py = ypos != null ? stack.calloc(JAVA_DOUBLE) : MemorySegment.NULL; + var px = xpos != null ? stack.callocDouble() : MemorySegment.NULL; + var py = ypos != null ? stack.callocDouble() : MemorySegment.NULL; ngetCursorPos(window, px, py); if (xpos != null && xpos.length > 0) { xpos[0] = px.get(JAVA_DOUBLE, 0); @@ -4296,8 +4297,8 @@ public static Pair.OfDouble getCursorPos(MemorySegment window) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_DOUBLE); - var py = stack.calloc(JAVA_DOUBLE); + var px = stack.callocDouble(); + var py = stack.callocDouble(); ngetCursorPos(window, px, py); return new Pair.OfDouble(px.get(JAVA_DOUBLE, 0), py.get(JAVA_DOUBLE, 0)); } finally { @@ -4861,7 +4862,7 @@ public static MemorySegment ngetJoystickAxes(int jid, MemorySegment count) { MemorySegment pAxes; final int count; try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); pAxes = ngetJoystickAxes(jid, pCount); count = pCount.get(JAVA_INT, 0); } finally { @@ -4923,7 +4924,7 @@ public static MemorySegment ngetJoystickButtons(int jid, MemorySegment count) { MemorySegment pButtons; final int count; try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); pButtons = ngetJoystickButtons(jid, pCount); count = pCount.get(JAVA_INT, 0); } finally { @@ -5004,7 +5005,7 @@ public static byte[] getJoystickHats(int jid) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); var pHats = ngetJoystickHats(jid, pCount); return RuntimeHelper.toArray(pHats, new byte[pCount.get(JAVA_INT, 0)]); } finally { @@ -5874,7 +5875,7 @@ public static MemorySegment ngetRequiredInstanceExtensions(MemorySegment count) MemorySegment pExt; final int count; try { - var pCount = stack.calloc(JAVA_INT); + var pCount = stack.callocInt(); pExt = ngetRequiredInstanceExtensions(pCount); count = pCount.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java index 700ba274..04c3db79 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWNative.java @@ -535,10 +535,10 @@ public static boolean getOSMesaColorBuffer(MemorySegment window, int @Nullable [ final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment pWidth = width != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pHeight = height != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pFormat = format != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pBuffer = buffer != null ? stack.calloc(ValueLayout.ADDRESS) : MemorySegment.NULL; + final MemorySegment pWidth = width != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pHeight = height != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pFormat = format != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pBuffer = buffer != null ? stack.callocPointer() : MemorySegment.NULL; final boolean success = ngetOSMesaColorBuffer(window, pWidth, pHeight, pFormat, pBuffer); if (width != null && width.length > 0) { width[0] = pWidth.get(ValueLayout.JAVA_INT, 0); @@ -600,10 +600,10 @@ public static boolean getOSMesaDepthBuffer(MemorySegment window, int @Nullable [ final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment pWidth = width != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pHeight = height != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pBPV = bytesPerValue != null ? stack.calloc(ValueLayout.JAVA_INT) : MemorySegment.NULL; - final MemorySegment pBuffer = buffer != null ? stack.calloc(ValueLayout.ADDRESS) : MemorySegment.NULL; + final MemorySegment pWidth = width != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pHeight = height != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pBPV = bytesPerValue != null ? stack.callocInt() : MemorySegment.NULL; + final MemorySegment pBuffer = buffer != null ? stack.callocPointer() : MemorySegment.NULL; final boolean success = ngetOSMesaDepthBuffer(window, pWidth, pHeight, pBPV, pBuffer); if (width != null && width.length > 0) { width[0] = pWidth.get(ValueLayout.JAVA_INT, 0); diff --git a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java index 4a79afd5..afa7c88c 100644 --- a/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java +++ b/modules/overrungl.glfw/src/main/java/overrungl/glfw/GLFWVulkan.java @@ -217,7 +217,7 @@ public static int glfwCreateWindowSurface(MemorySegment instance, MemorySegment var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pSurface = stack.calloc(ValueLayout.JAVA_LONG); + var pSurface = stack.callocLong(); int result = nglfwCreateWindowSurface(instance, window, allocator, pSurface); surface[0] = pSurface.get(ValueLayout.JAVA_LONG, 0); return result; 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 14ccc1f7..d69db9f7 100644 --- a/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java +++ b/modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java @@ -272,7 +272,7 @@ public static NFDResult openDialogN(String[] outPath, NFDNFilterItem.Buffer filt final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = nopenDialogN(seg, filterList != null ? filterList.address() : MemorySegment.NULL, filterList != null ? Math.toIntExact(filterList.elementCount()) : 0, @@ -356,7 +356,7 @@ public static NFDResult saveDialogN(String[] outPath, NFDNFilterItem.Buffer filt final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = nsaveDialogN(seg, filterList != null ? filterList.address() : MemorySegment.NULL, filterList != null ? Math.toIntExact(filterList.elementCount()) : 0, @@ -401,7 +401,7 @@ public static NFDResult pickFolderN(String[] outPath, String defaultPath) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npickFolderN(seg, defaultPath != null ? allocateString(defaultPath) : MemorySegment.NULL); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); @@ -554,7 +554,7 @@ public static NFDResult pathSetGetPathN(@NativeType("const nfdpathset_t*") Memor final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npathSetGetPathN(pathSet, index, seg); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); @@ -643,7 +643,7 @@ public static NFDResult pathSetEnumNextN(@NativeType("nfdpathsetenum_t*") Memory final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npathSetEnumNextN(enumerator, seg); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); @@ -719,7 +719,7 @@ public static NFDResult openDialogU8(String[] outPath, NFDU8FilterItem.Buffer fi final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = nopenDialogU8(seg, filterList != null ? filterList.address() : MemorySegment.NULL, filterList != null ? Math.toIntExact(filterList.elementCount()) : 0, @@ -813,7 +813,7 @@ public static NFDResult saveDialogU8(String[] outPath, NFDU8FilterItem.Buffer fi final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = nsaveDialogU8(seg, filterList != null ? filterList.address() : MemorySegment.NULL, filterList != null ? Math.toIntExact(filterList.elementCount()) : 0, @@ -860,7 +860,7 @@ public static NFDResult pickFolderU8(String[] outPath, String defaultPath) { final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npickFolderU8(seg, defaultPath != null ? stack.allocateUtf8String(defaultPath) : MemorySegment.NULL); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); @@ -910,7 +910,7 @@ public static NFDResult pathSetGetPathU8(@NativeType("const nfdpathset_t*") Memo final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npathSetGetPathU8(pathSet, index, seg); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); @@ -956,7 +956,7 @@ public static NFDResult pathSetEnumNextU8(@NativeType("nfdpathsetenum_t*") Memor final MemoryStack stack = MemoryStack.stackGet(); final long stackPointer = stack.getPointer(); try { - final MemorySegment seg = stack.calloc(ADDRESS); + final MemorySegment seg = stack.callocPointer(); final NFDResult result = npathSetEnumNextU8(enumerator, seg); if (result == NFDResult.OKAY) { final MemorySegment path = seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java index 9b008943..c62d601b 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10.java @@ -1028,14 +1028,9 @@ public static double[] getClipPlane(int plane) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pEq = stack.calloc(JAVA_DOUBLE, 4); + var pEq = stack.callocDouble(4); getClipPlane(plane, pEq); - return new double[]{ - pEq.get(JAVA_DOUBLE, 0), - pEq.getAtIndex(JAVA_DOUBLE, 1), - pEq.getAtIndex(JAVA_DOUBLE, 2), - pEq.getAtIndex(JAVA_DOUBLE, 3) - }; + return RuntimeHelper.toArray(pEq, new double[4]); } finally { stack.setPointer(stackPointer); } @@ -1060,7 +1055,7 @@ public static float getLightf(int light, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getLightfv(light, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -1087,7 +1082,7 @@ public static int getLighti(int light, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getLightiv(light, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { @@ -1114,7 +1109,7 @@ public static double getMapd(int target, int query) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pv = stack.calloc(JAVA_DOUBLE); + var pv = stack.callocDouble(); getMapdv(target, query, pv); return pv.get(JAVA_DOUBLE, 0); } finally { @@ -1141,7 +1136,7 @@ public static float getMapf(int target, int query) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pv = stack.calloc(JAVA_FLOAT); + var pv = stack.callocFloat(); getMapfv(target, query, pv); return pv.get(JAVA_FLOAT, 0); } finally { @@ -1168,7 +1163,7 @@ public static int getMapi(int target, int query) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pv = stack.calloc(JAVA_INT); + var pv = stack.callocInt(); getMapiv(target, query, pv); return pv.get(JAVA_INT, 0); } finally { @@ -1195,7 +1190,7 @@ public static float getMaterialf(int face, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getMaterialfv(face, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -1222,7 +1217,7 @@ public static int getMateriali(int face, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getMaterialiv(face, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { @@ -1309,7 +1304,7 @@ public static float getTexEnvf(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getTexEnvfv(target, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -1336,7 +1331,7 @@ public static int getTexEnvi(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getTexEnviv(target, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java index ac83d55d..1f16f453 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL10C.java @@ -464,7 +464,7 @@ public static double getDouble(int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pData = stack.calloc(JAVA_DOUBLE); + var pData = stack.callocDouble(); getDoublev(pname, pData); return pData.get(JAVA_DOUBLE, 0); } finally { @@ -500,7 +500,7 @@ public static float getFloat(int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pData = stack.calloc(JAVA_FLOAT); + var pData = stack.callocFloat(); getFloatv(pname, pData); return pData.get(JAVA_FLOAT, 0); } finally { @@ -527,7 +527,7 @@ public static int getInteger(int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pData = stack.calloc(JAVA_INT); + var pData = stack.callocInt(); getIntegerv(pname, pData); return pData.get(JAVA_INT, 0); } finally { @@ -578,7 +578,7 @@ public static float getTexLevelParameterf(int target, int level, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getTexLevelParameterfv(target, level, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -605,7 +605,7 @@ public static int getTexLevelParameteri(int target, int level, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getTexLevelParameteriv(target, level, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { @@ -632,7 +632,7 @@ public static float getTexParameterf(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getTexParameterfv(target, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -659,7 +659,7 @@ public static int getTexParameteri(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getTexParameteriv(target, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java index a48314fa..1ccadb33 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL11C.java @@ -209,7 +209,7 @@ public static int genTexture() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pTex = stack.calloc(JAVA_INT); + var pTex = stack.callocInt(); genTextures(1, pTex); return pTex.get(JAVA_INT, 0); } finally { @@ -230,7 +230,7 @@ public static MemorySegment getPointer(int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(ADDRESS); + var pParams = stack.callocPointer(); getPointerv(pname, pParams); return pParams.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java index 2f5e6d2b..69fe470c 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL15C.java @@ -266,7 +266,7 @@ public static int genBuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genBuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -293,7 +293,7 @@ public static int genQuery() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genQueries(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -314,7 +314,7 @@ public static int getBufferParameteri(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getBufferParameteriv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -335,7 +335,7 @@ public static MemorySegment getBufferPointer(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(ADDRESS); + var seg = stack.callocPointer(); getBufferPointerv(target, pname, seg); return seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); } finally { @@ -401,7 +401,7 @@ public static int getQueryObjecti(int id, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getQueryObjectiv(id, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -422,7 +422,7 @@ public static int getQueryObjectui(int id, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getQueryObjectuiv(id, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -443,7 +443,7 @@ public static int getQueryi(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getQueryiv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java index 433a693c..99d60b1f 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL20C.java @@ -23,6 +23,7 @@ import overrungl.internal.RuntimeHelper; import overrungl.util.MemoryStack; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; import java.lang.foreign.SegmentAllocator; @@ -455,18 +456,29 @@ public static void getProgramInfoLog(int program, int bufSize, MemorySegment len } } - public static String getProgramInfoLog(SegmentAllocator allocator, int program, int bufSize, int @Nullable [] length) { - var pLen = length != null ? allocator.allocate(JAVA_INT) : MemorySegment.NULL; - var pLog = allocator.allocateArray(JAVA_BYTE, bufSize); - getProgramInfoLog(program, bufSize, pLen, pLog); - if (length != null && length.length > 0) { - length[0] = pLen.get(JAVA_INT, 0); + public static String getProgramInfoLog(int program, int bufSize, int @Nullable [] length) { + final MemoryStack stack = MemoryStack.stackGet(); + final long stackPointer = stack.getPointer(); + try { + var pLen = length != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; + final Arena allocator = stack.getPointer() < bufSize ? Arena.ofConfined() : stack; + try { + var pLog = allocator.allocateArray(JAVA_BYTE, bufSize); + getProgramInfoLog(program, bufSize, pLen, pLog); + if (length != null && length.length > 0) { + length[0] = pLen.get(JAVA_INT, 0); + } + return pLog.getUtf8String(0); + } finally { + if (!(allocator instanceof MemoryStack)) allocator.close(); + } + } finally { + stack.setPointer(stackPointer); } - return pLog.getUtf8String(0); } - public static String getProgramInfoLog(SegmentAllocator allocator, int program) { - return getProgramInfoLog(allocator, program, getProgrami(program, INFO_LOG_LENGTH), null); + public static String getProgramInfoLog(int program) { + return getProgramInfoLog(program, getProgrami(program, INFO_LOG_LENGTH), null); } public static void getProgramiv(int program, int pname, MemorySegment params) { @@ -488,7 +500,7 @@ public static int getProgrami(int program, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getProgramiv(program, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -505,18 +517,29 @@ public static void getShaderInfoLog(int shader, int bufSize, MemorySegment lengt } } - public static String getShaderInfoLog(SegmentAllocator allocator, int shader, int bufSize, int @Nullable [] length) { - var pLen = length != null ? allocator.allocate(JAVA_INT) : MemorySegment.NULL; - var pLog = allocator.allocateArray(JAVA_BYTE, bufSize); - getShaderInfoLog(shader, bufSize, pLen, pLog); - if (length != null && length.length > 0) { - length[0] = pLen.get(JAVA_INT, 0); + public static String getShaderInfoLog(int shader, int bufSize, int @Nullable [] length) { + final MemoryStack stack = MemoryStack.stackGet(); + final long stackPointer = stack.getPointer(); + try { + var pLen = length != null ? stack.callocInt() : MemorySegment.NULL; + final Arena allocator = stack.getPointer() < bufSize ? Arena.ofConfined() : stack; + try { + var pLog = allocator.allocateArray(JAVA_BYTE, bufSize); + getShaderInfoLog(shader, bufSize, pLen, pLog); + if (length != null && length.length > 0) { + length[0] = pLen.get(JAVA_INT, 0); + } + return pLog.getUtf8String(0); + } finally { + if (!(allocator instanceof MemoryStack)) allocator.close(); + } + } finally { + stack.setPointer(stackPointer); } - return pLog.getUtf8String(0); } - public static String getShaderInfoLog(SegmentAllocator allocator, int shader) { - return getShaderInfoLog(allocator, shader, getShaderi(shader, INFO_LOG_LENGTH), null); + public static String getShaderInfoLog(int shader) { + return getShaderInfoLog(shader, getShaderi(shader, INFO_LOG_LENGTH), null); } public static void getShaderSource(int shader, int bufSize, MemorySegment length, MemorySegment source) { @@ -561,7 +584,7 @@ public static int getShaderi(int shader, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getShaderiv(shader, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -607,7 +630,7 @@ public static float getUniformf(int program, int location) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_FLOAT); + var seg = stack.callocFloat(); getUniformfv(program, location, seg); return seg.get(JAVA_FLOAT, 0); } finally { @@ -634,7 +657,7 @@ public static int getUniformi(int program, int location) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getUniformiv(program, location, seg); return seg.get(JAVA_INT, 0); } finally { @@ -700,7 +723,7 @@ public static double getVertexAttribd(int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_DOUBLE); + var seg = stack.callocDouble(); getVertexAttribdv(index, pname, seg); return seg.get(JAVA_DOUBLE, 0); } finally { @@ -727,7 +750,7 @@ public static float getVertexAttribf(int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_FLOAT); + var seg = stack.callocFloat(); getVertexAttribfv(index, pname, seg); return seg.get(JAVA_FLOAT, 0); } finally { @@ -754,7 +777,7 @@ public static int getVertexAttribi(int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getVertexAttribiv(index, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java index aa0ed9f0..63f7834a 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL30C.java @@ -725,7 +725,7 @@ public static int genFramebuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genFramebuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -752,7 +752,7 @@ public static int genRenderbuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genRenderbuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -779,7 +779,7 @@ public static int genVertexArray() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genVertexArrays(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -855,7 +855,7 @@ public static int getFramebufferAttachmentParameteri(int target, int attachment, var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getFramebufferAttachmentParameteriv(target, attachment, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -882,7 +882,7 @@ public static int getIntegeri(int target, int index) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getIntegeri_v(target, index, seg); return seg.get(JAVA_INT, 0); } finally { @@ -903,7 +903,7 @@ public static void getRenderbufferParameteriv(int target, int pname, int[] param var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getRenderbufferParameteriv(target, pname, seg); params[0] = seg.get(JAVA_INT, 0); } finally { @@ -915,7 +915,7 @@ public static int getRenderbufferParameteri(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getRenderbufferParameteriv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -957,7 +957,7 @@ public static int getTexParameterIi(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getTexParameterIiv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -984,7 +984,7 @@ public static int getTexParameterIui(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getTexParameterIuiv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1034,7 +1034,7 @@ public static int getUniformui(int program, int location) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getUniformuiv(program, location, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1061,7 +1061,7 @@ public static int getVertexAttribIi(int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getVertexAttribIiv(index, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1088,7 +1088,7 @@ public static int getVertexAttribIui(int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getVertexAttribIuiv(index, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java index 0112c124..7fd27c0d 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL31C.java @@ -251,7 +251,7 @@ public static int getActiveUniformi(int program, int uniformIndex, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getActiveUniformsiv(program, 1, stack.ints(uniformIndex), pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java index 5c65c9b2..ee6ea795 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL32C.java @@ -247,7 +247,7 @@ public static long getBufferParameteri64(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getBufferParameteri64v(target, pname, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -274,7 +274,7 @@ public static long getInteger64i(int target, int index) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getInteger64i_v(target, index, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -301,7 +301,7 @@ public static long getInteger64(int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pData = stack.calloc(JAVA_LONG); + var pData = stack.callocLong(); getInteger64v(pname, pData); return pData.get(JAVA_LONG, 0); } finally { @@ -353,7 +353,7 @@ public static int getSynci(MemorySegment sync, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getSynciv(sync, pname, 1, MemorySegment.NULL, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java index ea0f34a5..104ee734 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL33C.java @@ -169,7 +169,7 @@ public static int genSampler() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genSamplers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -209,7 +209,7 @@ public static long getQueryObjecti64(int id, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getQueryObjecti64v(id, pname, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -230,7 +230,7 @@ public static long getQueryObjectui64(int id, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getQueryObjectui64v(id, pname, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -257,7 +257,7 @@ public static int getSamplerParameterIi(int sampler, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getSamplerParameterIiv(sampler, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -284,7 +284,7 @@ public static int getSamplerParameterIui(int sampler, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getSamplerParameterIuiv(sampler, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -311,7 +311,7 @@ public static float getSamplerParameterf(int sampler, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_FLOAT); + var seg = stack.callocFloat(); getSamplerParameterfv(sampler, pname, seg); return seg.get(JAVA_FLOAT, 0); } finally { @@ -338,7 +338,7 @@ public static int getSamplerParameteri(int sampler, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getSamplerParameteriv(sampler, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java index e723c808..0ba158c3 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java @@ -346,7 +346,7 @@ public static int genTransformFeedback() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genTransformFeedbacks(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -403,7 +403,7 @@ public static int getActiveSubroutineUniformi(int program, int shaderType, int i var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getActiveSubroutineUniformiv(program, shaderType, index, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -424,7 +424,7 @@ public static int getProgramStagei(int program, int shaderType, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getProgramStageiv(program, shaderType, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -445,7 +445,7 @@ public static int getQueryIndexedi(int target, int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getQueryIndexediv(target, index, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -525,7 +525,7 @@ public static double getUniformd(int program, int location) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_DOUBLE); + var seg = stack.callocDouble(); getUniformdv(program, location, seg); return seg.get(JAVA_DOUBLE, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java index bd26587a..7518051b 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL41C.java @@ -315,7 +315,7 @@ public static int genProgramPipeline() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); genProgramPipelines(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -342,7 +342,7 @@ public static double getDoublei(int target, int index) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_DOUBLE); + var seg = stack.callocDouble(); getDoublei_v(target, index, seg); return seg.get(JAVA_DOUBLE, 0); } finally { @@ -369,7 +369,7 @@ public static float getFloati(int target, int index) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_FLOAT); + var seg = stack.callocFloat(); getFloati_v(target, index, seg); return seg.get(JAVA_FLOAT, 0); } finally { @@ -390,8 +390,8 @@ public static void getProgramBinary(int program, int bufSize, int @Nullable [] l var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pl = length != null ? stack.calloc(JAVA_INT) : MemorySegment.NULL; - var pf = stack.calloc(JAVA_INT); + var pl = length != null ? stack.callocInt() : MemorySegment.NULL; + var pf = stack.callocInt(); getProgramBinary(program, bufSize, pl, pf, binary); if (length != null && length.length > 0) { length[0] = pl.get(JAVA_INT, 0); @@ -445,7 +445,7 @@ public static int getProgramPipelinei(int pipeline, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getProgramPipelineiv(pipeline, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java index d8fdaeaa..4e2ba6f6 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL42C.java @@ -275,7 +275,7 @@ public static int getActiveAtomicCounterBufferi(int program, int bufferIndex, in var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getActiveAtomicCounterBufferiv(program, bufferIndex, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -302,7 +302,7 @@ public static int getInternalformati(int target, int internalFormat, int pname) var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getInternalformativ(target, internalFormat, pname, 1, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java index f012a7ce..4fe8f96c 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java @@ -524,7 +524,7 @@ public static int getFramebufferParameteri(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getFramebufferParameteriv(target, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -551,7 +551,7 @@ public static long getInternalformati64(int target, int internalFormat, int pnam var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getInternalformati64v(target, internalFormat, pname, 1, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -626,7 +626,7 @@ public static int getProgramInterfacei(int program, int programInterface, int pn var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getProgramInterfaceiv(program, programInterface, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java index 0e6f1d5a..10ee62a5 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL45C.java @@ -386,7 +386,7 @@ public static int createBuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createBuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -413,7 +413,7 @@ public static int createFramebuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createFramebuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -440,7 +440,7 @@ public static int createProgramPipeline() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createProgramPipelines(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -467,7 +467,7 @@ public static int createQuery(int target) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createQueries(target, 1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -494,7 +494,7 @@ public static int createRenderbuffer() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createRenderbuffers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -521,7 +521,7 @@ public static int createSampler() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createSamplers(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -549,7 +549,7 @@ public static int createTexture(int target) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pTex = stack.calloc(JAVA_INT); + var pTex = stack.callocInt(); createTextures(target, 1, pTex); return pTex.get(JAVA_INT, 0); } finally { @@ -576,7 +576,7 @@ public static int createTransformFeedback() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createTransformFeedbacks(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -603,7 +603,7 @@ public static int createVertexArray() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); createVertexArrays(1, seg); return seg.get(JAVA_INT, 0); } finally { @@ -687,7 +687,7 @@ public static long getNamedBufferParameteri64(int buffer, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getNamedBufferParameteri64v(buffer, pname, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -708,7 +708,7 @@ public static int getNamedBufferParameteri(int buffer, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getNamedBufferParameteriv(buffer, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -729,7 +729,7 @@ public static MemorySegment getNamedBufferPointer(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(ADDRESS); + var seg = stack.callocPointer(); getNamedBufferPointerv(target, pname, seg); return seg.get(RuntimeHelper.ADDRESS_UNBOUNDED, 0); } finally { @@ -795,7 +795,7 @@ public static int getNamedFramebufferAttachmentParameteri(int framebuffer, int a var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getNamedFramebufferAttachmentParameteriv(framebuffer, attachment, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -816,7 +816,7 @@ public static int getNamedFramebufferParameteri(int framebuffer, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getNamedFramebufferParameteriv(framebuffer, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -837,7 +837,7 @@ public static void getNamedRenderbufferParameteriv(int renderbuffer, int pname, var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getNamedRenderbufferParameteriv(renderbuffer, pname, seg); params[0] = seg.get(JAVA_INT, 0); } finally { @@ -849,7 +849,7 @@ public static int getNamedRenderbufferParameteri(int renderbuffer, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getNamedRenderbufferParameteriv(renderbuffer, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -921,7 +921,7 @@ public static float getTextureLevelParameterf(int texture, int level, int pname) var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getTextureLevelParameterfv(texture, level, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -948,7 +948,7 @@ public static int getTextureLevelParameteri(int texture, int level, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getTextureLevelParameteriv(texture, level, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { @@ -975,7 +975,7 @@ public static int getTextureParameterIi(int texture, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getTextureParameterIiv(texture, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1002,7 +1002,7 @@ public static int getTextureParameterIui(int texture, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getTextureParameterIuiv(texture, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1029,7 +1029,7 @@ public static float getTextureParameterf(int texture, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_FLOAT); + var pParams = stack.callocFloat(); getTextureParameterfv(texture, pname, pParams); return pParams.get(JAVA_FLOAT, 0); } finally { @@ -1056,7 +1056,7 @@ public static int getTextureParameteri(int texture, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var pParams = stack.calloc(JAVA_INT); + var pParams = stack.callocInt(); getTextureParameteriv(texture, pname, pParams); return pParams.get(JAVA_INT, 0); } finally { @@ -1155,7 +1155,7 @@ public static long getVertexArrayIndexed64i(int vaobj, int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_LONG); + var seg = stack.callocLong(); getVertexArrayIndexed64iv(vaobj, index, pname, seg); return seg.get(JAVA_LONG, 0); } finally { @@ -1176,7 +1176,7 @@ public static int getVertexArrayIndexedi(int vaobj, int index, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getVertexArrayIndexediv(vaobj, index, pname, seg); return seg.get(JAVA_INT, 0); } finally { @@ -1197,7 +1197,7 @@ public static int getVertexArrayi(int vaobj, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); getVertexArrayiv(vaobj, pname, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java index 3419ad00..bfe76fd0 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoadFunc.java @@ -29,8 +29,8 @@ *

Example

* {@snippet lang = java: * // loads OpenGL forward-compatible profile - * import overrungl.util.CheckUtil; - * CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + * import java.util.Objects; + * Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); * } * * @author squid233 diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLINTELPerformanceQuery.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLINTELPerformanceQuery.java index 4360a0aa..dc31ffcc 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLINTELPerformanceQuery.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLINTELPerformanceQuery.java @@ -91,7 +91,7 @@ public static int glCreatePerfQueryINTEL(int queryId) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glCreatePerfQueryINTEL(queryId, seg); return seg.get(JAVA_INT, 0); } finally { @@ -130,7 +130,7 @@ public static int glGetFirstPerfQueryIdINTEL() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGetFirstPerfQueryIdINTEL(seg); return seg.get(JAVA_INT, 0); } finally { @@ -151,7 +151,7 @@ public static int glGetNextPerfQueryIdINTEL(int queryId) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGetNextPerfQueryIdINTEL(queryId, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLMESAFramebufferFlipY.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLMESAFramebufferFlipY.java index b4935a45..429b3dab 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLMESAFramebufferFlipY.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/GLMESAFramebufferFlipY.java @@ -68,11 +68,11 @@ public static void glGetFramebufferParameterivMESA(SegmentAllocator allocator, i RuntimeHelper.toArray(seg, params); } - public static int glGetFramebufferParameteriMESA(SegmentAllocator allocator, int target, int pname) { + public static int glGetFramebufferParameteriMESA(int target, int pname) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(ValueLayout.JAVA_INT); + var seg = stack.callocInt(); glGetFramebufferParameterivMESA(target, pname, seg); return seg.get(ValueLayout.JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDNameGenDelete.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDNameGenDelete.java index e7d888a2..8ac23f19 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDNameGenDelete.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDNameGenDelete.java @@ -84,7 +84,7 @@ public static int glGenNameAMD(int identifier) { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGenNamesAMD(identifier, 1, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDPerformanceMonitor.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDPerformanceMonitor.java index 681b7b16..11904519 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDPerformanceMonitor.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDPerformanceMonitor.java @@ -113,7 +113,7 @@ public static int glGenPerfMonitorAMD() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGenPerfMonitorsAMD(1, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEFence.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEFence.java index 8e8b15a9..b4f0bd33 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEFence.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEFence.java @@ -94,7 +94,7 @@ public static int glGenFenceAPPLE() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGenFencesAPPLE(1, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEVertexArrayObject.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEVertexArrayObject.java index 1b93fcb2..3376e209 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEVertexArrayObject.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/apple/GLAPPLEVertexArrayObject.java @@ -88,7 +88,7 @@ public static int glGenVertexArrayAPPLE() { var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var seg = stack.calloc(JAVA_INT); + var seg = stack.callocInt(); glGenVertexArraysAPPLE(1, seg); return seg.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBFragmentProgram.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBFragmentProgram.java index 7a0bb007..b2bea9d9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBFragmentProgram.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBFragmentProgram.java @@ -106,7 +106,7 @@ public static int glGenProgramARB() { MemoryStack stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - MemorySegment segment = stack.calloc(JAVA_INT); + MemorySegment segment = stack.callocInt(); glGenProgramsARB(1, segment); return segment.get(JAVA_INT, 0); } finally { diff --git a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java index 858b9508..7a08617c 100644 --- a/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java +++ b/modules/overrungl.stb/src/main/java/overrungl/stb/STBImage.java @@ -205,9 +205,9 @@ public static boolean infoFromCallbacks(STBIIoCallbacks clbk, MemorySegment user var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); boolean b = ninfoFromCallbacks(clbk.address(), user, px, py, pc); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -230,9 +230,9 @@ public static boolean infoFromFile(MemorySegment f, int[] x, int[] y, int[] comp var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); boolean b = ninfoFromFile(f, px, py, pc); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -256,14 +256,20 @@ public static boolean infoFromMemory(MemorySegment buffer, MemorySegment x, Memo } public static boolean infoFromMemory(SegmentAllocator allocator, byte[] buffer, int[] x, int[] y, int[] comp) { - var px = allocator.allocate(JAVA_INT); - var py = allocator.allocate(JAVA_INT); - var pc = allocator.allocate(JAVA_INT); - boolean b = infoFromMemory(allocator.allocateArray(JAVA_BYTE, buffer), px, py, pc); - x[0] = px.get(JAVA_INT, 0); - y[0] = py.get(JAVA_INT, 0); - comp[0] = pc.get(JAVA_INT, 0); - return b; + var stack = MemoryStack.stackGet(); + long stackPointer = stack.getPointer(); + try { + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); + boolean b = infoFromMemory(allocator.allocateArray(JAVA_BYTE, buffer), px, py, pc); + x[0] = px.get(JAVA_INT, 0); + y[0] = py.get(JAVA_INT, 0); + comp[0] = pc.get(JAVA_INT, 0); + return b; + } finally { + stack.setPointer(stackPointer); + } } public static boolean nis16Bit(MemorySegment filename) { @@ -452,9 +458,9 @@ public static MemorySegment load16FromCallbacks(STBIIoCallbacks clbk, MemorySegm var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nload16FromCallbacks(clbk.address(), user, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -500,9 +506,9 @@ public static MemorySegment loadFromCallbacks(STBIIoCallbacks clbk, MemorySegmen var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nloadFromCallbacks(clbk.address(), user, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -525,9 +531,9 @@ public static MemorySegment loadFromFile(MemorySegment f, int[] x, int[] y, int[ var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nloadFromFile(f, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -550,9 +556,9 @@ public static MemorySegment loadFromFile16(MemorySegment f, int[] x, int[] y, in var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nloadFromFile16(f, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -651,9 +657,9 @@ public static MemorySegment loadfFromCallbacks(STBIIoCallbacks clbk, MemorySegme var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nloadfFromCallbacks(clbk.address(), user, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); @@ -676,9 +682,9 @@ public static MemorySegment loadfFromFile(MemorySegment f, int[] x, int[] y, int var stack = MemoryStack.stackGet(); long stackPointer = stack.getPointer(); try { - var px = stack.calloc(JAVA_INT); - var py = stack.calloc(JAVA_INT); - var pc = stack.calloc(JAVA_INT); + var px = stack.callocInt(); + var py = stack.callocInt(); + var pc = stack.callocInt(); var addr = nloadfFromFile(f, px, py, pc, desiredChannels); x[0] = px.get(JAVA_INT, 0); y[0] = py.get(JAVA_INT, 0); diff --git a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java index 127f4f22..debe9522 100644 --- a/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java +++ b/modules/samples/src/test/java/overrungl/demo/glfw/GLFWWindowIconTest.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; +import java.util.Objects; import static java.lang.foreign.ValueLayout.JAVA_INT; @@ -105,7 +106,7 @@ private void init(Arena arena) { } private void load() { - CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } diff --git a/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java b/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java index cbee2a60..75be4ada 100644 --- a/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java +++ b/modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java @@ -68,7 +68,7 @@ private static void openDialogMultiple() { NFD.init(); try (MemoryStack stack = MemoryStack.stackPush()) { - MemorySegment pOutPaths = stack.calloc(ValueLayout.ADDRESS); + MemorySegment pOutPaths = stack.callocPointer(); String[] outPath = new String[1]; // prepare filters for the dialog @@ -109,7 +109,7 @@ private static void openDialogMultipleEnum() { NFD.init(); try (MemoryStack stack = MemoryStack.stackPush()) { - MemorySegment pOutPaths = stack.calloc(ValueLayout.ADDRESS); + MemorySegment pOutPaths = stack.callocPointer(); // prepare filters for the dialog final NFDNFilterItem.Buffer filterItem = NFDNFilterItem.create(stack, diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java index 1b1cbdf7..98b5774f 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL10Test.java @@ -25,6 +25,7 @@ import overrungl.util.CheckUtil; import java.lang.foreign.MemorySegment; +import java.util.Objects; /** * Tests basic GLFW and OpenGL @@ -79,7 +80,7 @@ private void init() { } private void load() { - CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); } diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java index 025c0ce1..0b099931 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL15Test.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; +import java.util.Objects; import static java.lang.foreign.ValueLayout.JAVA_INT; @@ -91,7 +92,7 @@ private void init() { } private void load(Arena arena) { - CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); GL.enable(GL.TEXTURE_2D); diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java index c9a39a86..e18537d6 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL30Test.java @@ -29,6 +29,7 @@ import java.io.IOException; import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; +import java.util.Objects; import static java.lang.foreign.ValueLayout.JAVA_INT; @@ -97,7 +98,7 @@ private void init() { } private void load(Arena arena) { - CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f); diff --git a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java index 307c9e50..751463b9 100644 --- a/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java +++ b/modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java @@ -31,6 +31,7 @@ import java.lang.foreign.Arena; import java.lang.foreign.MemoryLayout; import java.lang.foreign.MemorySegment; +import java.util.Objects; /** * Tests OpenGL 3.3 instanced rendering @@ -109,7 +110,7 @@ private void init() { } private void load(Arena arena) { - CheckUtil.checkNotNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); + Objects.requireNonNull(GLLoader.load(GLFW::getProcAddress, true), "Failed to load OpenGL"); debugProc = GLUtil.setupDebugMessageCallback(); GL.clearColor(0.4f, 0.6f, 0.9f, 1.0f);