]> git.tdb.fi Git - libs/gl.git/blobdiff - source/framebuffer.cpp
Add a function to require the completeness of a framebuffer
[libs/gl.git] / source / framebuffer.cpp
index 98722195e32e8b10d40a43ab3d458d4c1ae5f4af..4d6c1752593cdbe54ac60f33d595af5dc1cd6491 100644 (file)
@@ -12,6 +12,42 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
+void operator<<(LexicalConverter &conv, FramebufferStatus status)
+{
+       switch(status)
+       {
+       case FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+               conv.result("incomplete attachment");
+               break;
+       case FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+               conv.result("missing attachment");
+               break;
+       case FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+               conv.result("mismatched attachment dimensions");
+               break;
+       case FRAMEBUFFER_INCOMPLETE_FORMATS:
+               conv.result("mismatched attachment formats");
+               break;
+       case FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
+               conv.result("missing draw buffer attachment");
+               break;
+       case FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
+               conv.result("missing read buffer attachment");
+               break;
+       case FRAMEBUFFER_UNSUPPORTED:
+               conv.result("unsupported");
+               break;
+       default:
+               conv.result(lexical_cast<string, unsigned>(status, "%#x"));
+               break;
+       }
+}
+
+framebuffer_incomplete::framebuffer_incomplete(FramebufferStatus status):
+       runtime_error(lexical_cast<string>(status))
+{ }
+
+
 Framebuffer::Framebuffer(unsigned i):
        id(i),
        dirty(0)
@@ -174,6 +210,13 @@ FramebufferStatus Framebuffer::check_status() const
        return static_cast<FramebufferStatus>(glCheckFramebufferStatus(GL_FRAMEBUFFER));
 }
 
+void Framebuffer::require_complete() const
+{
+       FramebufferStatus status = check_status();
+       if(status!=FRAMEBUFFER_COMPLETE)
+               throw framebuffer_incomplete(status);
+}
+
 void Framebuffer::clear(BufferBits bits)
 {
        Bind _bind(this, true);