]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturecube.cpp
Be less eager to optimize constant conditions in loops
[libs/gl.git] / source / texturecube.cpp
index b9a8f5dd02b8cacb73f63df7bce028a5920035cd..03e65167d73fee7a1d89ba9ea3cea7ef2c68d81d 100644 (file)
@@ -51,7 +51,7 @@ TextureCube::TextureCube():
        static Require _req(ARB_texture_cube_map);
 }
 
-void TextureCube::storage(PixelFormat fmt, unsigned sz)
+void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv)
 {
        if(size>0)
                throw invalid_operation("TextureCube::storage");
@@ -60,21 +60,25 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz)
 
        set_internal_format(fmt);
        size = sz;
+       levels = get_n_levels();
+       if(lv>0)
+               levels = min(levels, lv);
 }
 
 void TextureCube::allocate(unsigned level)
 {
        if(size==0)
                throw invalid_operation("TextureCube::allocate");
+       if(level>=levels)
+               throw invalid_argument("TextureCube::allocate");
        if(allocated&(1<<level))
                return;
 
        if(ARB_texture_storage)
        {
                BindRestore _bind(this);
-               unsigned n_levels = (is_mipmapped(min_filter) ? get_n_levels() : 1);
-               glTexStorage2D(target, n_levels, ifmt, size, size);
-               allocated |= (1<<n_levels)-1;
+               glTexStorage2D(target, levels, ifmt, size, size);
+               allocated |= (1<<levels)-1;
        }
        else
        {
@@ -156,7 +160,10 @@ void TextureCube::image(const Graphics::Image &img, bool srgb)
 
        PixelFormat fmt = pixelformat_from_graphics(img.get_format());
        if(size==0)
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w);
+       {
+               unsigned l = (is_mipmapped(min_filter) ? mipmap_levels ? mipmap_levels : 0 : 1);
+               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l);
+       }
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");