This isn't 100% accurate, but good enough for resource management.
size_t OpenGLTexture1D::get_data_size() const
{
+ if(!id)
+ return 0;
+
unsigned width = static_cast<const Texture1D *>(this)->width;
- return id ? width*get_pixel_size(storage_fmt) : 0;
+ unsigned levels = static_cast<const Texture1D *>(this)->levels;
+
+ size_t level_size = width*get_pixel_size(storage_fmt);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
}
} // namespace GL
uint64_t OpenGLTexture2D::get_data_size() const
{
+ if(!id)
+ return 0;
+
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;
+ unsigned levels = static_cast<const Texture2D *>(this)->levels;
+
+ size_t level_size = width*height*get_pixel_size(format);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
}
void OpenGLTexture2D::unload()
static Require _req(EXT_texture_array);
}
+size_t OpenGLTexture2DArray::get_data_size() const
+{
+ if(!id)
+ return 0;
+
+ size_t level_size = width*height*get_pixel_size(format);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ total_size += level_size*depth;
+ return total_size;
+}
+
} // namespace GL
} // namespace Msp
{
protected:
OpenGLTexture2DArray();
+
+public:
+ virtual std::size_t get_data_size() const;
};
using Texture2DArrayBackend = OpenGLTexture2DArray;
size_t OpenGLTexture3D::get_data_size() const
{
+ if(!id)
+ return 0;
+
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;
+ unsigned levels = static_cast<const Texture3D *>(this)->levels;
+
+ size_t level_size = width*height*depth*get_pixel_size(format);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
}
} // namespace GL
size_t OpenGLTextureCube::get_data_size() const
{
+ if(!id)
+ return 0;
+
unsigned size = static_cast<const TextureCube *>(this)->size;
- return id ? size*size*6*get_pixel_size(storage_fmt) : 0;
+ unsigned levels = static_cast<const TextureCube *>(this)->levels;
+
+ size_t level_size = size*size*get_pixel_size(storage_fmt);
+ size_t total_size = level_size;
+ for(unsigned i=0; i<levels; ++i, level_size>>=2)
+ total_size += level_size;
+ return total_size;
}