From d16a4ab73f87d177296b59f04880ef7eba593df7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 4 Oct 2008 19:50:15 +0000 Subject: [PATCH] Add Texture::bind_to() method Check if texture is already bound in bind() --- source/texture.cpp | 21 +++++++++++++++------ source/texture.h | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) 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); } -- 2.45.2