+ 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);
+ }
+ }
+}
+
+
+Texture::Loader::Loader(Texture &t):
+ DataFile::CollectionObjectLoader<Texture>(t, 0)
+{
+ init();
+}
+
+Texture::Loader::Loader(Texture &t, Collection &c):
+ DataFile::CollectionObjectLoader<Texture>(t, &c)
+{
+ init();
+}
+
+void Texture::Loader::init()
+{
+ if(Resources *res = dynamic_cast<Resources *>(coll))
+ srgb = res->get_srgb_conversion();
+ else
+ srgb = false;
+
+ add("external_image", &Loader::external_image);
+ add("filter", &Loader::filter);
+ add("generate_mipmap", &Loader::generate_mipmap);
+ add("image_data", &Loader::image_data);
+ add("mag_filter", &Loader::mag_filter);
+ add("max_anisotropy", &Loader::max_anisotropy);
+ add("min_filter", &Loader::min_filter);
+ add("mipmap_levels", &Loader::mipmap_levels);
+ add("wrap", &Loader::wrap);
+ add("wrap_r", &Loader::wrap_r);
+ add("wrap_s", &Loader::wrap_s);
+ add("wrap_t", &Loader::wrap_t);
+}
+
+void Texture::Loader::external_image(const string &fn)
+{
+ Graphics::Image img;
+ RefPtr<IO::Seekable> io = get_collection().open_raw(fn);
+ if(!io)
+ throw IO::file_not_found(fn);
+ img.load_io(*io);
+
+ obj.image(img, srgb);
+}
+
+void Texture::Loader::filter(TextureFilter f)
+{
+ obj.set_filter(f);