From 5aa9e68d6f1170121347be6103a2f2b34fb8b5aa Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 24 Nov 2025 22:03:50 +0300 Subject: [PATCH 1/3] improve framebuffer creation error messages --- src/graphics/core/Framebuffer.cpp | 9 +++++++-- src/graphics/core/gl_util.hpp | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/graphics/core/Framebuffer.cpp b/src/graphics/core/Framebuffer.cpp index bb360b54..73afee97 100644 --- a/src/graphics/core/Framebuffer.cpp +++ b/src/graphics/core/Framebuffer.cpp @@ -3,6 +3,7 @@ #include #include "Texture.hpp" #include "debug/Logger.hpp" +#include "gl_util.hpp" static debug::Logger logger("gl-framebuffer"); @@ -48,8 +49,12 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha) glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - logger.error() << "framebuffer is not complete!"; + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + auto logLine = logger.error(); + logLine << "framebuffer is not complete: "; + logLine << gl::to_string(status); + logLine << " (" << status << ")"; } glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/src/graphics/core/gl_util.hpp b/src/graphics/core/gl_util.hpp index da2abfb5..75402d4d 100644 --- a/src/graphics/core/gl_util.hpp +++ b/src/graphics/core/gl_util.hpp @@ -45,4 +45,26 @@ namespace gl { } return 0; } + + /// TODO: extend + inline const char* to_string(GLenum item) { + switch (item) { + case GL_FRAMEBUFFER_UNDEFINED: + return "framebuffer undefined"; + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + return "framebuffer incomplete attachment"; + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + return "framebuffer incomplete missing attachment"; + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + return "framebuffer incomplete draw buffer"; + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + return "framebuffer incomplete read buffer"; + case GL_FRAMEBUFFER_UNSUPPORTED: + return "framebuffer unsupported"; + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + return "framebuffer incomplete multisample"; + default: + return "unknown"; + } + } } From be6710bc831f700bd9099860c704b3571d1d90fa Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 24 Nov 2025 22:15:38 +0300 Subject: [PATCH 2/3] fix modelviewer fbo creation --- src/graphics/core/Framebuffer.cpp | 32 ++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/graphics/core/Framebuffer.cpp b/src/graphics/core/Framebuffer.cpp index 73afee97..61d2ea06 100644 --- a/src/graphics/core/Framebuffer.cpp +++ b/src/graphics/core/Framebuffer.cpp @@ -20,21 +20,35 @@ Framebuffer::Framebuffer(uint fbo, uint depth, std::unique_ptr texture) } static std::unique_ptr create_texture(int width, int height, int format) { - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, nullptr); + GLuint texture; + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D( + GL_TEXTURE_2D, + 0, + format, + width, + height, + 0, + format, + GL_UNSIGNED_BYTE, + nullptr + ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0); - return std::make_unique(tex, width, height); + glFramebufferTexture2D( + GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0 + ); + return std::make_unique(texture, width, height); } Framebuffer::Framebuffer(uint width, uint height, bool alpha) : width(width), height(height) { + width = std::max(1, width); + height = std::max(1, height); glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -46,8 +60,8 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha) // Setup depth attachment glGenRenderbuffers(1, &depth); glBindRenderbuffer(GL_RENDERBUFFER, depth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { @@ -83,7 +97,7 @@ void Framebuffer::resize(uint width, uint height) { glBindFramebuffer(GL_FRAMEBUFFER, fbo); glBindRenderbuffer(GL_RENDERBUFFER, depth); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); glBindRenderbuffer(GL_RENDERBUFFER, 0); texture = create_texture(width, height, format); From 6f765cda7c157d1998001844d7adde9a55e89d08 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 24 Nov 2025 22:24:38 +0300 Subject: [PATCH 3/3] update gl::to_string --- src/graphics/core/Framebuffer.cpp | 4 +++- src/graphics/core/gl_util.hpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/graphics/core/Framebuffer.cpp b/src/graphics/core/Framebuffer.cpp index 61d2ea06..abac8154 100644 --- a/src/graphics/core/Framebuffer.cpp +++ b/src/graphics/core/Framebuffer.cpp @@ -61,7 +61,9 @@ Framebuffer::Framebuffer(uint width, uint height, bool alpha) glGenRenderbuffers(1, &depth); glBindRenderbuffer(GL_RENDERBUFFER, depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth); + glFramebufferRenderbuffer( + GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depth + ); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { diff --git a/src/graphics/core/gl_util.hpp b/src/graphics/core/gl_util.hpp index 75402d4d..e82988ab 100644 --- a/src/graphics/core/gl_util.hpp +++ b/src/graphics/core/gl_util.hpp @@ -49,6 +49,20 @@ namespace gl { /// TODO: extend inline const char* to_string(GLenum item) { switch (item) { + 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_FRAMEBUFFER_UNDEFINED: return "framebuffer undefined"; case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: