Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
java.lang.Throwable
at com.unascribed.chipper.OpenGLDebug.lambda$0(OpenGLDebug.java:57)
at org.lwjgl.opengl.GLDebugMessageCallbackI.callback(GLDebugMessageCallbackI.java:39)
at org.lwjgl.opengl.GL11C.glEnable(Native Method)
at org.lwjgl.opengl.GL11.glEnable(GL11.java:777)
at com.unascribed.chipper.Chipper.main(Chipper.java:133)
[16:15:18.764] [E/OpenGL] API Error: 0x3 GL_INVALID_ENUM in glEnable(GL_FRONT)
package com.unascribed.chipper;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL43.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLDebugMessageCallbackI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OpenGLDebug {
private static final Logger log = LoggerFactory.getLogger("OpenGL");
@SuppressWarnings("unused")
private static GLDebugMessageCallbackI callback;
private static Map<Integer, String> strings = new HashMap<>();
static {
strings.put(GL_DEBUG_SOURCE_API, "API");
strings.put(GL_DEBUG_SOURCE_WINDOW_SYSTEM, "Window System");
strings.put(GL_DEBUG_SOURCE_SHADER_COMPILER, "Shader Compiler");
strings.put(GL_DEBUG_SOURCE_THIRD_PARTY, "Third Party");
strings.put(GL_DEBUG_SOURCE_APPLICATION, "Application");
strings.put(GL_DEBUG_SOURCE_OTHER, "Other");
strings.put(GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, "Deprecated Behavior");
strings.put(GL_DEBUG_TYPE_ERROR, "Error");
strings.put(GL_DEBUG_TYPE_MARKER, "Marker");
strings.put(GL_DEBUG_TYPE_OTHER, "Other");
strings.put(GL_DEBUG_TYPE_PERFORMANCE, "Performance");
strings.put(GL_DEBUG_TYPE_POP_GROUP, "Pop Group");
strings.put(GL_DEBUG_TYPE_PORTABILITY, "Portability");
strings.put(GL_DEBUG_TYPE_PUSH_GROUP, "Push Group");
strings.put(GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR, "Undefined Behavior");
}
public static void install() {
if (GL.getCapabilities().OpenGL43 || GL.getCapabilities().GL_KHR_debug) {
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(callback = (sourceId, typeId, id, severity, length, messagePtr, userParam) -> {
String message = memASCII(messagePtr);
String source = strings.containsKey(sourceId) ? strings.get(sourceId) : "Unknown";
String type = strings.containsKey(typeId) ? strings.get(typeId) : "Unknown";
String idHex = "0x"+Integer.toHexString(id).toUpperCase(Locale.ROOT);
if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) {
log.debug("{} {}: {} {}", source, type, idHex, message);
} else if (severity == GL_DEBUG_SEVERITY_LOW) {
log.info("{} {}: {} {}", source, type, idHex, message);
} else if (severity == GL_DEBUG_SEVERITY_MEDIUM) {
log.warn("{} {}: {} {}", source, type, idHex, message);
} else if (severity == GL_DEBUG_SEVERITY_HIGH) {
log.error("{} {}: {} {}", source, type, idHex, message, new Throwable().fillInStackTrace());
}
}, NULL);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment