X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture.cpp;h=820dd10fd90318c64278ae9b0aed66cf227d8743;hp=fb409e895c7fc3a0d221ee829648024462d76a55;hb=7af837734a28a14b3e24a421187d12ecd16572d0;hpb=4cb33c263a00787a57531dfc41a4128bf34d7bee diff --git a/source/texture.cpp b/source/texture.cpp index fb409e89..820dd10f 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -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,22 +314,30 @@ 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); - 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,15 +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)) { - 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); + } } } +bool Texture::is_legacy_target(GLenum target) +{ + return target(t, 0)