]> 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 fb409e895c7fc3a0d221ee829648024462d76a55..1b7bdc2297ec3a1be84d95fdcd091b55b59bae20 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)
        {
@@ -316,20 +316,26 @@ void Texture::bind_to(unsigned i) const
 
        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);
 
-               unit.bind();
-               if(unit.supports_legacy())
+               if(ARB_direct_state_access && !old_legacy && (!unit.supports_legacy() || !legacy))
+                       glBindTextureUnit(i, id);
+               else
                {
-                       if(old && old->target!=target)
-                               glDisable(old->target);
-                       if(!old || old->target!=target)
-                               glEnable(target);
+                       unit.bind();
+                       if(unit.supports_legacy())
+                       {
+                               if(old && old->target!=target && old_legacy)
+                                       glDisable(old->target);
+                               if((!old || old->target!=target) && legacy)
+                                       glEnable(target);
+                       }
+                       glBindTexture(target, id);
                }
-               glBindTexture(target, id);
 
                if(dirty_params)
                {
@@ -348,12 +354,18 @@ 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))
        {
-               unit.bind();
-               glBindTexture(cur->target, 0);
-               if(unit.supports_legacy())
-                       glDisable(cur->target);
+               if(ARB_direct_state_access && !legacy)
+                       glBindTextureUnit(i, 0);
+               else
+               {
+                       unit.bind();
+                       glBindTexture(cur->target, 0);
+                       if(unit.supports_legacy() && legacy)
+                               glDisable(cur->target);
+               }
        }
 }