- unsigned width = static_cast<const Texture2D *>(this)->width;
- unsigned height = static_cast<const Texture2D *>(this)->height;
- return id ? width*height*get_pixel_size(format) : 0;
+ if(!id)
+ return 0;
+
+ const Texture2D &self = *static_cast<const Texture2D *>(this);
+
+ size_t level_size = self.width*self.height*get_pixel_size(format);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;