From: Mikko Rasa Date: Sat, 4 Oct 2008 19:50:15 +0000 (+0000) Subject: Add Texture::bind_to() method X-Git-Tag: 1.0~2 X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=d16a4ab73f87d177296b59f04880ef7eba593df7 Add Texture::bind_to() method Check if texture is already bound in bind() --- diff --git a/source/texture.cpp b/source/texture.cpp index 7ce039ac..d71f38c2 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -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) diff --git a/source/texture.h b/source/texture.h index 6dd729b4..61b1bebd 100644 --- a/source/texture.h +++ b/source/texture.h @@ -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); }