diff --git a/modules/overrungl.core/src/main/java/overrungl/Configurations.java b/modules/overrungl.core/src/main/java/overrungl/Configurations.java index baa4be91..f8fc14b9 100644 --- a/modules/overrungl.core/src/main/java/overrungl/Configurations.java +++ b/modules/overrungl.core/src/main/java/overrungl/Configurations.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -69,12 +69,6 @@ public final class Configurations { * The default value is {@code true}. */ public static final Entry CHECKS = new Entry<>(() -> true); - /** - * Forcing to check all method handles for OpenGL. - *

- * The default value is {@code false}. - */ - public static final Entry GL_FORCE_CHECK_ALL = new Entry<>(() -> false); /** * The symbol lookup of GLFW. * The returned value must not be null. diff --git a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLAMD.kt b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLAMD.kt index fde48d9b..eda50cc5 100644 --- a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLAMD.kt +++ b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLAMD.kt @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Overrun Organization + * Copyright (c) 2023-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -62,7 +62,7 @@ fun amd() { ("glDebugMessageCallbackAMD"(void, address("callback", "GLDEBUGPROCAMD"), address("userParam", "void *"))) { "glDebugMessageCallbackAMD"( void, - "glDebugMessageCallbackAMD(callback.address(arena), userParam);", + "glDebugMessageCallbackAMD(callback.stub(arena), userParam);", arena("arena"), Type("GLDebugProcAMD", null)("callback"), address("userParam", "void *") diff --git a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLARB.kt b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLARB.kt index 36c8f6ce..3ee51377 100644 --- a/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLARB.kt +++ b/modules/overrungl.opengl/src/generator/kotlin/overrungl/opengl/GLARB.kt @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Overrun Organization + * Copyright (c) 2023-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -153,7 +153,7 @@ fun arb() { )) { "glDebugMessageCallbackARB"( void, - "glDebugMessageCallbackARB(callback.address(arena), userParam);", + "glDebugMessageCallbackARB(callback.stub(arena), userParam);", arena("arena"), Type("GLDebugProc", null)("callback"), address("userParam", "const void *") diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java index 0bf287e4..a86f77c9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawArraysIndirectCommand.java @@ -16,28 +16,26 @@ package overrungl.opengl; -import overrungl.ArrayPointer; -import overrungl.Struct; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; /** * The OpenGL 4.2 draw arrays indirect command. *

Layout

*

  * struct DrawArraysIndirectCommand {
- *     unsigned int {@link #count() count};
- *     unsigned int {@link #primCount() primCount};
- *     unsigned int {@link #first() first};
- *     unsigned int {@link #baseInstance() baseInstance};
+ *     unsigned int {@link #count};
+ *     unsigned int {@link #primCount};
+ *     unsigned int {@link #first};
+ *     unsigned int {@link #baseInstance};
  * }
* * @author squid233 * @since 0.1.0 */ -public sealed class DrawArraysIndirectCommand extends Struct { +public final class DrawArraysIndirectCommand extends Struct { /** * The struct layout. */ @@ -47,280 +45,58 @@ public sealed class DrawArraysIndirectCommand extends Struct { ValueLayout.JAVA_INT.withName("first"), ValueLayout.JAVA_INT.withName("baseInstance") ); - private static final VarHandle - pCount = LAYOUT.varHandle(PathElement.groupElement("count")), - pPrimCount = LAYOUT.varHandle(PathElement.groupElement("primCount")), - pFirst = LAYOUT.varHandle(PathElement.groupElement("first")), - pBaseInstance = LAYOUT.varHandle(PathElement.groupElement("baseInstance")); - /** - * Create the pointer instance. - * - * @param address the address. + * the count */ - public DrawArraysIndirectCommand(MemorySegment address) { - super(address, LAYOUT); - } - + public final StructHandle.Int count = StructHandle.ofInt(this, "count"); /** - * Creates a struct instance with the given memory layout. - * - * @param address the address. - * @param layout the memory layout of this struct. + * the primCount */ - protected DrawArraysIndirectCommand(MemorySegment address, MemoryLayout layout) { - super(address, layout); - } - + public final StructHandle.Int primCount = StructHandle.ofInt(this, "primCount"); /** - * {@return the elements size of this struct in bytes} + * the first */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - + public final StructHandle.Int first = StructHandle.ofInt(this, "first"); /** - * Creates a command instance with the given allocator. - * - * @param allocator the allocator - * @return the instance + * the baseInstance */ - public static DrawArraysIndirectCommand create(SegmentAllocator allocator) { - return new DrawArraysIndirectCommand(allocator.allocate(LAYOUT)); - } + public final StructHandle.Int baseInstance = StructHandle.ofInt(this, "baseInstance"); /** - * Creates a command instance with the given allocator and count. + * Creates a struct with the given layout. * - * @param allocator the allocator - * @param count the count - * @return the instance + * @param segment the segment + * @param elementCount the element count */ - public static Buffer create(SegmentAllocator allocator, long count) { - return new Buffer(allocator.allocate(LAYOUT, count), count); + public DrawArraysIndirectCommand(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * Sets the count. + * Allocates a struct with the given layout. * - * @param count the count - * @return this + * @param allocator the allocator + * @param elementCount the element count */ - public DrawArraysIndirectCommand count(int count) { - pCount.set(segment(), count); - return this; + public DrawArraysIndirectCommand(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Sets the primitive count. + * Creates a struct with the given layout. * - * @param primCount the primitive count - * @return this + * @param segment the segment */ - public DrawArraysIndirectCommand primCount(int primCount) { - pPrimCount.set(segment(), primCount); - return this; + public DrawArraysIndirectCommand(MemorySegment segment) { + super(segment, LAYOUT); } /** - * Sets the first. + * Allocates a struct with the given layout. * - * @param first the first - * @return this - */ - public DrawArraysIndirectCommand first(int first) { - pFirst.set(segment(), first); - return this; - } - - /** - * Sets the base instance. - * - * @param baseInstance the base instance - * @return this - */ - public DrawArraysIndirectCommand baseInstance(int baseInstance) { - pBaseInstance.set(segment(), baseInstance); - return this; - } - - /** - * {@return the count} - */ - public int count() { - return (int) pCount.get(segment()); - } - - /** - * {@return the primitive count} - */ - public int primCount() { - return (int) pPrimCount.get(segment()); - } - - /** - * {@return the first} - */ - public int first() { - return (int) pFirst.get(segment()); - } - - /** - * {@return the base instance} - */ - public int baseInstance() { - return (int) pBaseInstance.get(segment()); - } - - /** - * The OpenGL 4.2 draw arrays indirect commands. - * - * @author squid233 - * @since 0.1.0 + * @param allocator the allocator */ - public static final class Buffer extends DrawArraysIndirectCommand implements ArrayPointer { - private final VarHandle pCount, pPrimCount, pFirst, pBaseInstance; - - /** - * Create the pointer instance. - * - * @param address the address. - * @param elementCount the element count - */ - public Buffer(MemorySegment address, long elementCount) { - super(address, MemoryLayout.sequenceLayout(elementCount, LAYOUT)); - pCount = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("count")); - pPrimCount = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("primCount")); - pFirst = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("first")); - pBaseInstance = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("baseInstance")); - } - - /** - * Sets the count at the given index. - * - * @param index the index - * @param count the count - * @return this - */ - public Buffer count(long index, int count) { - pCount.set(segment(), index, count); - return this; - } - - /** - * Sets the primitive count at the given index. - * - * @param index the index - * @param primCount the primitive count - * @return this - */ - public Buffer primCount(long index, int primCount) { - pPrimCount.set(segment(), index, primCount); - return this; - } - - /** - * Sets the first at the given index. - * - * @param index the index - * @param first the first - * @return this - */ - public Buffer first(long index, int first) { - pFirst.set(segment(), index, first); - return this; - } - - /** - * Sets the base instance at the given index. - * - * @param index the index - * @param baseInstance the base instance - * @return this - */ - public Buffer baseInstance(long index, int baseInstance) { - pBaseInstance.set(segment(), index, baseInstance); - return this; - } - - @Override - public Buffer count(int count) { - return count(0, count); - } - - @Override - public Buffer primCount(int primCount) { - return primCount(0, primCount); - } - - @Override - public Buffer first(int first) { - return first(0, first); - } - - @Override - public Buffer baseInstance(int baseInstance) { - return baseInstance(0, baseInstance); - } - - /** - * Gets the count at the given index. - * - * @param index the index - * @return the count - */ - public int countAt(long index) { - return (int) pCount.get(segment(), index); - } - - /** - * Gets the primitive count at the given index. - * - * @param index the index - * @return the primitive count - */ - public int primCountAt(long index) { - return (int) pPrimCount.get(segment(), index); - } - - /** - * Gets the first at the given index. - * - * @param index the index - * @return the first - */ - public int firstAt(long index) { - return (int) pFirst.get(segment(), index); - } - - /** - * Gets the base instance at the given index. - * - * @param index the index - * @return the base instance - */ - public int baseInstanceAt(long index) { - return (int) pBaseInstance.get(segment(), index); - } - - @Override - public int count() { - return countAt(0); - } - - @Override - public int primCount() { - return primCountAt(0); - } - - @Override - public int first() { - return firstAt(0); - } - - @Override - public int baseInstance() { - return baseInstanceAt(0); - } + public DrawArraysIndirectCommand(SegmentAllocator allocator) { + super(allocator, LAYOUT); } } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java index 0dd1bdfd..ec08d704 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/DrawElementsIndirectCommand.java @@ -16,29 +16,27 @@ package overrungl.opengl; -import overrungl.ArrayPointer; -import overrungl.Struct; +import overrun.marshal.struct.Struct; +import overrun.marshal.struct.StructHandle; import java.lang.foreign.*; -import java.lang.foreign.MemoryLayout.PathElement; -import java.lang.invoke.VarHandle; /** * The OpenGL 4.2 draw elements indirect command. *

Layout

*

  * struct DrawElementsIndirectCommand {
- *     unsigned int {@link #count() count};
- *     unsigned int {@link #primCount() primCount};
- *     unsigned int {@link #firstIndex() firstIndex};
- *     unsigned int {@link #baseVertex() baseVertex};
- *     unsigned int {@link #baseInstance() baseInstance};
+ *     unsigned int {@link #count};
+ *     unsigned int {@link #primCount};
+ *     unsigned int {@link #firstIndex};
+ *     unsigned int {@link #baseVertex};
+ *     unsigned int {@link #baseInstance};
  * }
* * @author squid233 * @since 0.1.0 */ -public sealed class DrawElementsIndirectCommand extends Struct { +public final class DrawElementsIndirectCommand extends Struct { /** * The struct layout. */ @@ -49,332 +47,62 @@ public sealed class DrawElementsIndirectCommand extends Struct { ValueLayout.JAVA_INT.withName("baseVertex"), ValueLayout.JAVA_INT.withName("baseInstance") ); - private static final VarHandle - pCount = LAYOUT.varHandle(PathElement.groupElement("count")), - pPrimCount = LAYOUT.varHandle(PathElement.groupElement("primCount")), - pFirstIndex = LAYOUT.varHandle(PathElement.groupElement("firstIndex")), - pBaseVertex = LAYOUT.varHandle(PathElement.groupElement("baseVertex")), - pBaseInstance = LAYOUT.varHandle(PathElement.groupElement("baseInstance")); - /** - * Create the pointer instance. - * - * @param address the address. + * the count */ - public DrawElementsIndirectCommand(MemorySegment address) { - super(address, LAYOUT); - } - - /** - * Creates a struct instance with the given memory layout. - * - * @param address the address. - * @param layout the memory layout of this struct. - */ - protected DrawElementsIndirectCommand(MemorySegment address, MemoryLayout layout) { - super(address, layout); - } - + public final StructHandle.Int count = StructHandle.ofInt(this, "count"); /** - * {@return the elements size of this struct in bytes} + * the primCount */ - public static long sizeof() { - return LAYOUT.byteSize(); - } - - /** - * Creates a command instance with the given allocator. - * - * @param allocator the allocator - * @return the instance - */ - public static DrawElementsIndirectCommand create(SegmentAllocator allocator) { - return new DrawElementsIndirectCommand(allocator.allocate(LAYOUT)); - } - + public final StructHandle.Int primCount = StructHandle.ofInt(this, "primCount"); /** - * Creates a command instance with the given allocator and count. - * - * @param allocator the allocator - * @param count the count - * @return the instance + * the firstIndex */ - public static Buffer create(SegmentAllocator allocator, long count) { - return new Buffer(allocator.allocate(LAYOUT, count), count); - } - + public final StructHandle.Int firstIndex = StructHandle.ofInt(this, "firstIndex"); /** - * Sets the count. - * - * @param count the count - * @return this + * the baseVertex */ - public DrawElementsIndirectCommand count(int count) { - pCount.set(segment(), count); - return this; - } - + public final StructHandle.Int baseVertex = StructHandle.ofInt(this, "baseVertex"); /** - * Sets the primitive count. - * - * @param primCount the primitive count - * @return this + * the baseInstance */ - public DrawElementsIndirectCommand primCount(int primCount) { - pPrimCount.set(segment(), primCount); - return this; - } + public final StructHandle.Int baseInstance = StructHandle.ofInt(this, "baseInstance"); /** - * Sets the first index. + * Creates a struct with the given layout. * - * @param firstIndex the first index - * @return this + * @param segment the segment + * @param elementCount the element count */ - public DrawElementsIndirectCommand firstIndex(int firstIndex) { - pFirstIndex.set(segment(), firstIndex); - return this; + public DrawElementsIndirectCommand(MemorySegment segment, long elementCount) { + super(segment, elementCount, LAYOUT); } /** - * Sets the base vertex. + * Allocates a struct with the given layout. * - * @param baseVertex the base vertex - * @return this + * @param allocator the allocator + * @param elementCount the element count */ - public DrawElementsIndirectCommand baseVertex(int baseVertex) { - pBaseVertex.set(segment(), baseVertex); - return this; + public DrawElementsIndirectCommand(SegmentAllocator allocator, long elementCount) { + super(allocator, elementCount, LAYOUT); } /** - * Sets the base instance. + * Creates a struct with the given layout. * - * @param baseInstance the base instance - * @return this - */ - public DrawElementsIndirectCommand baseInstance(int baseInstance) { - pBaseInstance.set(segment(), baseInstance); - return this; - } - - /** - * {@return the count} - */ - public int count() { - return (int) pCount.get(segment()); - } - - /** - * {@return the primitive count} + * @param segment the segment */ - public int primCount() { - return (int) pPrimCount.get(segment()); + public DrawElementsIndirectCommand(MemorySegment segment) { + super(segment, LAYOUT); } /** - * {@return the first index} - */ - public int firstIndex() { - return (int) pFirstIndex.get(segment()); - } - - /** - * {@return the base vertex} - */ - public int baseVertex() { - return (int) pBaseVertex.get(segment()); - } - - /** - * {@return the base instance} - */ - public int baseInstance() { - return (int) pBaseInstance.get(segment()); - } - - /** - * The OpenGL 4.2 draw elements indirect commands. + * Allocates a struct with the given layout. * - * @author squid233 - * @since 0.1.0 + * @param allocator the allocator */ - public static final class Buffer extends DrawElementsIndirectCommand implements ArrayPointer { - private final VarHandle pCount, pPrimCount, pFirstIndex, pBaseVertex, pBaseInstance; - - /** - * Create the pointer instance. - * - * @param address the address. - * @param elementCount the element count - */ - public Buffer(MemorySegment address, long elementCount) { - super(address, MemoryLayout.sequenceLayout(elementCount, LAYOUT)); - pCount = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("count")); - pPrimCount = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("primCount")); - pFirstIndex = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("firstIndex")); - pBaseVertex = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("baseVertex")); - pBaseInstance = layout().varHandle(PathElement.sequenceElement(), PathElement.groupElement("baseInstance")); - } - - /** - * Sets the count at the given index. - * - * @param index the index - * @param count the count - * @return this - */ - public Buffer count(long index, int count) { - pCount.set(segment(), index, count); - return this; - } - - /** - * Sets the primitive count at the given index. - * - * @param index the index - * @param primCount the primitive count - * @return this - */ - public Buffer primCount(long index, int primCount) { - pPrimCount.set(segment(), index, primCount); - return this; - } - - /** - * Sets the first index at the given index. - * - * @param index the index - * @param firstIndex the first index - * @return this - */ - public Buffer firstIndex(long index, int firstIndex) { - pFirstIndex.set(segment(), index, firstIndex); - return this; - } - - /** - * Sets the base vertex at the given index. - * - * @param index the index - * @param baseVertex the base vertex - * @return this - */ - public Buffer baseVertex(long index, int baseVertex) { - pBaseVertex.set(segment(), index, baseVertex); - return this; - } - - /** - * Sets the base instance at the given index. - * - * @param index the index - * @param baseInstance the base instance - * @return this - */ - public Buffer baseInstance(long index, int baseInstance) { - pBaseInstance.set(segment(), index, baseInstance); - return this; - } - - @Override - public Buffer count(int count) { - return count(0, count); - } - - @Override - public Buffer primCount(int primCount) { - return primCount(0, primCount); - } - - @Override - public Buffer firstIndex(int firstIndex) { - return firstIndex(0, firstIndex); - } - - @Override - public Buffer baseVertex(int baseVertex) { - return baseVertex(0, baseVertex); - } - - @Override - public Buffer baseInstance(int baseInstance) { - return baseInstance(0, baseInstance); - } - - /** - * Gets the count at the given index. - * - * @param index the index - * @return the count - */ - public int countAt(long index) { - return (int) pCount.get(segment(), index); - } - - /** - * Gets the primitive count at the given index. - * - * @param index the index - * @return the primitive count - */ - public int primCountAt(long index) { - return (int) pPrimCount.get(segment(), index); - } - - /** - * Gets the first index at the given index. - * - * @param index the index - * @return the first index - */ - public int firstIndexAt(long index) { - return (int) pFirstIndex.get(segment(), index); - } - - /** - * Gets the base vertex at the given index. - * - * @param index the index - * @return the base vertex - */ - public int baseVertexAt(long index) { - return (int) pBaseVertex.get(segment(), index); - } - - /** - * Gets the base instance at the given index. - * - * @param index the index - * @return the base instance - */ - public int baseInstanceAt(long index) { - return (int) pBaseInstance.get(segment(), index); - } - - @Override - public int count() { - return countAt(0); - } - - @Override - public int primCount() { - return primCountAt(0); - } - - @Override - public int firstIndex() { - return firstIndexAt(0); - } - - @Override - public int baseVertex() { - return baseVertexAt(0); - } - - @Override - public int baseInstance() { - return baseInstanceAt(0); - } + public DrawElementsIndirectCommand(SegmentAllocator allocator) { + super(allocator, LAYOUT); } } 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 c1a36a3a..3a279f3a 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL40C.java @@ -276,7 +276,7 @@ public static void drawArraysIndirect(int mode, MemorySegment indirect) { } public static void drawArraysIndirect(int mode, DrawArraysIndirectCommand indirect) { - drawArraysIndirect(mode, indirect.address()); + drawArraysIndirect(mode, indirect.segment()); } public static void drawArraysIndirect(SegmentAllocator allocator, int mode, int[] indirect) { @@ -293,7 +293,7 @@ public static void drawElementsIndirect(int mode, int type, MemorySegment indire } public static void drawElementsIndirect(int mode, int type, DrawElementsIndirectCommand indirect) { - drawElementsIndirect(mode, type, indirect.address()); + drawElementsIndirect(mode, type, indirect.segment()); } public static void drawElementsIndirect(SegmentAllocator allocator, int mode, int type, int[] indirect) { 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 94d70f19..adaca630 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GL43C.java @@ -419,7 +419,7 @@ public static void debugMessageCallback(MemorySegment callback, MemorySegment us } public static void debugMessageCallback(Arena arena, GLDebugProc callback, MemorySegment userParam) { - debugMessageCallback(callback.address(arena), userParam); + debugMessageCallback(callback.stub(arena), userParam); } public static void debugMessageControl(int source, int type, int severity, int count, MemorySegment ids, boolean enabled) { @@ -838,8 +838,8 @@ public static void multiDrawArraysIndirect(int mode, MemorySegment indirect, int } } - public static void multiDrawArraysIndirect(int mode, DrawArraysIndirectCommand.Buffer indirect, int drawCount, int stride) { - multiDrawArraysIndirect(mode, indirect.address(), drawCount, stride); + public static void multiDrawArraysIndirect(int mode, DrawArraysIndirectCommand indirect, int drawCount, int stride) { + multiDrawArraysIndirect(mode, indirect.segment(), drawCount, stride); } public static void multiDrawElementsIndirect(int mode, int type, MemorySegment indirect, int drawCount, int stride) { @@ -852,7 +852,7 @@ public static void multiDrawElementsIndirect(int mode, int type, MemorySegment i } public static void multiDrawElementsIndirect(int mode, int type, DrawElementsIndirectCommand.Buffer indirect, int drawCount, int stride) { - multiDrawElementsIndirect(mode, type, indirect.address(), drawCount, stride); + multiDrawElementsIndirect(mode, type, indirect.segment(), drawCount, stride); } public static void objectLabel(int identifier, int name, int length, MemorySegment label) { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLCapabilities.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLCapabilities.java index 95ad7588..72f5875d 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLCapabilities.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLCapabilities.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,7 +16,6 @@ package overrungl.opengl; -import overrungl.Configurations; import overrungl.FunctionDescriptors; import java.lang.foreign.Arena; @@ -30,7 +29,7 @@ * @author squid233 * @since 0.1.0 */ -public class GLCapabilities { +public final class GLCapabilities { private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+).*$"); /** @@ -324,7 +323,7 @@ public int load(GLLoadFunc load) { GL45C.load(this, load); GL46C.load(this, load); - int version = findCoreGL(false); + int version = findCoreGL(); if (!forwardCompatible) { GL10.load(this, load); GL11.load(this, load); @@ -336,7 +335,6 @@ public int load(GLLoadFunc load) { try (var arena = Arena.ofConfined()) { if (!ext.findExtensionsGL(version, arena)) return 0; - findCoreGL(true); } ext.load(load); @@ -349,31 +347,7 @@ private boolean check(boolean checkAll, boolean b, Predicate che return checkAll ? checkFunc.test(this) : (b || checkFunc.test(this)); } - private int findCoreGL(boolean checkAll) { - if (checkAll) { - boolean forceCheckAll = Configurations.GL_FORCE_CHECK_ALL.get(); - // Note: use Predicate to avoid side effects - Ver10 = check(forceCheckAll, Ver10, GL10C::isSupported); - Ver11 = check(forceCheckAll, Ver11, GL11C::isSupported); - Ver12 = check(forceCheckAll, Ver12, GL12C::isSupported); - Ver13 = check(forceCheckAll, Ver13, GL13C::isSupported); - Ver14 = check(forceCheckAll, Ver14, GL14C::isSupported); - Ver15 = check(forceCheckAll, Ver15, GL15C::isSupported); - Ver20 = check(forceCheckAll, Ver20, GL20C::isSupported); - Ver21 = check(forceCheckAll, Ver21, GL21C::isSupported); - Ver30 = check(forceCheckAll, Ver30, GL30C::isSupported); - Ver31 = check(forceCheckAll, Ver31, GL31C::isSupported); - Ver32 = check(forceCheckAll, Ver32, GL32C::isSupported); - Ver33 = check(forceCheckAll, Ver33, GL33C::isSupported); - Ver40 = check(forceCheckAll, Ver40, GL40C::isSupported); - Ver41 = check(forceCheckAll, Ver41, GL41C::isSupported); - Ver42 = check(forceCheckAll, Ver42, GL42C::isSupported); - Ver43 = check(forceCheckAll, Ver43, GL43C::isSupported); - Ver44 = check(forceCheckAll, Ver44, GL44C::isSupported); - Ver45 = check(forceCheckAll, Ver45, GL45C::isSupported); - Ver46 = check(forceCheckAll, Ver46, GL46C::isSupported); - return -1; - } + private int findCoreGL() { final String[] prefixes = { "OpenGL ES-CM ", "OpenGL ES-CL ", diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java index 0f054355..b5528570 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLDebugProc.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,16 +16,10 @@ package overrungl.opengl; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.ADDRESS; -import static java.lang.foreign.ValueLayout.JAVA_INT; /** * The OpenGL debug message callback. @@ -34,9 +28,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface GLDebugProc extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLDebugProc extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * debug callback @@ -51,17 +47,13 @@ public interface GLDebugProc extends Callback { */ void invoke(int source, int type, int id, int severity, String message, MemorySegment userParam); + @Stub default void ninvoke(int source, int type, int id, int severity, int length, MemorySegment message, MemorySegment userParam) { - invoke(source, type, id, severity, message.reinterpret(length + 1).getString(0), userParam.reinterpret(Long.MAX_VALUE)); - } - - @Override - default FunctionDescriptor descriptor() { - return DESC; + invoke(source, type, id, severity, message.reinterpret(length + 1).getString(0), userParam); } @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(GLDebugProc.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java index 6f424a3b..18d62129 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/GLLoader.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDDebugOutput.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDDebugOutput.java index 09043b58..594b9b12 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDDebugOutput.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLAMDDebugOutput.java @@ -72,7 +72,7 @@ public static void glDebugMessageCallbackAMD(@NativeType("GLDEBUGPROCAMD") Memor } public static void glDebugMessageCallbackAMD(Arena arena, GLDebugProcAMD callback, @NativeType("void *") MemorySegment userParam) { - glDebugMessageCallbackAMD(callback.address(arena), userParam); + glDebugMessageCallbackAMD(callback.stub(arena), userParam); } public static int glGetDebugMessageLogAMD(int count, int bufSize, @NativeType("GLenum *") MemorySegment categories, @NativeType("GLenum *") MemorySegment severities, @NativeType("GLuint *") MemorySegment ids, @NativeType("GLsizei *") MemorySegment lengths, @NativeType("GLchar *") MemorySegment message) { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java index af855e69..9d21bf70 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/amd/GLDebugProcAMD.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2022-2023 Overrun Organization + * Copyright (c) 2022-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,17 +16,10 @@ package overrungl.opengl.ext.amd; -import overrungl.Callback; -import overrungl.internal.RuntimeHelper; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; +import java.lang.foreign.Arena; import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; - -import static java.lang.foreign.ValueLayout.ADDRESS; -import static java.lang.foreign.ValueLayout.JAVA_INT; /** * The OpenGL debug message callback. @@ -35,9 +28,11 @@ * @since 0.1.0 */ @FunctionalInterface -public interface GLDebugProcAMD extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS); - MethodType MTYPE = DESC.toMethodType(); +public interface GLDebugProcAMD extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); /** * debug callback @@ -51,17 +46,13 @@ public interface GLDebugProcAMD extends Callback { */ void invoke(int id, int category, int severity, String message, MemorySegment userParam); + @Stub default void ninvoke(int id, int category, int severity, int length, MemorySegment message, MemorySegment userParam) { - invoke(id, category, severity, message.reinterpret(length + 1).getString(0), userParam.reinterpret(Long.MAX_VALUE)); - } - - @Override - default FunctionDescriptor descriptor() { - return DESC; + invoke(id, category, severity, message.reinterpret(length + 1).getString(0), userParam); } @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(GLDebugProcAMD.class, "ninvoke", MTYPE); + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } } diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBDebugOutput.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBDebugOutput.java index 0d1e3f6a..8d3a24de 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBDebugOutput.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/arb/GLARBDebugOutput.java @@ -80,7 +80,7 @@ public static void glDebugMessageCallbackARB(@NativeType("GLDEBUGPROCARB") Memor } public static void glDebugMessageCallbackARB(Arena arena, GLDebugProc callback, @NativeType("const void *") MemorySegment userParam) { - glDebugMessageCallbackARB(callback.address(arena), userParam); + glDebugMessageCallbackARB(callback.stub(arena), userParam); } public static int glGetDebugMessageLogARB(int count, int bufSize, @NativeType("GLenum *") MemorySegment sources, @NativeType("GLenum *") MemorySegment types, @NativeType("GLuint *") MemorySegment ids, @NativeType("GLenum *") MemorySegment severities, @NativeType("GLsizei *") MemorySegment lengths, @NativeType("GLchar *") MemorySegment messageLog) { diff --git a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java index ff939276..07030ec9 100644 --- a/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java +++ b/modules/overrungl.opengl/src/main/java/overrungl/opengl/ext/nv/GLVulkanProcNV.java @@ -1,7 +1,7 @@ /* * MIT License * - * Copyright (c) 2023 Overrun Organization + * Copyright (c) 2023-2024 Overrun Organization * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -16,12 +16,10 @@ package overrungl.opengl.ext.nv; -import overrungl.Callback; +import overrun.marshal.Upcall; -import java.lang.foreign.FunctionDescriptor; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; +import java.lang.foreign.Arena; +import java.lang.foreign.MemorySegment; /** * {@link GLNVDrawVulkanImage} @@ -30,29 +28,28 @@ * @since 0.1.0 */ @FunctionalInterface -public interface GLVulkanProcNV extends Callback { - FunctionDescriptor DESC = FunctionDescriptor.ofVoid(); - MethodType MTYPE = DESC.toMethodType(); - Native NATIVE = segment -> new GLVulkanProcNV() { - @Override - public void invoke() { - try { - nativeHandle(segment).invokeExact(); - } catch (Throwable e) { - throw new AssertionError("should not reach here", e); - } - } - }; +public interface GLVulkanProcNV extends Upcall { + /** + * The type. + */ + Type TYPE = Upcall.type(); + @Stub void invoke(); @Override - default FunctionDescriptor descriptor() { - return DESC; + default MemorySegment stub(Arena arena) { + return TYPE.of(arena, this); } - @Override - default MethodHandle handle(MethodHandles.Lookup lookup) throws NoSuchMethodException, IllegalAccessException { - return lookup.findVirtual(GLVulkanProcNV.class, "invoke", MTYPE); + @Wrapper + static GLVulkanProcNV wrap(Arena arena, MemorySegment stub) { + return TYPE.wrap(stub, handle -> () -> { + try { + handle.invokeExact(); + } catch (Throwable e) { + throw new RuntimeException(e); + } + }); } }