]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture2d.cpp
Clear Texture2D's allocation flags when unloading
[libs/gl.git] / source / texture2d.cpp
index 45c2e665d056973ee4ecdb41eb6033dd831c2b5b..47e0c7434d0ef56c7fbf892b0ee45a31f4552710 100644 (file)
@@ -104,9 +104,9 @@ void Texture2D::image(unsigned level, PixelFormat fmt, DataType type, const void
        glTexImage2D(target, level, ifmt, w, h, 0, get_upload_format(fmt), type, data);
 
        allocated |= 1<<level;
-       if(gen_mipmap && level==0)
+       if(auto_gen_mipmap && level==0)
        {
-               auto_generate_mipmap();
+               generate_mipmap();
                allocated |= (1<<get_n_levels())-1;
        }
 }
@@ -125,8 +125,8 @@ void Texture2D::sub_image(unsigned level, int x, int y, unsigned wd, unsigned ht
        else
                glTexSubImage2D(target, level, x, y, wd, ht, fmt, type, data);
 
-       if(gen_mipmap && level==0)
-               auto_generate_mipmap();
+       if(auto_gen_mipmap && level==0)
+               generate_mipmap();
 }
 
 void Texture2D::image(const Graphics::Image &img, bool srgb)
@@ -188,6 +188,7 @@ void Texture2D::unload()
 {
        glDeleteTextures(1, &id);
        id = 0;
+       allocated = 0;
        // TODO check which params actually need refreshing
        dirty_params = -1;
 }
@@ -218,8 +219,6 @@ void Texture2D::Loader::raw_data(const string &data)
 
 void Texture2D::Loader::storage(PixelFormat fmt, unsigned w, unsigned h)
 {
-       if(srgb)
-               fmt = get_srgb_pixelformat(fmt);
        obj.storage(fmt, w, h);
 }
 
@@ -254,8 +253,8 @@ bool Texture2D::AsyncLoader::process()
        }
        else if(phase==1)
        {
-               pixel_buffer.data(n_bytes, 0);
-               mapped_address = reinterpret_cast<char *>(pixel_buffer.map(WRITE_ONLY));
+               pixel_buffer.storage(n_bytes);
+               mapped_address = reinterpret_cast<char *>(pixel_buffer.map());
        }
        else if(phase==2)
        {
@@ -272,7 +271,12 @@ bool Texture2D::AsyncLoader::process()
                }
 
                if(!texture.id)
-                       glGenTextures(1, &texture.id);
+               {
+                       if(ARB_direct_state_access)
+                               glCreateTextures(texture.target, 1, &texture.id);
+                       else
+                               glGenTextures(1, &texture.id);
+               }
                texture.image(image, srgb_conversion, true);
        }