+ if(width==0 || height==0)
+ throw invalid_operation("Texture2D::allocate");
+ if(level>=levels)
+ throw invalid_argument("Texture2D::allocate");
+ if(allocated&(1<<level))
+ return;
+
+ if(ARB_texture_storage)
+ {
+ Conditional<BindRestore> _bind(!ARB_direct_state_access, this);
+ if(ARB_direct_state_access)
+ glTextureStorage2D(id, levels, storage_fmt, width, height);
+ else
+ glTexStorage2D(target, levels, storage_fmt, width, height);
+ apply_swizzle();
+ allocated |= (1<<levels)-1;
+ }
+ else
+ image(level, 0);
+}
+
+void Texture2D::image(unsigned level, const void *data)
+{
+ if(width==0 || height==0)
+ throw invalid_operation("Texture2D::image");
+
+ unsigned w = width;
+ unsigned h = height;
+ get_level_size(level, w, h);
+
+ if(ARB_texture_storage)
+ return sub_image(level, 0, 0, w, h, data);
+
+ BindRestore _bind(this);