]> git.tdb.fi Git - libs/gl.git/blobdiff - source/texture.cpp
Bind textures in the modern way when shaders are used
[libs/gl.git] / source / texture.cpp
index f095fe98aadcb99500ecad562275027453d14dcf..1b7bdc2297ec3a1be84d95fdcd091b55b59bae20 100644 (file)
@@ -301,7 +301,7 @@ void Texture::load_image(const string &fn, bool srgb)
        image(img, srgb);
 }
 
        image(img, srgb);
 }
 
-void Texture::bind_to(unsigned i) const
+void Texture::bind_to(unsigned i, bool legacy) const
 {
        if(!id)
        {
 {
        if(!id)
        {
@@ -316,21 +316,22 @@ void Texture::bind_to(unsigned i) const
 
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *old = unit.get_texture();
 
        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(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())
                        {
                        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);
                                        glDisable(old->target);
-                               if((!old || old->target!=target))
+                               if((!old || old->target!=target) && legacy)
                                        glEnable(target);
                        }
                        glBindTexture(target, id);
                                        glEnable(target);
                        }
                        glBindTexture(target, id);
@@ -353,15 +354,16 @@ void Texture::unbind_from(unsigned i)
 {
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *cur = unit.get_texture();
 {
        TexUnit &unit = TexUnit::get_unit(i);
        const Texture *cur = unit.get_texture();
+       bool legacy = unit.get_texture_legacy();
        if(unit.set_texture(0))
        {
        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);
                        glBindTextureUnit(i, 0);
                else
                {
                        unit.bind();
                        glBindTexture(cur->target, 0);
-                       if(unit.supports_legacy())
+                       if(unit.supports_legacy() && legacy)
                                glDisable(cur->target);
                }
        }
                                glDisable(cur->target);
                }
        }