X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fframebuffer.cpp;h=97b5c8b1394e428bcc640339af98d58a68607462;hb=2e09b4f72f06537431151fe8b2574e1aa886ad48;hp=05cd27f0395947fab9465c313b25db1a7ff09bd1;hpb=6353307898cd397e2bcde13e2448a8a678a60004;p=libs%2Fgl.git diff --git a/source/core/framebuffer.cpp b/source/core/framebuffer.cpp index 05cd27f0..97b5c8b1 100644 --- a/source/core/framebuffer.cpp +++ b/source/core/framebuffer.cpp @@ -131,32 +131,31 @@ void Framebuffer::update() const vector color_bufs; color_bufs.reserve(format.size()); unsigned i = 0; - for(const UInt16 *j=format.begin(); j!=format.end(); ++j, ++i) + for(FrameAttachment a: format) { - GLenum gl_attach_point = get_gl_attachment(static_cast(*j)); + GLenum gl_attach_point = get_gl_attachment(a); if(dirty&(1<get_target(); if(ARB_direct_state_access) { - if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE || attch.layer<0) - glNamedFramebufferTexture(id, gl_attach_point, attch.tex->get_id(), attch.level); + if(attch.tex->target==GL_TEXTURE_2D || attch.tex->target==GL_TEXTURE_2D_MULTISAMPLE || attch.layer<0) + glNamedFramebufferTexture(id, gl_attach_point, attch.tex->id, attch.level); else - glNamedFramebufferTextureLayer(id, gl_attach_point, attch.tex->get_id(), attch.level, attch.layer); + glNamedFramebufferTextureLayer(id, gl_attach_point, attch.tex->id, attch.level, attch.layer); } - else if(type==GL_TEXTURE_2D || type==GL_TEXTURE_2D_MULTISAMPLE) - glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, type, attch.tex->get_id(), attch.level); + else if(attch.tex->target==GL_TEXTURE_2D || attch.tex->target==GL_TEXTURE_2D_MULTISAMPLE) + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, attch.tex->target, attch.tex->id, attch.level); else if(attch.layer<0) - glFramebufferTexture(GL_FRAMEBUFFER, gl_attach_point, attch.tex->get_id(), attch.level); - else if(type==GL_TEXTURE_2D_ARRAY) - glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attach_point, attch.tex->get_id(), attch.level, attch.layer); - else if(type==GL_TEXTURE_3D) - glFramebufferTexture3D(GL_FRAMEBUFFER, gl_attach_point, type, attch.tex->get_id(), attch.level, attch.layer); - else if(type==GL_TEXTURE_CUBE_MAP) - glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, TextureCube::enumerate_faces(attch.layer), attch.tex->get_id(), attch.level); + glFramebufferTexture(GL_FRAMEBUFFER, gl_attach_point, attch.tex->id, attch.level); + else if(attch.tex->target==GL_TEXTURE_2D_ARRAY) + glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attach_point, attch.tex->id, attch.level, attch.layer); + else if(attch.tex->target==GL_TEXTURE_3D) + glFramebufferTexture3D(GL_FRAMEBUFFER, gl_attach_point, attch.tex->target, attch.tex->id, attch.level, attch.layer); + else if(attch.tex->target==GL_TEXTURE_CUBE_MAP) + glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attach_point, get_gl_cube_face(static_cast(attch.layer)), attch.tex->id, attch.level); } else if(ARB_direct_state_access) glNamedFramebufferTexture(id, gl_attach_point, 0, 0); @@ -166,6 +165,8 @@ void Framebuffer::update() const if(gl_attach_point!=GL_DEPTH_ATTACHMENT && gl_attach_point!=GL_STENCIL_ATTACHMENT) color_bufs.push_back(gl_attach_point); + + ++i; } if(color_bufs.size()>1) @@ -200,36 +201,48 @@ void Framebuffer::update() const void Framebuffer::check_size() { - for(vector::iterator i=attachments.begin(); i!=attachments.end(); ++i) - if(i->tex) + bool first = true; + for(Attachment &a: attachments) + if(a.tex) { - GLenum type = i->tex->get_target(); - if(type==GL_TEXTURE_2D) + unsigned w = 0; + unsigned h = 0; + if(a.tex->target==GL_TEXTURE_2D) { - Texture2D *tex = static_cast(i->tex); - width = max(tex->get_width()>>i->level, 1U); - height = max(tex->get_height()>>i->level, 1U); + Texture2D *tex = static_cast(a.tex); + w = max(tex->get_width()>>a.level, 1U); + h = max(tex->get_height()>>a.level, 1U); } - else if(type==GL_TEXTURE_2D_MULTISAMPLE) + else if(a.tex->target==GL_TEXTURE_2D_MULTISAMPLE) { - Texture2DMultisample *tex = static_cast(i->tex); - width = tex->get_width(); - height = tex->get_height(); + Texture2DMultisample *tex = static_cast(a.tex); + w = tex->get_width(); + h = tex->get_height(); } - else if(type==GL_TEXTURE_3D || type==GL_TEXTURE_2D_ARRAY) + else if(a.tex->target==GL_TEXTURE_3D || a.tex->target==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); + Texture3D *tex = static_cast(a.tex); + w = max(tex->get_width()>>a.level, 1U); + h = max(tex->get_height()>>a.level, 1U); } - else if(type==GL_TEXTURE_CUBE_MAP) + else if(a.tex->target==GL_TEXTURE_CUBE_MAP) { - width = max(static_cast(i->tex)->get_size()>>i->level, 1U); - height = width; + w = max(static_cast(a.tex)->get_size()>>a.level, 1U); + h = w; } - break; - } + if(first) + { + width = w; + height = h; + first = false; + } + else + { + width = min(width, w); + height = min(height, h); + } + } } void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned level, int layer, unsigned samples) @@ -241,21 +254,23 @@ void Framebuffer::set_attachment(FrameAttachment attch, Texture &tex, unsigned l throw incompatible_data("Framebuffer::attach"); unsigned i = 0; - for(const UInt16 *j=format.begin(); j!=format.end(); ++j, ++i) - if(*j==attch) + for(FrameAttachment a: format) + { + if(a==attch) { attachments[i].set(tex, level, layer); dirty |= 1<