Skip to content

Instantly share code, notes, and snippets.

@DenisNasc
Forked from liam-middlebrook/GLDebugMessageCallback.c
Last active September 15, 2020 20:48
Show Gist options
  • Select an option

  • Save DenisNasc/cb36219511ba0a914be5c8c1fa5a068b to your computer and use it in GitHub Desktop.

Select an option

Save DenisNasc/cb36219511ba0a914be5c8c1fa5a068b to your computer and use it in GitHub Desktop.

Revisions

  1. DenisNasc renamed this gist Sep 15, 2020. 1 changed file with 5 additions and 28 deletions.
    33 changes: 5 additions & 28 deletions GLDebugMessageCallback.c → GLDebugMessageCallback.cpp
    Original file line number Diff line number Diff line change
    @@ -1,35 +1,13 @@
    // This is free and unencumbered software released into the public domain.
    //
    // Anyone is free to copy, modify, publish, use, compile, sell, or distribute
    // this software, either in source code form or as a compiled binary, for any
    // purpose, commercial or non-commercial, and by any means.
    //
    // In jurisdictions that recognize copyright laws, the author or authors of this
    // software dedicate any and all copyright interest in the software to the
    // public domain. We make this dedication for the benefit of the public at large
    // and to the detriment of our heirs and successors. We intend this dedication
    // to be an overt act of relinquishment in perpetuity of all present and future
    // rights to this software under copyright law.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    //
    // For more information, please refer to <http://unlicense.org/>

    // REQUIREMENTS: OpenGL version with the KHR_debug extension available.
    // Função para gerenciar erros do OpenGL >4.3

    // Callback function for printing debug statements
    void APIENTRY GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    GLenum severity, GLsizei length,
    const GLchar *msg, const void *data)
    {
    char* _source;
    char* _type;
    char* _severity;
    const char* _source;
    const char* _type;
    const char* _severity;

    switch (source) {
    case GL_DEBUG_SOURCE_API:
    @@ -117,8 +95,7 @@ void APIENTRY GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    break;
    }

    printf("%d: %s of %s severity, raised from %s: %s\n",
    id, _type, _severity, _source, msg);
    std::cout << id <<": " << _type << " of " << _severity << " severity, raised from " << _source <<": " << msg << std::endl;
    }

    // =============== INIT DEBUG OUTPUT ================
  2. @liam-middlebrook liam-middlebrook revised this gist Sep 2, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions GLDebugMessageCallback.c
    Original file line number Diff line number Diff line change
    @@ -23,9 +23,9 @@
    // REQUIREMENTS: OpenGL version with the KHR_debug extension available.

    // Callback function for printing debug statements
    void GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    void APIENTRY GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    GLenum severity, GLsizei length,
    const GLchar *msg, void *data)
    const GLchar *msg, const void *data)
    {
    char* _source;
    char* _type;
    @@ -131,7 +131,7 @@ void GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    // GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint
    // can be placed on the callback in order to get a stacktrace for the GL error.

    glEnable(GL_DEBUG_OUTPUT_SYNCHRONUS);
    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);

    // Set the function that will be triggered by the callback, the second parameter
    // is the data parameter of the callback, it can be useful for different
  3. @liam-middlebrook liam-middlebrook revised this gist Aug 19, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions GLDebugMessageCallback.c
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,8 @@
    //
    // For more information, please refer to <http://unlicense.org/>

    // REQUIREMENTS: OpenGL version with the KHR_debug extension available.

    // Callback function for printing debug statements
    void GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    GLenum severity, GLsizei length,
  4. @liam-middlebrook liam-middlebrook created this gist Aug 19, 2015.
    137 changes: 137 additions & 0 deletions GLDebugMessageCallback.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,137 @@
    // This is free and unencumbered software released into the public domain.
    //
    // Anyone is free to copy, modify, publish, use, compile, sell, or distribute
    // this software, either in source code form or as a compiled binary, for any
    // purpose, commercial or non-commercial, and by any means.
    //
    // In jurisdictions that recognize copyright laws, the author or authors of this
    // software dedicate any and all copyright interest in the software to the
    // public domain. We make this dedication for the benefit of the public at large
    // and to the detriment of our heirs and successors. We intend this dedication
    // to be an overt act of relinquishment in perpetuity of all present and future
    // rights to this software under copyright law.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
    // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    //
    // For more information, please refer to <http://unlicense.org/>

    // Callback function for printing debug statements
    void GLDebugMessageCallback(GLenum source, GLenum type, GLuint id,
    GLenum severity, GLsizei length,
    const GLchar *msg, void *data)
    {
    char* _source;
    char* _type;
    char* _severity;

    switch (source) {
    case GL_DEBUG_SOURCE_API:
    _source = "API";
    break;

    case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
    _source = "WINDOW SYSTEM";
    break;

    case GL_DEBUG_SOURCE_SHADER_COMPILER:
    _source = "SHADER COMPILER";
    break;

    case GL_DEBUG_SOURCE_THIRD_PARTY:
    _source = "THIRD PARTY";
    break;

    case GL_DEBUG_SOURCE_APPLICATION:
    _source = "APPLICATION";
    break;

    case GL_DEBUG_SOURCE_OTHER:
    _source = "UNKNOWN";
    break;

    default:
    _source = "UNKNOWN";
    break;
    }

    switch (type) {
    case GL_DEBUG_TYPE_ERROR:
    _type = "ERROR";
    break;

    case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
    _type = "DEPRECATED BEHAVIOR";
    break;

    case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
    _type = "UDEFINED BEHAVIOR";
    break;

    case GL_DEBUG_TYPE_PORTABILITY:
    _type = "PORTABILITY";
    break;

    case GL_DEBUG_TYPE_PERFORMANCE:
    _type = "PERFORMANCE";
    break;

    case GL_DEBUG_TYPE_OTHER:
    _type = "OTHER";
    break;

    case GL_DEBUG_TYPE_MARKER:
    _type = "MARKER";
    break;

    default:
    _type = "UNKNOWN";
    break;
    }

    switch (severity) {
    case GL_DEBUG_SEVERITY_HIGH:
    _severity = "HIGH";
    break;

    case GL_DEBUG_SEVERITY_MEDIUM:
    _severity = "MEDIUM";
    break;

    case GL_DEBUG_SEVERITY_LOW:
    _severity = "LOW";
    break;

    case GL_DEBUG_SEVERITY_NOTIFICATION:
    _severity = "NOTIFICATION";
    break;

    default:
    _severity = "UNKNOWN";
    break;
    }

    printf("%d: %s of %s severity, raised from %s: %s\n",
    id, _type, _severity, _source, msg);
    }

    // =============== INIT DEBUG OUTPUT ================
    // The following function calls should be made directly after OpenGL
    // initialization.

    // Enable the debugging layer of OpenGL
    //
    // GL_DEBUG_OUTPUT - Faster version but not useful for breakpoints
    // GL_DEBUG_OUTPUT_SYNCHRONUS - Callback is in sync with errors, so a breakpoint
    // can be placed on the callback in order to get a stacktrace for the GL error.

    glEnable(GL_DEBUG_OUTPUT_SYNCHRONUS);

    // Set the function that will be triggered by the callback, the second parameter
    // is the data parameter of the callback, it can be useful for different
    // contexts but isn't necessary for our simple use case.
    glDebugMessageCallback(GLDebugMessageCallback, NULL);