X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fframebuffer.cpp;h=672495182f7f641bbf419c2ea5b35dd28af6c28e;hb=61ff840cd211f10d45dca8c4dad2cca5f68aaa42;hp=43b0f94b82e4c882327ef686491453a1bc7cf263;hpb=6afbace895a7bbcf216ab8e48280ea0303ab5892;p=libs%2Fgl.git diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 43b0f94b..67249518 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -1,6 +1,7 @@ +#include +#include +#include #include "error.h" -#include "ext_framebuffer_blit.h" -#include "ext_framebuffer_object.h" #include "framebuffer.h" #include "misc.h" #include "renderbuffer.h" @@ -11,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) @@ -46,7 +83,8 @@ void Framebuffer::update_attachment(unsigned mask) const { if(current()==this) { - GLenum color_buf = GL_NONE; + std::vector color_bufs; + color_bufs.reserve(attachments.size()); for(unsigned i=0; i=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3) - color_buf = attch.attachment; + color_bufs.push_back(attch.attachment); } - glDrawBuffer(color_buf); + if(color_bufs.empty()) + { + glDrawBuffer(GL_NONE); + glReadBuffer(GL_NONE); + } + else if(color_bufs.size()==1) + { + glDrawBuffer(color_bufs.front()); + glReadBuffer(color_bufs.front()); + } + else + { + static Require _req(ARB_draw_buffers); + glDrawBuffers(color_bufs.size(), &color_bufs[0]); + glReadBuffer(color_bufs.front()); + } } else dirty |= mask; @@ -160,13 +213,20 @@ void Framebuffer::detach(FramebufferAttachment attch) FramebufferStatus Framebuffer::check_status() const { - Bind _bind(this, true); + BindRestore _bind(this); 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); + BindRestore _bind(this); glClear(bits); } @@ -219,7 +279,7 @@ void Framebuffer::bind() const } const Framebuffer *Framebuffer::current() -{ +{ if(!cur_obj) cur_obj = &system(); return cur_obj;