]> git.tdb.fi Git - libs/gl.git/commitdiff
Add Texture::bind_to() method
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 Oct 2008 19:50:15 +0000 (19:50 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 4 Oct 2008 19:50:15 +0000 (19:50 +0000)
Check if texture is already bound in bind()

source/texture.cpp
source/texture.h

index 7ce039acb6df2278ff8c2df8c289e63cfd290820..d71f38c2f1f2efba27edf95c57925c0a11946f54 100644 (file)
@@ -44,12 +44,21 @@ void Texture::bind() const
                throw InvalidState("Attempt to bind a texture without target");
 
        const Texture *cur=TexUnit::current().get_texture();
-       if(cur && cur->target!=target)
-               glDisable(cur->target);
-       if(!cur || cur->target!=target)
-               glEnable(target);
-       glBindTexture(target, id);
-       TexUnit::current().set_texture(this);
+       if(cur!=this)
+       {
+               if(cur && cur->target!=target)
+                       glDisable(cur->target);
+               if(!cur || cur->target!=target)
+                       glEnable(target);
+               glBindTexture(target, id);
+               TexUnit::current().set_texture(this);
+       }
+}
+
+void Texture::bind_to(unsigned i) const
+{
+       TexUnit::activate(i);
+       bind();
 }
 
 void Texture::parameter(GLenum param, int value)
index 6dd729b4d23a546f0c50bc92a4aa2cb73291652d..61b1bebdbac92611e9fcc853eea99a4a4e19a5a4 100644 (file)
@@ -53,6 +53,7 @@ public:
        ~Texture();
 
        void bind() const;
+       void bind_to(unsigned) const;
        void parameter(GLenum, int);
        void parameter(GLenum, float);
        void set_min_filter(TextureFilter f) { parameter(GL_TEXTURE_MIN_FILTER, f); }