]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/texturecube.cpp
Store the number of mipmap levels in the Texture base class
[libs/gl.git] / source / core / texturecube.cpp
index 2f36f33624cee007b2667daeb993caaf212e9a04..bfa63873b2e188f2f339940fc48bf09e4c38034e 100644 (file)
@@ -33,7 +33,7 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv)
 {
        if(size>0)
        {
-               if(fmt!=format || sz!=size || (lv && lv!=levels))
+               if(fmt!=format || sz!=size || (lv && lv!=n_levels))
                        throw incompatible_data("TextureCube::storage");
                return;
        }
@@ -42,9 +42,9 @@ void TextureCube::storage(PixelFormat fmt, unsigned sz, unsigned lv)
 
        set_format(fmt);
        size = sz;
-       levels = get_n_levels();
+       n_levels = count_levels(size);
        if(lv>0)
-               levels = min(levels, lv);
+               n_levels = min(n_levels, lv);
 
        allocate();
 }
@@ -67,7 +67,7 @@ void TextureCube::sub_image(TextureCubeFace face, unsigned level, unsigned x, un
 {
        if(size==0)
                throw invalid_operation("TextureCube::sub_image");
-       if(level>=levels || x>size || x+wd>size || y>size || y+ht>size)
+       if(level>=n_levels || x>size || x+wd>size || y>size || y+ht>size)
                throw out_of_range("TextureCube::sub_image");
 
        TextureCubeBackend::sub_image(face, level, x, y, wd, ht, data);
@@ -101,13 +101,6 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv)
        image(0, img.get_pixels());
 }
 
-unsigned TextureCube::get_n_levels() const
-{
-       unsigned n = 0;
-       for(unsigned s=size; s; s>>=1, ++n) ;
-       return n;
-}
-
 unsigned TextureCube::get_level_size(unsigned level) const
 {
        return size>>level;