diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 0881c468e..4a36940d1 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -9,34 +9,9 @@ namespace opengl { bool Framebuffer::isGrabbing = false; - std::map Framebuffer::status_to_string; - Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { - // maybe create status code messages - if (status_to_string.empty()) { - status_to_string[GL_FRAMEBUFFER_UNSUPPORTED] // the most important one - = "your opengl implementation does not support framebuffer objects"; - - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT] - = "framebuffer has incomplete attachments"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER] - = "incomplete draw buffer"; - - // the ones that should never, ever happen: - status_to_string[GL_FRAMEBUFFER_UNDEFINED] - = "default framebuffer does not exist"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] - = "framebuffer needs at least one image attached"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER] - = "incomplete read buffer"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE] - = "number of samples mismatch in attached buffers"; - // "Additionally, if an error occurs, zero is returned." and - // "GL_INVALID_ENUM is generated if target is not GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER or GL_FRAMEBUFFER." - status_to_string[0] = "Framebuffer hijacked by aliens"; - } // world coordinates vertices[0].x = 0; vertices[0].y = 0; @@ -85,11 +60,6 @@ namespace opengl glDeleteFramebuffers(1, &img); } - const char* Framebuffer::statusMessage() const - { - status_to_string[statusCode()]; - } - bool Framebuffer::grab() { // don't allow nesting or forgetting Framebuffer::stop() diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index b09408cda..8e3e9ec31 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -20,9 +20,7 @@ namespace opengl Framebuffer(int width, int height); virtual ~Framebuffer(); - // for internal use (w_newFramebuffer <-> love.graphics.newFramebuffer) only - GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE - const char* statusMessage() const; + unsigned int getStatus() const { return status_; } bool grab(); bool stop(); @@ -41,7 +39,6 @@ namespace opengl vertex vertices[4]; GLenum status_; - static std::map status_to_string; }; } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index e67684492..fd3f04d0a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -297,12 +297,26 @@ namespace opengl int width, height; width = luaL_checkint(L, 1); height = luaL_checkint(L, 2); - Framebuffer * Framebuffer = instance->newFramebuffer(width, height); + Framebuffer * framebuffer = instance->newFramebuffer(width, height); //and there we go with the status... still disliked - if (Framebuffer->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT) - return luaL_error(L, "Cannot create Framebuffer: %s", Framebuffer->statusMessage()); - luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)Framebuffer); + if (framebuffer->getStatus() != GL_FRAMEBUFFER_COMPLETE) { + switch (framebuffer->getStatus()) { + case GL_FRAMEBUFFER_UNSUPPORTED: + return luaL_error(L, "Cannot create Framebuffer: " + "Not supported by your OpenGL implementation"); + // remaining error codes are highly unlikely: + // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, + // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER + // GL_FRAMEBUFFER_UNDEFINED + // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT + // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER + // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE + default: + return luaL_error(L, "Cannot create Framebuffer: Aliens did it"); + } + } + luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)framebuffer); return 1; }