]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texturecube.cpp
Simplify applying texture swizzling
[libs/gl.git] / source / texturecube.cpp
index 14ddf43d41c2cdc076e4489a62e2ed2e7341dd36..8d194c42028bb6a4c6eb56cf2e9c0cb9567eba71 100644 (file)
@@ -78,6 +78,7 @@ void TextureCube::allocate(unsigned level)
        {
                BindRestore _bind(this);
                glTexStorage2D(target, levels, ifmt, size, size);
+               apply_swizzle();
                allocated |= (1<<levels)-1;
        }
        else
@@ -104,7 +105,10 @@ void TextureCube::image(TextureCubeFace face, unsigned level, PixelFormat fmt, D
        BindRestore _bind(this);
 
        if(!allocated)
+       {
                glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+               apply_swizzle();
+       }
        glTexImage2D(face, level, ifmt, s, s, 0, get_upload_format(fmt), type, data);
 
        if(level==0)
@@ -176,10 +180,7 @@ void TextureCube::image(const Graphics::Image &img, unsigned lv, bool srgb)
 
        PixelFormat fmt = pixelformat_from_graphics(img.get_format());
        if(size==0)
-       {
-               unsigned l = (is_mipmapped(min_filter) ? lv : 1);
-               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, l);
-       }
+               storage(storage_pixelformat_from_graphics(img.get_format(), srgb), w, lv);
        else if(w!=size || h!=size)
                throw incompatible_data("TextureCube::image");
 
@@ -274,6 +275,7 @@ void TextureCube::Loader::init()
        add("image_data", &Loader::image_data);
        add("raw_data", &Loader::raw_data);
        add("storage", &Loader::storage);
+       add("storage", &Loader::storage_levels);
 }
 
 void TextureCube::Loader::external_image(TextureCubeFace face, const string &fn)
@@ -304,6 +306,11 @@ void TextureCube::Loader::storage(PixelFormat fmt, unsigned s)
        obj.storage(fmt, s);
 }
 
+void TextureCube::Loader::storage_levels(PixelFormat fmt, unsigned s, unsigned l)
+{
+       obj.storage(fmt, s, l);
+}
+
 
 void operator>>(const LexicalConverter &conv, TextureCubeFace &face)
 {