]> git.tdb.fi Git - libs/gl.git/blobdiff - source/framebuffer.cpp
Drop Id tags and copyright notices from files
[libs/gl.git] / source / framebuffer.cpp
index 77ac21be6b0e6ef76da3928247b54b2c69074c5b..3ac742bd209fd0e89c05d723c082524b4799c02c 100644 (file)
@@ -1,11 +1,5 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2007  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include "extension.h"
+#include "ext_framebuffer_blit.h"
 #include "ext_framebuffer_object.h"
 #include "framebuffer.h"
 #include "misc.h"
@@ -53,7 +47,6 @@ void Framebuffer::update_attachment(unsigned mask) const
        if(current()==this)
        {
                GLenum color_buf = GL_NONE;
-               bool has_depth = false;
                for(unsigned i=0; i<attachments.size(); ++i)
                {
                        const Attachment &attch = attachments[i];
@@ -62,19 +55,19 @@ void Framebuffer::update_attachment(unsigned mask) const
                                if(attch.type==GL_RENDERBUFFER_EXT)
                                        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attch.attachment, GL_RENDERBUFFER_EXT, attch.rbuf->get_id());
                                else if(attch.type==GL_TEXTURE_2D)
+                               {
+                                       static_cast<Texture2D *>(attch.tex)->allocate(attch.level);
                                        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attch.attachment, attch.type, attch.tex->get_id(), attch.level);
+                               }
                                else
                                        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attch.attachment, 0, 0);
                        }
 
                        if(attch.attachment>=COLOR_ATTACHMENT0 && attch.attachment<=COLOR_ATTACHMENT3)
                                color_buf = attch.attachment;
-                       if(attch.attachment==DEPTH_ATTACHMENT)
-                               has_depth = true;
                }
 
                glDrawBuffer(color_buf);
-               glDepthMask(has_depth);
        }
        else
                dirty |= mask;
@@ -113,7 +106,7 @@ void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf)
        check_size();
 }
 
-void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, int level)
+void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned level)
 {
        if(!id)
                throw InvalidState("Can't attach to system framebuffer");
@@ -147,6 +140,39 @@ void Framebuffer::clear(BufferBits bits)
        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 RequireExtension _ext("GL_EXT_framebuffer_blit");
+
+       const Framebuffer *old = current();
+       if(set_current(this))
+       {
+               glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, id);
+               if(dirty)
+               {
+                       update_attachment(dirty);
+                       dirty = 0;
+               }
+       }
+       if(old!=&other)
+               glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, other.id);
+
+       glBlitFramebufferEXT(sx0, sy0, sx1, sy1, dx0, dy0, dx1, dy1, bits, (filter ? GL_LINEAR : GL_NEAREST));
+
+       set_current(old);
+       glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, (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(set_current(this))
@@ -203,7 +229,7 @@ void Framebuffer::Attachment::set(Renderbuffer &r)
        level = 0;
 }
 
-void Framebuffer::Attachment::set(Texture &t, int l)
+void Framebuffer::Attachment::set(Texture &t, unsigned l)
 {
        type = t.get_target();
        tex = &t;