3 This file is part of libmspgl
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
17 istream &operator>>(istream &in, TextureFilter &tf)
24 else if(str=="LINEAR")
26 else if(str=="NEAREST_MIPMAP_NEAREST")
27 tf=NEAREST_MIPMAP_NEAREST;
28 else if(str=="NEAREST_MIPMAP_LINEAR")
29 tf=NEAREST_MIPMAP_LINEAR;
30 else if(str=="LINEAR_MIPMAP_NEAREST")
31 tf=LINEAR_MIPMAP_NEAREST;
32 else if(str=="LINEAR_MIPMAP_LINEAR")
33 tf=LINEAR_MIPMAP_LINEAR;
35 in.setstate(ios_base::failbit);
41 void Texture::bind() const
44 throw InvalidState("Attempt to bind a texture without target");
46 const Texture *cur=TexUnit::current().get_texture();
47 if(cur && cur->target!=target)
48 glDisable(cur->target);
49 if(!cur || cur->target!=target)
51 glBindTexture(target, id);
52 TexUnit::current().set_texture(this);
55 void Texture::parameter(GLenum param, int value)
59 glTexParameteri(target, param, value);
62 void Texture::parameter(GLenum param, float value)
66 glTexParameterf(target, param, value);
71 glDeleteTextures(1, &id);
74 void Texture::unbind()
76 const Texture *cur=TexUnit::current().get_texture();
80 glBindTexture(cur->target, 0);
81 glDisable(cur->target);
82 TexUnit::current().set_texture(0);
88 glGenTextures(1, &id);
91 void Texture::maybe_bind() const
93 if(TexUnit::current().get_texture()!=this)
98 Texture::Loader::Loader(Texture &t):
101 add("min_filter", &Loader::min_filter);
102 add("mag_filter", &Loader::mag_filter);
103 add("generate_mipmap", &Loader::generate_mipmap);
106 void Texture::Loader::min_filter(TextureFilter f)
108 tex.set_min_filter(f);
111 void Texture::Loader::mag_filter(TextureFilter f)
113 tex.set_mag_filter(f);
116 void Texture::Loader::generate_mipmap(bool gm)
118 tex.parameter(GL_GENERATE_MIPMAP_SGIS, gm);