]> git.tdb.fi Git - libs/gl.git/commitdiff
Add a function to require the completeness of a framebuffer
authorMikko Rasa <tdb@tdb.fi>
Sat, 29 Dec 2012 12:13:20 +0000 (14:13 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 29 Dec 2012 12:14:24 +0000 (14:14 +0200)
source/framebuffer.cpp
source/framebuffer.h

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);
index 236d29e6a3dd65a8fddcf3bdc567b92530b80c21..e25967aca41ddfd6b29bfa6aae211e473e1807f2 100644 (file)
@@ -57,6 +57,13 @@ enum RWBuffer
        FRONT_AND_BACK = GL_FRONT_AND_BACK
 };
 
+class framebuffer_incomplete: public std::runtime_error
+{
+public:
+       framebuffer_incomplete(FramebufferStatus);
+       virtual ~framebuffer_incomplete() throw() { }
+};
+
 /**
 Framebuffer objects can be used to perform offscreen rendering.  The most
 common application is rendering to a texture, which can then be used for
@@ -119,6 +126,10 @@ public:
        or one of the error status codes otherwise. */
        FramebufferStatus check_status() const;
 
+       /** Ensures that the framebuffer is complete, throwing an exception if it
+       isn't. */
+       void require_complete() const;
+
        void clear(BufferBits);
 
        /** Blits a region from another framebuffer into this one.  If the source