]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Rearrange texture bind calls to keep them closer to where they're needed
[libs/gl.git] / source / texture2d.cpp
index 4aad82d27ad9eeb71678e1b9b1d23386751c6ece..23cb9477e122c69ddabdbf614dfafca05ed71801 100644 (file)
@@ -89,11 +89,11 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        unsigned h = height;
        get_level_size(level, w, h);
 
-       BindRestore _bind(this);
        if(ARB_texture_storage)
-               sub_image(level, 0, 0, w, h, fmt, type, data);
-       else
-               glTexImage2D(target, level, ifmt, w, h, 0, fmt, type, data);
+               return sub_image(level, 0, 0, w, h, fmt, type, data);
+
+       BindRestore _bind(this);
+       glTexImage2D(target, level, ifmt, w, h, 0, fmt, type, data);
 
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
@@ -108,10 +108,13 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        if(width==0 || height==0)
                throw invalid_operation("Texture2D::sub_image");
 
+       BindRestore _bind(this);
        allocate(level);
 
-       BindRestore _bind(this);
        glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
+
+       if(gen_mipmap && level==0)
+               auto_generate_mipmap();
 }
 
 void Texture2D::image(const Graphics::Image &img, bool srgb)