]> git.tdb.fi Git - libs/gl.git/blobdiff - source/framebuffer.cpp
Add support for cube map textures
[libs/gl.git] / source / framebuffer.cpp
index 6877f4808b7402c7f1660097c3860bb7fcbbe5bc..8806ea6c4956d980dafd2b72419050e78813c2d8 100644 (file)
@@ -60,6 +60,11 @@ void Framebuffer::update_attachment(unsigned mask) const
                                        static_cast<Texture2D *>(attch.tex)->allocate(attch.level);
                                        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attch.attachment, attch.type, attch.tex->get_id(), attch.level);
                                }
+                               else if(attch.type==GL_TEXTURE_CUBE_MAP)
+                               {
+                                       static_cast<TextureCube *>(attch.tex)->allocate(attch.level);
+                                       glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attch.attachment, attch.cube_face, attch.tex->get_id(), attch.level);
+                               }
                                else
                                        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, attch.attachment, 0, 0);
                        }
@@ -90,6 +95,11 @@ void Framebuffer::check_size()
                                width = tex->get_width();
                                height = tex->get_height();
                        }
+                       else if(i->type==GL_TEXTURE_CUBE_MAP)
+                       {
+                               width = static_cast<TextureCube *>(i->tex)->get_size();
+                               height = width;
+                       }
                        if(current()==this)
                                glViewport(0, 0, width, height);
                        break;
@@ -113,7 +123,18 @@ void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned l
                throw invalid_operation("Framebuffer::attach");
 
        unsigned i = get_attachment_index(attch);
-       attachments[i].set(tex, level);
+       attachments[i].set(tex, 0, level);
+       update_attachment(1<<i);
+       check_size();
+}
+
+void Framebuffer::attach(FramebufferAttachment attch, TextureCube &tex, TextureCubeFace face, unsigned level)
+{
+       if(!id)
+               throw invalid_operation("Framebuffer::attach");
+
+       unsigned i = get_attachment_index(attch);
+       attachments[i].set(tex, face, level);
        update_attachment(1<<i);
        check_size();
 }
@@ -230,10 +251,11 @@ void Framebuffer::Attachment::set(Renderbuffer &r)
        level = 0;
 }
 
-void Framebuffer::Attachment::set(Texture &t, unsigned l)
+void Framebuffer::Attachment::set(Texture &t, GLenum f, unsigned l)
 {
        type = t.get_target();
        tex = &t;
+       cube_face = f;
        level = l;
 }