#include <glad/glad.h>
#include <string>
#include <iostream>

#include <opengl-debug.hpp>

static void debugBreak() {
    return;
}

namespace OpenGLDebug {
    // Print out all of the errors generated by the previous OpenGL call
    void printErrors(std::string_view file, int line) {
        unsigned int code = 0;
        while ((code = glGetError()) != GL_NO_ERROR) {
            std::string error;
            switch (code) {
            case GL_INVALID_ENUM:
                error = "GL_INVALID_ENUM";
                break;
            case GL_INVALID_VALUE:
                error = "GL_INVALID_VALUE";
                break;
            case GL_INVALID_OPERATION:
                error = "GL_INVALID_OPERATION";
                break;
            case GL_INVALID_FRAMEBUFFER_OPERATION:
                error = "GL_INVALID_FRAMEBUFFER_OPERATION";
                break;
            case GL_STACK_OVERFLOW:
                error = "GL_STACK_OVERFLOW";
                break;
            case GL_STACK_UNDERFLOW:
                error = "GL_STACK_UNDERFLOW";
                break;
            case GL_OUT_OF_MEMORY:
                error = "GL_OUT_OF_MEMORY";
                break;
            }
            
            std::cerr << "[OPENGL ERROR]: " << error << " at " << file << "[" << line << "]" << std::endl;
            debugBreak();
        }
    }
}