X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fframebuffer.cpp;h=8806ea6c4956d980dafd2b72419050e78813c2d8;hb=70153a4e27eeebc7e0a91de122f45eff6296cb71;hp=77ac21be6b0e6ef76da3928247b54b2c69074c5b;hpb=c4cacaf8f9225e006e6bb35f81eb6c2f78602bdc;p=libs%2Fgl.git diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 77ac21be..8806ea6c 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -1,11 +1,6 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include "error.h" #include "extension.h" +#include "ext_framebuffer_blit.h" #include "ext_framebuffer_object.h" #include "framebuffer.h" #include "misc.h" @@ -22,7 +17,7 @@ Framebuffer::Framebuffer(unsigned i): dirty(0) { if(id) - throw InvalidParameterValue("System framebuffer must have id 0"); + throw invalid_argument("System framebuffer must have id 0"); int viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); @@ -53,7 +48,6 @@ void Framebuffer::update_attachment(unsigned mask) const if(current()==this) { GLenum color_buf = GL_NONE; - bool has_depth = false; for(unsigned i=0; iget_id()); else if(attch.type==GL_TEXTURE_2D) + { + static_cast(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(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); } 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; @@ -96,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(i->tex)->get_size(); + height = width; + } if(current()==this) glViewport(0, 0, width, height); break; @@ -105,7 +109,7 @@ void Framebuffer::check_size() void Framebuffer::attach(FramebufferAttachment attch, Renderbuffer &rbuf) { if(!id) - throw InvalidState("Can't attach to system framebuffer"); + throw invalid_operation("Framebuffer::attach"); unsigned i = get_attachment_index(attch); attachments[i].set(rbuf); @@ -113,13 +117,24 @@ 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 invalid_operation("Framebuffer::attach"); + + unsigned i = get_attachment_index(attch); + attachments[i].set(tex, 0, level); + update_attachment(1<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,10 +251,11 @@ void Framebuffer::Attachment::set(Renderbuffer &r) level = 0; } -void Framebuffer::Attachment::set(Texture &t, int l) +void Framebuffer::Attachment::set(Texture &t, GLenum f, unsigned l) { type = t.get_target(); tex = &t; + cube_face = f; level = l; }