Skip to content

Instantly share code, notes, and snippets.

@exaskye
Last active November 26, 2019 11:05
Show Gist options
  • Select an option

  • Save exaskye/a4165d57d2069f056ddd8a1f59285a5c to your computer and use it in GitHub Desktop.

Select an option

Save exaskye/a4165d57d2069f056ddd8a1f59285a5c to your computer and use it in GitHub Desktop.

Revisions

  1. exaskye revised this gist Oct 18, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions _output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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)

  2. exaskye revised this gist Oct 18, 2018. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions OpenGLDebug.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    package com.unascribed.chipper;

    import static org.lwjgl.opengl.GL11.*;
    import static org.lwjgl.opengl.GL43.*;
    import static org.lwjgl.system.MemoryUtil.*;
    @@ -46,13 +48,13 @@ public static void install() {
    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("[{} | {}] {} {}", type, source, idHex, message);
    log.debug("{} {}: {} {}", source, type, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_LOW) {
    log.info("[{} | {}] {} {}", type, source, idHex, message);
    log.info("{} {}: {} {}", source, type, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_MEDIUM) {
    log.warn("[{} | {}] {} {}", type, source, idHex, message);
    log.warn("{} {}: {} {}", source, type, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_HIGH) {
    log.error("[{} | {}] {} {}", type, source, idHex, message, new Throwable().fillInStackTrace());
    log.error("{} {}: {} {}", source, type, idHex, message, new Throwable().fillInStackTrace());
    }
    }, NULL);
    }
  3. exaskye revised this gist Oct 18, 2018. No changes.
  4. exaskye created this gist Oct 18, 2018.
    61 changes: 61 additions & 0 deletions OpenGLDebug.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    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("[{} | {}] {} {}", type, source, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_LOW) {
    log.info("[{} | {}] {} {}", type, source, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_MEDIUM) {
    log.warn("[{} | {}] {} {}", type, source, idHex, message);
    } else if (severity == GL_DEBUG_SEVERITY_HIGH) {
    log.error("[{} | {}] {} {}", type, source, idHex, message, new Throwable().fillInStackTrace());
    }
    }, NULL);
    }
    }

    }