diff --git a/CMakeLists.txt b/CMakeLists.txt index ae3c6fb..f4e0f14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -set(BLT_GRAPHICS_VERSION 0.13.8) +set(BLT_GRAPHICS_VERSION 0.13.9) set(BLT_GRAPHICS_TEST_VERSION 0.0.1) project(BLT_WITH_GRAPHICS VERSION ${BLT_GRAPHICS_VERSION}) diff --git a/include/blt/gfx/gl_includes.h b/include/blt/gfx/gl_includes.h index 429d822..90df392 100644 --- a/include/blt/gfx/gl_includes.h +++ b/include/blt/gfx/gl_includes.h @@ -8,9 +8,13 @@ #ifndef BLT_GL_INCLUDES_H #define BLT_GL_INCLUDES_H +#include + // emscripten provides its own gl bindings. #ifndef __EMSCRIPTEN__ + #include + #else #include #include @@ -21,4 +25,40 @@ #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 diff --git a/include/blt/gfx/renderer/shaders/pp_screen.frag b/include/blt/gfx/renderer/shaders/pp_screen.frag index 5c97965..b87b9a0 100644 --- a/include/blt/gfx/renderer/shaders/pp_screen.frag +++ b/include/blt/gfx/renderer/shaders/pp_screen.frag @@ -4,7 +4,7 @@ const std::string shader_pp_screen_frag = R"(" #version 300 es precision mediump float; -out vec4 FragColor; +${LAYOUT_STRING} out vec4 FragColor; in vec2 uv; in vec2 pos; diff --git a/src/blt/gfx/framebuffer.cpp b/src/blt/gfx/framebuffer.cpp index f68cd95..9ea5838 100644 --- a/src/blt/gfx/framebuffer.cpp +++ b/src/blt/gfx/framebuffer.cpp @@ -222,7 +222,7 @@ namespace blt::gfx fbo.create(); fbo.bind(); - auto* texture = new texture_gl2D(width, height); + auto* texture = new texture_gl2D(width, height, GL_RGBA8); fbo.attachTexture(texture, attachment_t::COLOR0); render_buffer_t depth_rbo = render_buffer_t::make_render_buffer(GL_DEPTH24_STENCIL8, width, height); diff --git a/src/blt/gfx/renderer/postprocess.cpp b/src/blt/gfx/renderer/postprocess.cpp index c91a8ec..b060229 100644 --- a/src/blt/gfx/renderer/postprocess.cpp +++ b/src/blt/gfx/renderer/postprocess.cpp @@ -145,20 +145,21 @@ namespace blt::gfx void pp_in_place_t::post_draw(frame_buffer_t& previous) { - draw_buffer.blitTexture(previous, 0, 0, 0, 0, GL_NEAREST, from, to); -// previous.bind(); -// GLenum buf[32]; -// auto buff_val = static_cast(to); -// auto size = buff_val - GL_COLOR_ATTACHMENT0; -// for (GLenum i = 0; i < size; i++) -// buf[i] = GL_NONE; -// buf[size] = buff_val; -// glDrawBuffers(static_cast(size) + 1, buf); -// glClear(GL_COLOR_BUFFER_BIT); -// shader_pass->bind(); -// glActiveTexture(GL_TEXTURE0); -// draw_buffer.getTexture(frame_buffer_t::attachment_t::COLOR0).bind(); -// pp_engine_t::render_quad(); +// draw_buffer.blitTexture(previous, 0, 0, 0, 0, GL_NEAREST, from, to); + handle_errors(); + previous.bind(); + GLenum buf[32]; + auto to_val = static_cast(to); + auto size = to_val - GL_COLOR_ATTACHMENT0; + for (GLenum i = 0; i < size; i++) + buf[i] = GL_NONE; + buf[size] = to_val; + glDrawBuffers(static_cast(size) + 1, buf); + glClear(GL_COLOR_BUFFER_BIT); + shader_pass->bind(); + glActiveTexture(GL_TEXTURE0); + draw_buffer.getTexture(frame_buffer_t::attachment_t::COLOR0).bind(); + pp_engine_t::render_quad(); } void pp_in_place_t::draw(frame_buffer_t& previous) diff --git a/src/blt/gfx/window.cpp b/src/blt/gfx/window.cpp index 83dc50d..80712f7 100644 --- a/src/blt/gfx/window.cpp +++ b/src/blt/gfx/window.cpp @@ -27,6 +27,22 @@ void error_callback(int error, const char* description) std::abort(); } +void gl_error_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei, const GLchar* message, const void*) +{ + // do not log performance concerns + if (type == GL_DEBUG_TYPE_PERFORMANCE || type == GL_DEBUG_TYPE_OTHER) + return; + if (type == GL_DEBUG_TYPE_ERROR) + { + BLT_ERROR("[OpenGL Error] message = '%s', type = 0x%x, severity = 0x%x, source = 0x%x, id = %d", + message, type, severity, source, id); + } else + { + BLT_WARN("[OpenGL Error] message = '%s', type = 0x%x, severity = 0x%x, source = 0x%x, id = %d", + message, type, severity, source, id); + } +} + namespace blt::gfx { struct @@ -236,6 +252,9 @@ namespace blt::gfx gladLoadGL(glfwGetProcAddress); #endif + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(gl_error_callback, nullptr); + /* -- Set up our local callbacks, ImGUI will then call these -- */ create_callbacks();