From fe5bf090db687ef1dd1084218156bcbc0b801081 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 29 Dec 2012 14:13:20 +0200 Subject: [PATCH] Add a function to require the completeness of a framebuffer --- source/framebuffer.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++ source/framebuffer.h | 11 +++++++++++ 2 files changed, 54 insertions(+) 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 -- 2.43.0