#ifndef _PIUMA_RENDER_GL_HELPERS_H_
#define _PIUMA_RENDER_GL_HELPERS_H_

#include "../debug/logger.h"

inline void APIENTRY glDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char *message, const void *userParam)
{
    // ignore non-significant error/warning codes
    if(id == 131169 || id == 131185 || id == 131218 || id == 131204)
    	return;

    if (severity == GL_DEBUG_SEVERITY_NOTIFICATION)
    	return;

    // @Cleanup: LOG does not replace printf here. We need to merge the multiple printfs into a single log message
    LOG(LOG_DEBUG, "---------------");
    LOG(LOG_DEBUG, "Debug message (%u): %s", id, message);

    switch (source)
    {
        case GL_DEBUG_SOURCE_API:             LOG(LOG_DEBUG, "Source: API");             break;
        case GL_DEBUG_SOURCE_WINDOW_SYSTEM:   LOG(LOG_DEBUG, "Source: Window System");   break;
        case GL_DEBUG_SOURCE_SHADER_COMPILER: LOG(LOG_DEBUG, "Source: Shader Compiler"); break;
        case GL_DEBUG_SOURCE_THIRD_PARTY:     LOG(LOG_DEBUG, "Source: Third Party");     break;
        case GL_DEBUG_SOURCE_APPLICATION:     LOG(LOG_DEBUG, "Source: Application");     break;
        case GL_DEBUG_SOURCE_OTHER:           LOG(LOG_DEBUG, "Source: Other");           break;
    }

    switch (type)
    {
        case GL_DEBUG_TYPE_ERROR:               LOG(LOG_DEBUG, "Type: Error");                break;
        case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: LOG(LOG_DEBUG, "Type: Deprecated Behaviour"); break;
        case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:  LOG(LOG_DEBUG, "Type: Undefined Behaviour");  break;
        case GL_DEBUG_TYPE_PORTABILITY:         LOG(LOG_DEBUG, "Type: Portability");          break;
        case GL_DEBUG_TYPE_PERFORMANCE:         LOG(LOG_DEBUG, "Type: Performance");          break;
        case GL_DEBUG_TYPE_MARKER:              LOG(LOG_DEBUG, "Type: Marker");               break;
        case GL_DEBUG_TYPE_PUSH_GROUP:          LOG(LOG_DEBUG, "Type: Push Group");           break;
        case GL_DEBUG_TYPE_POP_GROUP:           LOG(LOG_DEBUG, "Type: Pop Group");            break;
        case GL_DEBUG_TYPE_OTHER:               LOG(LOG_DEBUG, "Type: Other");                break;
    }

    switch (severity)
    {
        case GL_DEBUG_SEVERITY_HIGH:         LOG(LOG_DEBUG, "Severity: high");         break;
        case GL_DEBUG_SEVERITY_MEDIUM:       LOG(LOG_DEBUG, "Severity: medium");       break;
        case GL_DEBUG_SEVERITY_LOW:          LOG(LOG_DEBUG, "Severity: low");          break;
        case GL_DEBUG_SEVERITY_NOTIFICATION: LOG(LOG_DEBUG, "Severity: notification"); break;
    }
    LOG(LOG_DEBUG, "");
}

#endif
