Skip to content

Commit 36cb31a

Browse files
authored
Merge pull request #109 from Over-Run/feature
2 parents 5fd0316 + 1cfde52 commit 36cb31a

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

  • modules

modules/overrungl.opengl/src/main/java/overrungl/opengl/GLUtil.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package overrungl.opengl;
1818

19-
import org.jetbrains.annotations.Nullable;
2019
import overrungl.OverrunGL;
2120
import overrungl.opengl.amd.GLAMDDebugOutput;
2221
import overrungl.opengl.amd.GLDebugProcAMD;
@@ -50,38 +49,38 @@ private GLUtil() {
5049
* Detects the best debug output functionality to use and creates a callback that prints information to
5150
* {@link OverrunGL#apiLogger() API Logger}.
5251
* <p>
53-
* The callback function is returned as a {@link Arena}, that should be reset to NULL and
52+
* The callback function is allocated with the given {@link Arena} that should be
5453
* {@link Arena#close() closed} when no longer needed, which is often after destroying GL context.
5554
*
55+
* @param arena the arena to allocate the callback
5656
* @param gl the OpenGL context.
5757
* @param flags the OpenGL flags.
5858
* @param func the loading function
59-
* @return the arena.
6059
*/
61-
@Nullable
62-
public static Arena setupDebugMessageCallback(
60+
public static void setupDebugMessageCallback(
61+
Arena arena,
6362
GL43 gl,
6463
GLFlags flags,
6564
GLLoadFunc func
6665
) {
67-
return setupDebugMessageCallback(gl, flags, func, OverrunGL.apiLogger());
66+
setupDebugMessageCallback(arena, gl, flags, func, OverrunGL.apiLogger());
6867
}
6968

7069
/**
7170
* Detects the best debug output functionality to use and creates a callback that prints information to the specified
7271
* logger.
7372
* <p>
74-
* The callback function is returned as a {@link Arena}, that should be reset to NULL and
73+
* The callback function is allocated with the given {@link Arena} that should be
7574
* {@link Arena#close() closed} when no longer needed, which is often after destroying GL context.
7675
*
76+
* @param arena the arena to allocate the callback
7777
* @param gl the OpenGL context.
7878
* @param flags the OpenGL flags.
7979
* @param func the loading function
8080
* @param logger the output logger.
81-
* @return the arena.
8281
*/
83-
@Nullable
84-
public static Arena setupDebugMessageCallback(
82+
public static void setupDebugMessageCallback(
83+
Arena arena,
8584
GL43 gl,
8685
GLFlags flags,
8786
GLLoadFunc func,
@@ -93,7 +92,6 @@ public static Arena setupDebugMessageCallback(
9392
} else {
9493
apiLog("[GL] Using KHR_debug for error logging.");
9594
}
96-
var arena = Arena.ofConfined();
9795
gl.DebugMessageCallback(GLDebugProc.alloc(arena, (source, type, id, severity, _, message, _) -> {
9896
var sb = new StringBuilder(768);
9997
sb.append("[OverrunGL] OpenGL debug message\n");
@@ -121,12 +119,10 @@ public static Arena setupDebugMessageCallback(
121119
gl.Enable(GL_DEBUG_OUTPUT);
122120
}
123121
}
124-
return arena;
125122
}
126123

127124
if (flags.GL_ARB_debug_output) {
128125
apiLog("[GL] Using ARB_debug_output for error logging.");
129-
var arena = Arena.ofConfined();
130126
new GLARBDebugOutput(func).DebugMessageCallbackARB(GLDebugProc.alloc(arena, (source, type, id, severity, _, message, _) -> {
131127
var sb = new StringBuilder(768);
132128
sb.append("[OverrunGL] ARB_debug_output message\n");
@@ -141,12 +137,10 @@ public static Arena setupDebugMessageCallback(
141137
}
142138
logger.accept(sb.toString());
143139
}), MemorySegment.NULL);
144-
return arena;
145140
}
146141

147142
if (flags.GL_AMD_debug_output) {
148143
apiLog("[GL] Using AMD_debug_output for error logging.");
149-
var arena = Arena.ofConfined();
150144
new GLAMDDebugOutput(func).DebugMessageCallbackAMD(GLDebugProcAMD.alloc(arena, (id, category, severity, _, message, _) -> {
151145
var sb = new StringBuilder(768);
152146
sb.append("[OverrunGL] AMD_debug_output message\n");
@@ -160,11 +154,9 @@ public static Arena setupDebugMessageCallback(
160154
}
161155
logger.accept(sb.toString());
162156
}), MemorySegment.NULL);
163-
return arena;
164157
}
165158

166159
apiLog("[GL] No debug output implementation is available.");
167-
return null;
168160
}
169161

170162
private static void printDetail(StringBuilder sb, String type, String message) {

modules/samples/src/test/java/overrungl/demo/opengl/GL33Test.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class GL33Test {
5050
private int program;
5151
private int rotationMat;
5252
private int vao, vbo, ebo, mbo;
53-
private Arena debugProc;
5453

5554
private static int square(int x) {
5655
return x * x;
@@ -71,7 +70,6 @@ public void run() {
7170

7271
glfwDestroyWindow(window);
7372
windowArena.close();
74-
debugProc.close();
7573

7674
glfwTerminate();
7775
glfwSetErrorCallback(MemorySegment.NULL);
@@ -122,7 +120,7 @@ private void load(Arena arena) {
122120
gl = new GL(glLoadFunc);
123121

124122
var flags = new GLFlags(glLoadFunc);
125-
debugProc = GLUtil.setupDebugMessageCallback(gl, flags, glLoadFunc);
123+
GLUtil.setupDebugMessageCallback(Arena.global(), gl, flags, glLoadFunc);
126124
gl.ClearColor(0.4f, 0.6f, 0.9f, 1.0f);
127125
program = gl.CreateProgram();
128126
int vsh = gl.CreateShader(GL_VERTEX_SHADER);

0 commit comments

Comments
 (0)