X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fframebuffer.cpp;h=4dbb30929e05dc38ff822c981b51e251613f61bb;hb=ce36589;hp=23b39f2d691c8de06aeaf378be10c25fe39db601;hpb=2b2676392aff2eb6b38c3e463cc67f4d67a4ef8b;p=libs%2Fgl.git diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 23b39f2d..4dbb3092 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -12,6 +11,7 @@ #include "renderbuffer.h" #include "texture2d.h" #include "texture3d.h" +#include "windowview.h" using namespace std; @@ -65,19 +65,22 @@ framebuffer_incomplete::framebuffer_incomplete(FramebufferStatus status): Framebuffer::Framebuffer(unsigned i): id(i), + status(FRAMEBUFFER_COMPLETE), dirty(0) { if(id) throw invalid_argument("System framebuffer must have id 0"); - glGetIntegerv(GL_VIEWPORT, &view.left); - width = view.width; - height = view.height; + int view[4]; + glGetIntegerv(GL_VIEWPORT, view); + width = view[2]; + height = view[3]; } Framebuffer::Framebuffer(): width(0), height(0), + status(FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT), dirty(0) { static Require _req(EXT_framebuffer_object); @@ -92,24 +95,16 @@ Framebuffer::~Framebuffer() { if(id) glDeleteFramebuffers(1, &id); - if(current()==this) - unbind(); } -void Framebuffer::update_attachment(unsigned mask) const +void Framebuffer::update() const { - if(!ARB_direct_state_access && current()!=this) - { - dirty |= mask; - return; - } - vector color_bufs; color_bufs.reserve(attachments.size()); for(unsigned i=0; i(glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER)); + else + status = static_cast(glCheckFramebufferStatus(GL_FRAMEBUFFER)); + + dirty = 0; } 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) { @@ -199,8 +200,6 @@ void Framebuffer::check_size() width = max(static_cast(i->tex)->get_size()>>i->level, 1U); height = width; } - if(full_viewport) - reset_viewport(); break; } } @@ -221,7 +220,7 @@ void Framebuffer::set_texture_attachment(FramebufferAttachment attch, Texture &t unsigned i = get_attachment_index(attch); attachments[i].set(tex, level, layer); - update_attachment(1<(glCheckNamedFramebufferStatus(id, GL_FRAMEBUFFER)); - else - { - BindRestore _bind(this); - return static_cast(glCheckFramebufferStatus(GL_FRAMEBUFFER)); - } + if(id) + throw invalid_operation("Framebuffer::resize"); + + width = view.get_width(); + height = view.get_height(); } void Framebuffer::require_complete() const { - FramebufferStatus status = check_status(); if(status!=FRAMEBUFFER_COMPLETE) 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() -{ - clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT|STENCIL_BUFFER_BIT); -} - -void Framebuffer::clear(BufferBits bits) -{ - BindRestore _bind(this); - glClear(bits); -} - -void Framebuffer::blit_from(const Framebuffer &other, int sx0, int sy0, int sx1, int sy1, int dx0, int dy0, int dx1, int dy1, BufferBits bits, bool filter) -{ - static Require _req(EXT_framebuffer_blit); - - if(ARB_direct_state_access) - { - glBlitNamedFramebuffer(other.id, id, sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, bits, (filter ? GL_LINEAR : GL_NEAREST)); - return; - } - - const Framebuffer *old = current(); - if(set_current(this)) - { - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, id); - if(dirty) - { - update_attachment(dirty); - dirty = 0; - } - } - if(old!=&other) - glBindFramebuffer(GL_READ_FRAMEBUFFER, other.id); - - glBlitFramebuffer(sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, bits, (filter ? GL_LINEAR : GL_NEAREST)); - - set_current(old); - glBindFramebuffer(GL_FRAMEBUFFER, (old ? old->id : 0)); -} - -void Framebuffer::blit_from(const Framebuffer &other, int sx, int sy, unsigned wd, unsigned ht, int dx, int dy, BufferBits bits) -{ - blit_from(other, sx, sy, sx+wd, sy+ht, dx, dy, dx+wd, dy+ht, bits, false); -} - -void Framebuffer::blit_from(const Framebuffer &other, BufferBits bits, bool filter) -{ - blit_from(other, 0, 0, other.width, other.height, 0, 0, width, height, bits, filter); -} - -void Framebuffer::bind() const -{ - if(id && attachments.empty()) - throw invalid_operation("Framebuffer::bind"); - - if(set_current(this)) - { - glBindFramebuffer(GL_FRAMEBUFFER, id); - if(dirty) - { - update_attachment(dirty); - dirty = 0; - } - - if(width && height) - glViewport(view.left, view.bottom, view.width, view.height); - } -} - -const Framebuffer *Framebuffer::current() -{ - if(!cur_obj) - cur_obj = &system(); - return cur_obj; -} - -void Framebuffer::unbind() -{ - system().bind(); -} - void Framebuffer::set_debug_name(const string &name) { #ifdef DEBUG @@ -439,13 +338,5 @@ void Framebuffer::Attachment::clear() type = 0; } - -Framebuffer::Viewport::Viewport(): - left(0), - bottom(0), - width(0), - height(0) -{ } - } // namespace GL } // namespace Msp