+ static Require _req(EXT_texture3D);
+ wrap_r = w;
+ update_parameter(WRAP_R);
+}
+
+bool Texture::can_generate_mipmap()
+{
+ return EXT_framebuffer_object;
+}
+
+void Texture::generate_mipmap()
+{
+ // glGenerateMipmap is defined here
+ static Require _req(EXT_framebuffer_object);
+
+ if(ARB_direct_state_access)
+ glGenerateTextureMipmap(id);
+ else
+ {
+ BindRestore _bind(this);
+ glGenerateMipmap(target);
+ }
+}
+
+void Texture::set_auto_generate_mipmap(bool gm)
+{
+ if(gm)
+ static Require _req(EXT_framebuffer_object);
+
+ auto_gen_mipmap = gm;
+}
+
+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);
+ if(unit.set_texture(this))
+ {
+ if(manager)
+ manager->resource_used(*this);
+
+ if(ARB_direct_state_access)
+ glBindTextureUnit(i, id);
+ else
+ {
+ unit.bind();
+ 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))
+ {
+ if(ARB_direct_state_access)
+ glBindTextureUnit(i, 0);
+ else
+ {
+ unit.bind();
+ glBindTexture(cur->target, 0);
+ }
+ }