1 #include <msp/core/error.h>
8 void Texture::bind() const
11 throw InvalidState("Attempt to bind a texture without target");
13 const Texture *cur=TexUnit::current().get_texture();
14 if(cur && cur->target!=target)
15 glDisable(cur->target);
16 if(!cur || cur->target!=target)
18 glBindTexture(target, id);
19 TexUnit::current().set_texture(this);
22 void Texture::parameter(GLenum param, int value)
26 glTexParameteri(target, param, value);
29 void Texture::parameter(GLenum param, float value)
33 glTexParameterf(target, param, value);
38 glDeleteTextures(1, &id);
41 void Texture::unbind()
43 const Texture *cur=TexUnit::current().get_texture();
47 glBindTexture(cur->target, 0);
48 glDisable(cur->target);
49 TexUnit::current().set_texture(0);
55 glGenTextures(1, &id);
58 void Texture::maybe_bind() const
60 if(TexUnit::current().get_texture()!=this)