]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Throw an exception if Texture*::allocate is called before storage
[libs/gl.git] / source / texture.cpp
index f095fe98aadcb99500ecad562275027453d14dcf..820dd10fd90318c64278ae9b0aed66cf227d8743 100644 (file)
@@ -301,7 +301,7 @@ void Texture::load_image(const string &fn, bool srgb)
        image(img, srgb);
 }
 
-void Texture::bind_to(unsigned i) const
+void Texture::bind_to(unsigned i, bool legacy) const
 {
        if(!id)
        {
@@ -314,23 +314,26 @@ void Texture::bind_to(unsigned i) const
                }
        }
 
+       legacy = (legacy && is_legacy_target(target));
+
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *old = unit.get_texture();
-       if(unit.set_texture(this))
+       bool old_legacy = unit.get_texture_legacy();
+       if(unit.set_texture(this, legacy))
        {
                if(manager)
                        manager->resource_used(*this);
 
-               if(ARB_direct_state_access && !unit.supports_legacy())
+               if(ARB_direct_state_access && !old_legacy && (!unit.supports_legacy() || !legacy))
                        glBindTextureUnit(i, id);
                else
                {
                        unit.bind();
                        if(unit.supports_legacy())
                        {
-                               if(old && old->target!=target)
+                               if(old && old->target!=target && old_legacy)
                                        glDisable(old->target);
-                               if((!old || old->target!=target))
+                               if((!old || old->target!=target) && legacy)
                                        glEnable(target);
                        }
                        glBindTexture(target, id);
@@ -353,20 +356,26 @@ void Texture::unbind_from(unsigned i)
 {
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *cur = unit.get_texture();
+       bool legacy = unit.get_texture_legacy();
        if(unit.set_texture(0))
        {
-               if(ARB_direct_state_access && !unit.supports_legacy())
+               if(ARB_direct_state_access && !legacy)
                        glBindTextureUnit(i, 0);
                else
                {
                        unit.bind();
                        glBindTexture(cur->target, 0);
-                       if(unit.supports_legacy())
+                       if(unit.supports_legacy() && legacy)
                                glDisable(cur->target);
                }
        }
 }
 
+bool Texture::is_legacy_target(GLenum target)
+{
+       return target<GL_TEXTURE_1D_ARRAY;
+}
+
 
 Texture::Loader::Loader(Texture &t):
        DataFile::CollectionObjectLoader<Texture>(t, 0)