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