From: Mikko Rasa Date: Sun, 19 Oct 2014 14:25:56 +0000 (+0300) Subject: Don't enable/disable textures on non-legacy units X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e1672476c5a258ff67fe1fcb47dd9a40b89169cb;p=libs%2Fgl.git Don't enable/disable textures on non-legacy units --- diff --git a/source/texture.cpp b/source/texture.cpp index 187c2533..81373c97 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -199,17 +199,20 @@ void Texture::bind_to(unsigned i) const } TexUnit &unit = TexUnit::get_unit(i); - const Texture *cur = unit.get_texture(); + const Texture *old = unit.get_texture(); if(unit.set_texture(this)) { if(manager) manager->resource_used(*this); unit.bind(); - if(cur && cur->target!=target) - glDisable(cur->target); - if(!cur || cur->target!=target) - glEnable(target); + if(unit.supports_legacy()) + { + if(old && old->target!=target) + glDisable(old->target); + if(!old || old->target!=target) + glEnable(target); + } glBindTexture(target, id); if(dirty_params) @@ -233,7 +236,8 @@ void Texture::unbind_from(unsigned i) { unit.bind(); glBindTexture(cur->target, 0); - glDisable(cur->target); + if(unit.supports_legacy()) + glDisable(cur->target); } } diff --git a/source/texunit.cpp b/source/texunit.cpp index 9b905120..74a23246 100644 --- a/source/texunit.cpp +++ b/source/texunit.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "gl.h" #include "misc.h" #include "texunit.h" @@ -14,6 +15,7 @@ vector TexUnit::units; TexUnit *TexUnit::cur_unit = 0; TexUnit::TexUnit(): + legacy(false), texture(0) { } @@ -46,6 +48,19 @@ unsigned TexUnit::get_n_units() return count; } +unsigned TexUnit::get_n_legacy_units() +{ + static int count = -1; + if(count<0) + { + if(MSP_legacy_features) + count = get_i(GL_MAX_TEXTURE_UNITS); + else + count = 0; + } + return count; +} + TexUnit &TexUnit::get_unit(unsigned n) { if(n>0) @@ -56,9 +71,13 @@ TexUnit &TexUnit::get_unit(unsigned n) if(units.size()<=n) { unsigned i = units.size(); + unsigned n_legacy = get_n_legacy_units(); units.resize(n+1, TexUnit()); for(; i units; @@ -26,11 +27,13 @@ private: public: unsigned get_index() const { return index; } + bool supports_legacy() const { return legacy; } bool set_texture(const Texture *); const Texture *get_texture() const { return texture; } void bind(); static unsigned get_n_units(); + static unsigned get_n_legacy_units(); static TexUnit &get_unit(unsigned); static TexUnit ¤t(); static TexUnit *find_unit(const Texture *);