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();
49 if(cur && cur->target!=target)
50 glDisable(cur->target);
51 if(!cur || cur->target!=target)
53 glBindTexture(target, id);
54 TexUnit::current().set_texture(this);
58 void Texture::bind_to(unsigned i) const
64 void Texture::parameter(GLenum param, int value)
68 glTexParameteri(target, param, value);
71 void Texture::parameter(GLenum param, float value)
75 glTexParameterf(target, param, value);
80 glDeleteTextures(1, &id);
83 void Texture::unbind()
85 const Texture *cur=TexUnit::current().get_texture();
89 glBindTexture(cur->target, 0);
90 glDisable(cur->target);
91 TexUnit::current().set_texture(0);
94 void Texture::unbind_from(unsigned i)
103 glGenTextures(1, &id);
106 void Texture::maybe_bind() const
108 if(TexUnit::current().get_texture()!=this)
113 Texture::Loader::Loader(Texture &t):
114 DataFile::ObjectLoader<Texture>(t)
116 add("min_filter", &Loader::min_filter);
117 add("mag_filter", &Loader::mag_filter);
118 add("generate_mipmap", &Loader::generate_mipmap);
121 void Texture::Loader::min_filter(TextureFilter f)
123 obj.set_min_filter(f);
126 void Texture::Loader::mag_filter(TextureFilter f)
128 obj.set_mag_filter(f);
131 void Texture::Loader::generate_mipmap(bool gm)
133 obj.parameter(GL_GENERATE_MIPMAP_SGIS, gm);