+ if(gm && !EXT_framebuffer_object)
+ static Require _req(SGIS_generate_mipmap);
+ gen_mipmap = gm;
+ if(!EXT_framebuffer_object)
+ update_parameter(GENERATE_MIPMAP);
+}
+
+void Texture::auto_generate_mipmap()
+{
+ // glGenerateMipmap is defined here
+ if(EXT_framebuffer_object)
+ {
+ if(ARB_direct_state_access)
+ glGenerateTextureMipmap(id);
+ else
+ glGenerateMipmap(target);
+ }
+}
+
+void Texture::set_compare_enabled(bool c)
+{
+ if(c)
+ static Require _req(ARB_shadow);
+ compare = c;
+ update_parameter(COMPARE);
+}
+
+void Texture::set_compare_func(Predicate f)
+{
+ static Require _req(ARB_shadow);
+ cmp_func = f;
+ update_parameter(COMPARE_FUNC);
+}
+
+void Texture::load_image(const string &fn, bool srgb)
+{
+ Graphics::Image img;
+ img.load_file(fn);
+
+ image(img, srgb);
+}
+
+void Texture::bind_to(unsigned i) const
+{
+ if(!id)
+ {
+ if(manager)
+ manager->resource_used(*this);
+ if(!id)
+ {
+ unbind_from(i);
+ return;
+ }
+ }
+
+ TexUnit &unit = TexUnit::get_unit(i);
+ const Texture *old = unit.get_texture();
+ if(unit.set_texture(this))
+ {
+ if(manager)
+ manager->resource_used(*this);
+
+ unit.bind();
+ if(unit.supports_legacy())
+ {
+ if(old && old->target!=target)
+ glDisable(old->target);
+ if(!old || old->target!=target)
+ glEnable(target);
+ }
+ glBindTexture(target, id);
+
+ if(dirty_params)
+ {
+ update_parameter(dirty_params);
+ dirty_params = 0;
+ }
+ }
+}
+
+const Texture *Texture::current(unsigned i)
+{
+ return TexUnit::get_unit(i).get_texture();
+}
+
+void Texture::unbind_from(unsigned i)
+{
+ TexUnit &unit = TexUnit::get_unit(i);
+ const Texture *cur = unit.get_texture();
+ if(unit.set_texture(0))
+ {
+ unit.bind();
+ glBindTexture(cur->target, 0);
+ if(unit.supports_legacy())
+ glDisable(cur->target);
+ }