X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fframebuffer.cpp;h=8c618ce51b7112ba96f4332cb1e08de683744397;hp=672495182f7f641bbf419c2ea5b35dd28af6c28e;hb=357acfb941a8b5b4a6fb36e2134707d46e028d88;hpb=aa4d25153b806a657ac3b4b0f2711f2a126f39b7 diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 67249518..8c618ce5 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -55,10 +55,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(): @@ -133,6 +132,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 +152,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; } } @@ -224,6 +224,22 @@ 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) { BindRestore _bind(this); @@ -273,8 +289,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 +340,13 @@ void Framebuffer::Attachment::clear() type = 0; } + +Framebuffer::Viewport::Viewport(): + left(0), + bottom(0), + width(0), + height(0) +{ } + } // namespace GL } // namespace Msp