X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fframebuffer.cpp;h=1c2ae519bade1ef1059df7ff1a43dbdd33a23440;hb=0221e39a685c4f3122a0fae032a7888b5ce40579;hp=ae8f4dd471a936881f77e8e569de8e97ba5bc8c0;hpb=a86623004ba91baef76dac9275e9b79366acce16;p=libs%2Fgl.git diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index ae8f4dd4..1c2ae519 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "error.h" #include "framebuffer.h" #include "misc.h" @@ -55,10 +56,9 @@ Framebuffer::Framebuffer(unsigned i): if(id) throw invalid_argument("System framebuffer must have id 0"); - int viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - width = viewport[2]; - height = viewport[3]; + glGetIntegerv(GL_VIEWPORT, &view.left); + width = view.width; + height = view.height; } Framebuffer::Framebuffer(): @@ -110,22 +110,17 @@ void Framebuffer::update_attachment(unsigned mask) const color_bufs.push_back(attch.attachment); } - 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 - { + if(color_bufs.size()>1) static Require _req(ARB_draw_buffers); + + GLenum first_buffer = (color_bufs.empty() ? GL_NONE : color_bufs.front()); + if(ARB_draw_buffers) glDrawBuffers(color_bufs.size(), &color_bufs[0]); - glReadBuffer(color_bufs.front()); - } + else if(MSP_draw_buffer) + glDrawBuffer(first_buffer); + + if(MSP_draw_buffer) + glReadBuffer(first_buffer); } else dirty |= mask; @@ -133,6 +128,7 @@ void Framebuffer::update_attachment(unsigned mask) const void Framebuffer::check_size() { + bool full_viewport = (view.left==0 && view.bottom==0 && view.width==width && view.height==height); for(vector::iterator i=attachments.begin(); i!=attachments.end(); ++i) if(i->type) { @@ -152,8 +148,8 @@ void Framebuffer::check_size() width = static_cast(i->tex)->get_size(); height = width; } - if(current()==this) - glViewport(0, 0, width, height); + if(full_viewport) + reset_viewport(); break; } } @@ -213,7 +209,7 @@ void Framebuffer::detach(FramebufferAttachment attch) FramebufferStatus Framebuffer::check_status() const { - Bind _bind(this, true); + BindRestore _bind(this); return static_cast(glCheckFramebufferStatus(GL_FRAMEBUFFER)); } @@ -224,9 +220,25 @@ void Framebuffer::require_complete() const throw framebuffer_incomplete(status); } +void Framebuffer::viewport(int l, int b, unsigned w, unsigned h) +{ + view.left = l; + view.bottom = b; + view.width = w; + view.height = h; + + if(current()==this) + glViewport(view.left, view.bottom, view.width, view.height); +} + +void Framebuffer::reset_viewport() +{ + viewport(0, 0, width, height); +} + void Framebuffer::clear(BufferBits bits) { - Bind _bind(this, true); + BindRestore _bind(this); glClear(bits); } @@ -273,8 +285,9 @@ void Framebuffer::bind() const update_attachment(dirty); dirty = 0; } + if(width && height) - glViewport(0, 0, width, height); + glViewport(view.left, view.bottom, view.width, view.height); } } @@ -323,5 +336,13 @@ void Framebuffer::Attachment::clear() type = 0; } + +Framebuffer::Viewport::Viewport(): + left(0), + bottom(0), + width(0), + height(0) +{ } + } // namespace GL } // namespace Msp