]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturecube.cpp
Make explicit mipmap generation public
[libs/gl.git] / source / texturecube.cpp
index db679cf9e1259cb4feb0e087c0f3e066c40921c3..cd18c10d6909a2c459c4b2409789069900a67b88 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,19 +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
        {
@@ -100,10 +106,10 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
 
        // XXX Allocation should be tracked per-face, but we'll run out of bits
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap==1 && level==0)
        {
                // TODO Only do this once all faces are created
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -118,8 +124,8 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, int x, int y,
 
        glTexSubImage2D(face, level, x, y, wd, ht, get_upload_format(fmt), type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap==1 && level==0)
+               generate_mipmap();
 }
 
 void TextureCube::image(TextureCubeFace face, const Graphics::Image &img, bool srgb)
@@ -154,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");
 
@@ -276,8 +285,6 @@ void TextureCube::Loader::raw_data(TextureCubeFace face, const string &data)
 
 void TextureCube::Loader::storage(PixelFormat fmt, unsigned s)
 {
-       if(srgb)
-               fmt = get_srgb_pixelformat(fmt);
        obj.storage(fmt, s);
 }