]> git.tdb.fi Git - libs/gl.git/commitdiff
Better handling of unloaded textures
authorMikko Rasa <tdb@tdb.fi>
Mon, 29 Sep 2014 21:07:20 +0000 (00:07 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 29 Sep 2014 21:07:20 +0000 (00:07 +0300)
Since it's no longer guaranteed that calling ResourceManager::resource_used
will result in Resource::load being called, it's better to avoid the
binding logic entirely in the unloaded case.  In particular, parameters
must not be updated until the GL texture object has been created.

Generating an ID for the texture has been delayed to the last phase of
loading to further differentiate the loaded and unloaded states.

source/texture.cpp
source/texture2d.cpp

index 0fa65eadaed0f7b31508c6e9e4fa55a2d6ba4cfe..cf08ac6371ceeacad9f362a49b3970d887e3398f 100644 (file)
@@ -181,6 +181,17 @@ void Texture::set_compare_func(Predicate f)
 
 void Texture::bind_to(unsigned i) const
 {
+       if(!id)
+       {
+               if(manager)
+                       manager->resource_used(*this);
+               if(!id)
+               {
+                       unbind_from(i);
+                       return;
+               }
+       }
+
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *cur = unit.get_texture();
        if(unit.set_texture(this))
index e237e504176ace2bfd56ddf74597907aee397abb..2ea713eb3a539c9705e13f90b2775ff9b643fdfd 100644 (file)
@@ -207,10 +207,7 @@ Texture2D::AsyncLoader::AsyncLoader(Texture2D &t, IO::Seekable &i):
        pixel_buffer(PIXEL_UNPACK_BUFFER),
        mapped_address(0),
        phase(0)
-{
-       if(!texture.id)
-               glGenTextures(1, &texture.id);
-}
+{ }
 
 bool Texture2D::AsyncLoader::needs_sync() const
 {
@@ -245,6 +242,8 @@ bool Texture2D::AsyncLoader::process()
                        return false;
                }
 
+               if(!texture.id)
+                       glGenTextures(1, &texture.id);
                texture.image(image, false, true);
        }