X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftexture.cpp;h=820dd10fd90318c64278ae9b0aed66cf227d8743;hp=1d2ece8074410ded753c621f4c4dd43418e2694d;hb=3c46227c280bc4cd8a4487c648f2f080d5b4f7ea;hpb=ed2d1c8c5ac065751a7887b178b4499007c1ffe4 diff --git a/source/texture.cpp b/source/texture.cpp index 1d2ece80..820dd10f 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -63,6 +63,7 @@ Texture::Texture(GLenum t, ResourceManager *m): ifmt(RGB), min_filter(NEAREST_MIPMAP_LINEAR), mag_filter(LINEAR), + max_anisotropy(1.0f), wrap_s(REPEAT), wrap_t(REPEAT), wrap_r(REPEAT), @@ -220,7 +221,8 @@ void Texture::set_max_anisotropy(float a) else if(a>1.0f) static Require _req(EXT_texture_filter_anisotropic); max_anisotropy = a; - update_parameter(MAX_ANISOTROPY); + if(EXT_texture_filter_anisotropic) + update_parameter(MAX_ANISOTROPY); } void Texture::set_wrap(TextureWrap w) @@ -299,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) { @@ -312,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) { @@ -346,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)