X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fframebuffer.cpp;h=cf478ce29b686d842ce2074078952633b2e47b02;hp=638a710f464431cd7a708434e1fa980157d9b009;hb=9d1fa012a23693768bbe287371e97751c03acc50;hpb=08e19bc2b4eba572bc7699378cf55cd8772ac67e diff --git a/source/framebuffer.cpp b/source/framebuffer.cpp index 638a710f..cf478ce2 100644 --- a/source/framebuffer.cpp +++ b/source/framebuffer.cpp @@ -2,12 +2,15 @@ #include #include #include -#include +#include +#include +#include #include "error.h" #include "framebuffer.h" #include "misc.h" #include "renderbuffer.h" #include "texture2d.h" +#include "texture3d.h" using namespace std; @@ -36,6 +39,15 @@ void operator<<(LexicalConverter &conv, FramebufferStatus status) case FRAMEBUFFER_INCOMPLETE_READ_BUFFER: conv.result("missing read buffer attachment"); break; + case FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + conv.result("mismatched attachment sample counts"); + break; + case FRAMEBUFFER_INCOMPLETE_LAYER_COUNT: + conv.result("mismatched attachment layer counts"); + break; + case FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS: + conv.result("mismatched attachment layering"); + break; case FRAMEBUFFER_UNSUPPORTED: conv.result("unsupported"); break; @@ -113,6 +125,16 @@ void Framebuffer::update_attachment(unsigned mask) const else glFramebufferTexture2D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level); } + else if(attch.type==GL_TEXTURE_3D || attch.type==GL_TEXTURE_2D_ARRAY) + { + static_cast(attch.tex)->allocate(attch.level); + if(ARB_direct_state_access) + glNamedFramebufferTextureLayer(id, attch.attachment, attch.tex->get_id(), attch.level, attch.layer); + else if(attch.type==GL_TEXTURE_2D_ARRAY) + glFramebufferTextureLayer(GL_FRAMEBUFFER, attch.attachment, attch.tex->get_id(), attch.level, attch.layer); + else + glFramebufferTexture3D(GL_FRAMEBUFFER, attch.attachment, attch.type, attch.tex->get_id(), attch.level, attch.layer); + } else if(attch.type==GL_TEXTURE_CUBE_MAP) { static_cast(attch.tex)->allocate(attch.level); @@ -146,10 +168,10 @@ void Framebuffer::update_attachment(unsigned mask) const { if(ARB_draw_buffers) glDrawBuffers(color_bufs.size(), &color_bufs[0]); - else if(MSP_draw_buffer) + else if(MSP_buffer_control) glDrawBuffer(first_buffer); - if(MSP_draw_buffer) + if(MSP_buffer_control) glReadBuffer(first_buffer); } } @@ -168,12 +190,18 @@ void Framebuffer::check_size() else if(i->type==GL_TEXTURE_2D) { Texture2D *tex = static_cast(i->tex); - width = tex->get_width(); - height = tex->get_height(); + width = max(tex->get_width()>>i->level, 1U); + height = max(tex->get_height()>>i->level, 1U); + } + else if(i->type==GL_TEXTURE_3D || i->type==GL_TEXTURE_2D_ARRAY) + { + Texture3D *tex = static_cast(i->tex); + width = max(tex->get_width()>>i->level, 1U); + height = max(tex->get_height()>>i->level, 1U); } else if(i->type==GL_TEXTURE_CUBE_MAP) { - width = static_cast(i->tex)->get_size(); + width = max(static_cast(i->tex)->get_size()>>i->level, 1U); height = width; } if(full_viewport) @@ -213,6 +241,17 @@ void Framebuffer::attach(FramebufferAttachment attch, Texture2D &tex, unsigned l check_size(); } +void Framebuffer::attach(FramebufferAttachment attch, Texture3D &tex, unsigned layer, unsigned level) +{ + if(!id) + throw invalid_operation("Framebuffer::attach"); + + unsigned i = get_attachment_index(attch); + attachments[i].set(tex, level, layer); + update_attachment(1<