GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA
};
+Texture *Texture::scratch_binding = 0;
+
Texture::Texture(GLenum t, ResourceManager *m):
id(0),
target(t),
Texture::~Texture()
{
+ if(this==scratch_binding)
+ unbind_scratch();
if(id)
glDeleteTextures(1, &id);
}
// glGenerateMipmap is defined here
static Require _req(EXT_framebuffer_object);
- if(!ARB_direct_state_access)
- {
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(target, id);
- }
- generate_mipmap_();
- if(!ARB_direct_state_access)
- glBindTexture(target, 0);
-}
-
-void Texture::generate_mipmap_()
-{
if(ARB_direct_state_access)
glGenerateTextureMipmap(id);
else
+ {
+ bind_scratch();
glGenerateMipmap(target);
+ }
}
void Texture::set_auto_generate_mipmap(bool gm)
#endif
}
+void Texture::bind_scratch()
+{
+ if(!scratch_binding)
+ glActiveTexture(GL_TEXTURE0);
+ if(scratch_binding!=this)
+ {
+ if(scratch_binding && scratch_binding->target!=target)
+ glBindTexture(scratch_binding->target, 0);
+ glBindTexture(target, id);
+ scratch_binding = this;
+ }
+}
+
+void Texture::unbind_scratch()
+{
+ if(scratch_binding)
+ {
+ glBindTexture(scratch_binding->target, 0);
+ scratch_binding = 0;
+ }
+}
+
Texture::Loader::Loader(Texture &t):
DataFile::CollectionObjectLoader<Texture>(t, 0)