]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture3d.cpp
Rearrange texture bind calls to keep them closer to where they're needed
[libs/gl.git] / source / texture3d.cpp
index d04a17e1fbb38bf81c507f9798406f75ca3b2942..36afa9bcdfe9b3fc2dc1e72c5ef8d19bce06f8aa 100644 (file)
@@ -78,11 +78,11 @@ void Texture3D::image(unsigned level, PixelFormat fmt, DataType type, const void
        unsigned d = depth;
        get_level_size(level, w, h, d);
 
-       BindRestore _bind(this);
        if(ARB_texture_storage)
-               sub_image(level, 0, 0, 0, w, h, d, fmt, type, data);
-       else
-               glTexImage3D(target, level, ifmt, width, height, depth, 0, fmt, type, data);
+               return sub_image(level, 0, 0, 0, w, h, d, fmt, type, data);
+
+       BindRestore _bind(this);
+       glTexImage3D(target, level, ifmt, width, height, depth, 0, fmt, type, data);
 
        allocated |= 1<<level;
        if(gen_mipmap && level==0)
@@ -97,10 +97,13 @@ void Texture3D::sub_image(unsigned level, int x, int y, int z, unsigned wd, unsi
        if(width==0 || height==0 || depth==0)
                throw invalid_operation("Texture3D::image");
 
+       BindRestore _bind(this);
        allocate(level);
 
-       BindRestore _bind(this);
        glTexSubImage3D(target, level, x, y, z, wd, ht, dp, fmt, type, data);
+
+       if(gen_mipmap && level==0)
+               auto_generate_mipmap();
 }
 
 void Texture3D::load_image(const string &fn, int dp)