-
Notifications
You must be signed in to change notification settings - Fork 0
/
Callbacks.java
51 lines (45 loc) · 1.87 KB
/
Callbacks.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
*/
package org.lwjgl.glfw;
import org.lwjgl.system.*;
import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.JNI.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.lang.reflect.*;
/** Utility class for GLFW callbacks. */
public final class Callbacks {
private Callbacks() {}
/**
* Resets all callbacks for the specified GLFW window to {@code NULL} and {@link Callback#free frees} all previously set callbacks.
*
* <p>This method resets only callbacks registered with a GLFW window. Non-window callbacks (registered with
* {@link GLFW#glfwSetErrorCallback SetErrorCallback}, {@link GLFW#glfwSetMonitorCallback SetMonitorCallback}, etc.) must be reset and freed
* separately.</p>
*
* <p>This method is not official GLFW API. It exists in LWJGL to simplify window callback cleanup.</p>
*
* @param window the GLFW window
*/
public static void glfwFreeCallbacks(@NativeType("GLFWwindow *") long window) {
if (Checks.CHECKS) {
check(window);
}
try {
for (Method callback : GLFW.class.getMethods()) {
if (callback.getName().startsWith("glfwSet") && callback.getName().endsWith("Callback")) {
if (callback.getParameterCount() == 1) {
callback.invoke(null, (Object)null);
} else {
callback.invoke(null, GLFW.glfwGetCurrentContext(), null);
}
}
}
} catch (IllegalAccessException|NullPointerException e) {
throw new RuntimeException("org.lwjgl.GLFW.glfwSetXXXCallback() must be set to public and static", e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}