+ while(TexUnit *unit = TexUnit::find_unit(this))
+ unbind_from(unit->get_index());
+
+ if(id)
+ glDeleteTextures(1, &id);
+}
+
+DataType Texture::get_alloc_type(PixelFormat fmt)
+{
+ return (get_base_pixelformat(fmt)==DEPTH_COMPONENT ? UNSIGNED_SHORT : UNSIGNED_BYTE);
+}
+
+void Texture::set_internal_format(PixelFormat fmt)
+{
+ if(!get_component_size(fmt) && OES_required_internalformat)
+ fmt = get_default_sized_pixelformat(fmt);
+
+ FormatSwizzle swiz = NO_SWIZZLE;
+ if(ARB_texture_rg && ARB_texture_swizzle)
+ {
+ if(fmt==LUMINANCE8)
+ {
+ fmt = R8;
+ swiz = R_TO_LUMINANCE;
+ }
+ else if(fmt==LUMINANCE8_ALPHA8)
+ {
+ fmt = RG8;
+ swiz = RG_TO_LUMINANCE_ALPHA;
+ }
+ }
+
+ require_pixelformat(fmt);
+ ifmt = fmt;
+ swizzle = swiz;
+ if(swizzle)
+ update_parameter(FORMAT_SWIZZLE);
+}
+
+PixelFormat Texture::get_upload_format(PixelFormat fmt) const
+{
+ if(fmt==LUMINANCE || fmt==LUMINANCE_ALPHA)
+ return get_base_pixelformat(ifmt);
+ else
+ return fmt;