Add human readable error strings when creating the Fbo failed

This commit is contained in:
Matthias Richter
2010-08-11 20:29:47 +02:00
parent f87738edb5
commit e5c2f063e8
3 changed files with 36 additions and 6 deletions
+28 -2
View File
@@ -8,9 +8,35 @@ namespace graphics
namespace opengl
{
std::map<GLenum, const char*> Fbo::status_to_string;
Fbo::Fbo(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;
vertices[1].x = 0; vertices[1].y = height;
@@ -58,9 +84,9 @@ namespace opengl
glDeleteFramebuffers(1, &img);
}
GLenum Fbo::status() const
const char* Fbo::statusMessage() const
{
return status_;
status_to_string[statusCode()];
}
void Fbo::bind()
+6 -1
View File
@@ -4,6 +4,7 @@
#include <graphics/Drawable.h>
#include <graphics/Volatile.h>
#include <common/math.h>
#include <map>
#include "GLee.h"
namespace love
@@ -19,7 +20,9 @@ namespace opengl
Fbo(int width, int height);
virtual ~Fbo();
GLenum status() const; //SERIOUS DISLIKE HERE
// for internal use (w_newFbo <-> love.graphics.newFbo) only
GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE
const char* statusMessage() const;
void bind(); //DOUBTFUL ABOUT NAME
void unbind(); //Maybe start/stop?
@@ -37,6 +40,8 @@ namespace opengl
GLenum status_;
vertex vertices[4];
static std::map<GLenum, const char*> status_to_string;
};
} // opengl
@@ -300,9 +300,8 @@ namespace opengl
Fbo * fbo = instance->newFbo(width, height);
//and there we go with the status... still disliked
GLenum status = fbo->status();
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
return luaL_error(L, "Cannot create FBO: %d", status);
if (fbo->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT)
return luaL_error(L, "Cannot create FBO: %s", fbo->statusMessage());
luax_newtype(L, "Fbo", GRAPHICS_FBO_T, (void*)fbo);
return 1;
}