BLT-With-Graphics-Template/include/blt/gfx/gl_includes.h

65 lines
1.6 KiB
C++

#pragma once
/*
* Created by Brett on 16/12/23.
* Licensed under GNU General Public License V3.0
* See LICENSE file for license detail
*/
#ifndef BLT_GL_INCLUDES_H
#define BLT_GL_INCLUDES_H
#include <blt/std/logging.h>
// emscripten provides its own gl bindings.
#ifndef __EMSCRIPTEN__
#include <glad/gl.h>
#else
#include <GLES2/gl2.h>
#include <GLES3/gl3.h>
#include <GLES3/gl31.h>
#include <GLES3/gl32.h>
#include <emscripten.h>
#define GL_GLEXT_PROTOTYPES
#define EGL_EGLEXT_PROTOTYPES
#endif
namespace blt::gfx
{
inline std::string get_error_message(GLenum error)
{
switch (error)
{
case GL_INVALID_ENUM:
return "Invalid Enum";
case GL_INVALID_VALUE:
return "Invalid Value";
case GL_INVALID_OPERATION:
return "Invalid Operation";
case GL_STACK_OVERFLOW:
return "Stack Overflow";
case GL_STACK_UNDERFLOW:
return "Stack Underflow";
case GL_OUT_OF_MEMORY:
return "Out Of Memory";
case GL_INVALID_FRAMEBUFFER_OPERATION:
return "Invalid Framebuffer Operation";
case GL_INVALID_INDEX:
return "Invalid Index";
}
return std::string("Unknown Error: ") += std::to_string(error);
}
inline void handle_errors()
{
GLenum err;
while ((err = glGetError()) != GL_NO_ERROR)
{
BLT_ERROR(get_error_message(err));
}
}
}
#endif //BLT_GL_INCLUDES_H