move estimate_texture_memory() to Texture class
This commit is contained in:
parent
facee7431d
commit
0a4cb27405
|
|
@ -87,6 +87,10 @@ create_texture(DXScreenData &scrn) {
|
|||
delete_texture();
|
||||
mark_loaded();
|
||||
|
||||
#ifdef DO_PSTATS
|
||||
update_data_size_bytes(get_texture()->estimate_texture_memory());
|
||||
#endif // DO_PSTATS
|
||||
|
||||
// bpp indicates requested fmt, not texture fmt
|
||||
DWORD target_bpp = get_bits_per_pixel(get_texture()->get_format(), &num_alpha_bits);
|
||||
DWORD num_color_channels = get_texture()->get_num_components();
|
||||
|
|
|
|||
|
|
@ -554,6 +554,71 @@ write(const Filename &name, int z) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::estimate_texture_memory
|
||||
// Access: Published
|
||||
// Description: Estimates the amount of texture memory that will be
|
||||
// consumed by loading this texture. This returns a
|
||||
// value that is not specific to any particular graphics
|
||||
// card or driver; it tries to make a reasonable
|
||||
// assumption about how a driver will load the texture.
|
||||
// It does not account for texture compression or
|
||||
// anything fancy. This is mainly useful for debugging
|
||||
// and reporting purposes.
|
||||
//
|
||||
// Returns a value in bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
size_t Texture::
|
||||
estimate_texture_memory() const {
|
||||
size_t pixels = get_x_size() * get_y_size();
|
||||
|
||||
size_t bpp = 4;
|
||||
switch (get_format()) {
|
||||
case Texture::F_rgb332:
|
||||
bpp = 1;
|
||||
break;
|
||||
|
||||
case Texture::F_alpha:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_luminance:
|
||||
case Texture::F_luminance_alpha:
|
||||
case Texture::F_luminance_alphamask:
|
||||
bpp = 4;
|
||||
break;
|
||||
|
||||
case Texture::F_rgba:
|
||||
case Texture::F_rgba4:
|
||||
case Texture::F_rgbm:
|
||||
case Texture::F_rgb:
|
||||
case Texture::F_rgb5:
|
||||
case Texture::F_rgba5:
|
||||
bpp = 4;
|
||||
break;
|
||||
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_stencil_index:
|
||||
case Texture::F_depth_component:
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgba8:
|
||||
bpp = 4;
|
||||
break;
|
||||
|
||||
case Texture::F_rgba12:
|
||||
case Texture::F_rgb12:
|
||||
bpp = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t bytes = pixels * bpp;
|
||||
if (is_mipmap(get_minfilter())) {
|
||||
bytes = (bytes * 4) / 3;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: Texture::read_txo
|
||||
// Access: Published
|
||||
|
|
|
|||
|
|
@ -276,6 +276,8 @@ PUBLISHED:
|
|||
|
||||
void write(ostream &out, int indent_level) const;
|
||||
|
||||
size_t estimate_texture_memory() const;
|
||||
|
||||
PUBLISHED:
|
||||
// These are published, but in general, you shouldn't be mucking
|
||||
// with these values; they are set automatically when a texture is
|
||||
|
|
|
|||
|
|
@ -27,9 +27,6 @@ TextureContext(PreparedGraphicsObjects *pgo, Texture *tex) :
|
|||
BufferContext(&pgo->_texture_residency),
|
||||
_texture(tex)
|
||||
{
|
||||
#ifdef DO_PSTATS
|
||||
update_data_size_bytes(estimate_texture_memory());
|
||||
#endif
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -18,82 +18,4 @@
|
|||
|
||||
#include "textureContext.h"
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
TypeHandle TextureContext::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: TextureContext::estimate_texture_memory
|
||||
// Access: Public, Virtual
|
||||
// Description: Estimates the amount of texture memory that will be
|
||||
// consumed by loading this texture. This is mainly
|
||||
// useful for debugging and reporting purposes.
|
||||
//
|
||||
// Returns a value in bytes.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
size_t TextureContext::
|
||||
estimate_texture_memory() {
|
||||
size_t pixels = _texture->get_x_size() * _texture->get_y_size();
|
||||
|
||||
size_t bpp = 4;
|
||||
|
||||
/*
|
||||
size_t bpp = 1;
|
||||
switch (_texture->get_format()) {
|
||||
case Texture::F_rgb332:
|
||||
case Texture::F_alpha:
|
||||
case Texture::F_red:
|
||||
case Texture::F_green:
|
||||
case Texture::F_blue:
|
||||
case Texture::F_luminance:
|
||||
case Texture::F_luminance_alpha:
|
||||
case Texture::F_luminance_alphamask:
|
||||
case Texture::F_color_index:
|
||||
case Texture::F_stencil_index:
|
||||
case Texture::F_depth_component:
|
||||
bpp = 1;
|
||||
break;
|
||||
|
||||
case Texture::F_rgba:
|
||||
case Texture::F_rgba4:
|
||||
case Texture::F_rgbm:
|
||||
case Texture::F_rgb:
|
||||
case Texture::F_rgb5:
|
||||
case Texture::F_rgba5:
|
||||
bpp = 2;
|
||||
break;
|
||||
|
||||
case Texture::F_rgb8:
|
||||
case Texture::F_rgba8:
|
||||
bpp = 4;
|
||||
break;
|
||||
|
||||
case Texture::F_rgba12:
|
||||
case Texture::F_rgb12:
|
||||
bpp = 6;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
size_t bytes = pixels * bpp;
|
||||
|
||||
bool use_mipmaps;
|
||||
switch (_texture->get_minfilter()) {
|
||||
case Texture::FT_nearest_mipmap_nearest:
|
||||
case Texture::FT_linear_mipmap_nearest:
|
||||
case Texture::FT_nearest_mipmap_linear:
|
||||
case Texture::FT_linear_mipmap_linear:
|
||||
use_mipmaps = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
use_mipmaps = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (use_mipmaps) {
|
||||
bytes += bytes / 3;
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,6 @@ public:
|
|||
INLINE bool was_modified() const;
|
||||
INLINE void mark_loaded();
|
||||
|
||||
virtual size_t estimate_texture_memory();
|
||||
|
||||
private:
|
||||
// This cannot be a PT(Texture), because the texture and the GSG
|
||||
// both own their TextureContexts! That would create a circular
|
||||
|
|
|
|||
Loading…
Reference in New Issue