]> git.tdb.fi Git - libs/gl.git/commitdiff
Don't enable/disable textures on non-legacy units
authorMikko Rasa <tdb@tdb.fi>
Sun, 19 Oct 2014 14:25:56 +0000 (17:25 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 19 Oct 2014 15:31:07 +0000 (18:31 +0300)
source/texture.cpp
source/texunit.cpp
source/texunit.h

index 187c2533acbea6fc9e30c33370ffb99ca2a15a18..81373c97b8793bb99f66c5669e6bc7f761c5d7d9 100644 (file)
@@ -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);
        }
 }
 
index 9b905120db6861d54204b172264d58c6f5340383..74a23246b368ac6ad3b6b3d69765c5f6d4bbd82e 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdexcept>
 #include <msp/gl/extensions/arb_multitexture.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
+#include <msp/gl/extensions/msp_legacy_features.h>
 #include "gl.h"
 #include "misc.h"
 #include "texunit.h"
@@ -14,6 +15,7 @@ vector<TexUnit> 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.size(); ++i)
+               {
                        units[i].index = i;
+                       units[i].legacy = (i<n_legacy);
+               }
        }
 
        return units[n];
index f3f95e7e422b2179ffea94f6d9c3834891ea8bc9..0bba15d6a48fc86ccfe945351b04190f95fef73f 100644 (file)
@@ -17,6 +17,7 @@ class TexUnit
 {
 private:
        unsigned index;
+       bool legacy;
        const Texture *texture;
 
        static std::vector<TexUnit> 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 &current();
        static TexUnit *find_unit(const Texture *);