From: Mikko Rasa Date: Sat, 29 Dec 2012 12:13:20 +0000 (+0200) Subject: Add a function to require the completeness of a framebuffer X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=fe5bf090db687ef1dd1084218156bcbc0b801081;p=libs%2Fgl.git Add a function to require the completeness of a framebuffer --- diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 98722195..4d6c1752 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -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(status, "%#x")); + break; + } +} + +framebuffer_incomplete::framebuffer_incomplete(FramebufferStatus status): + runtime_error(lexical_cast(status)) +{ } + + Framebuffer::Framebuffer(unsigned i): id(i), dirty(0) @@ -174,6 +210,13 @@ FramebufferStatus Framebuffer::check_status() const return static_cast(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); diff --git a/source/framebuffer.h b/source/framebuffer.h index 236d29e6..e25967ac 100644 --- a/source/framebuffer.h +++ b/source/framebuffer.h @@ -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