]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/framebuffer.cpp
Use C++11 features with containers
[libs/gl.git] / source / core / framebuffer.cpp
index 05cd27f0395947fab9465c313b25db1a7ff09bd1..0ce00becd23d5503ca5f26fec5f13eab065f9f17 100644 (file)
@@ -200,36 +200,49 @@ void Framebuffer::update() const
 
 void Framebuffer::check_size()
 {
-       for(vector<Attachment>::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();
+                       GLenum type = a.tex->get_target();
+                       unsigned w = 0;
+                       unsigned h = 0;
                        if(type==GL_TEXTURE_2D)
                        {
-                               Texture2D *tex = static_cast<Texture2D *>(i->tex);
-                               width = max(tex->get_width()>>i->level, 1U);
-                               height = max(tex->get_height()>>i->level, 1U);
+                               Texture2D *tex = static_cast<Texture2D *>(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)
                        {
-                               Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(i->tex);
-                               width = tex->get_width();
-                               height = tex->get_height();
+                               Texture2DMultisample *tex = static_cast<Texture2DMultisample *>(a.tex);
+                               w = tex->get_width();
+                               h = tex->get_height();
                        }
                        else if(type==GL_TEXTURE_3D || type==GL_TEXTURE_2D_ARRAY)
                        {
-                               Texture3D *tex = static_cast<Texture3D *>(i->tex);
-                               width = max(tex->get_width()>>i->level, 1U);
-                               height = max(tex->get_height()>>i->level, 1U);
+                               Texture3D *tex = static_cast<Texture3D *>(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)
                        {
-                               width = max(static_cast<TextureCube *>(i->tex)->get_size()>>i->level, 1U);
-                               height = width;
+                               w = max(static_cast<TextureCube *>(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)