X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftexture.cpp;h=d71f38c2f1f2efba27edf95c57925c0a11946f54;hb=d16a4ab73f87d177296b59f04880ef7eba593df7;hp=c6aea2c85910f99ec3411587b8b005b6e525920f;hpb=f098a871fc6dc7b61a5aca5581fa327e4124c036;p=libs%2Fgl.git diff --git a/source/texture.cpp b/source/texture.cpp index c6aea2c8..d71f38c2 100644 --- a/source/texture.cpp +++ b/source/texture.cpp @@ -5,25 +5,60 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#include +#include "except.h" #include "texture.h" #include "texunit.h" +using namespace std; + namespace Msp { namespace GL { +istream &operator>>(istream &in, TextureFilter &tf) +{ + string str; + in>>str; + + if(str=="NEAREST") + tf=NEAREST; + else if(str=="LINEAR") + tf=LINEAR; + else if(str=="NEAREST_MIPMAP_NEAREST") + tf=NEAREST_MIPMAP_NEAREST; + else if(str=="NEAREST_MIPMAP_LINEAR") + tf=NEAREST_MIPMAP_LINEAR; + else if(str=="LINEAR_MIPMAP_NEAREST") + tf=LINEAR_MIPMAP_NEAREST; + else if(str=="LINEAR_MIPMAP_LINEAR") + tf=LINEAR_MIPMAP_LINEAR; + else + in.setstate(ios_base::failbit); + + return in; +} + + void Texture::bind() const { if(!target) 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) @@ -68,5 +103,29 @@ void Texture::maybe_bind() const bind(); } + +Texture::Loader::Loader(Texture &t): + tex(t) +{ + add("min_filter", &Loader::min_filter); + add("mag_filter", &Loader::mag_filter); + add("generate_mipmap", &Loader::generate_mipmap); +} + +void Texture::Loader::min_filter(TextureFilter f) +{ + tex.set_min_filter(f); +} + +void Texture::Loader::mag_filter(TextureFilter f) +{ + tex.set_mag_filter(f); +} + +void Texture::Loader::generate_mipmap(bool gm) +{ + tex.parameter(GL_GENERATE_MIPMAP_SGIS, gm); +} + } // namespace GL } // namespace Msp