diff --git a/panda/src/dxgsg8/dxTextureContext8.cxx b/panda/src/dxgsg8/dxTextureContext8.cxx index 56a45722a6..6b1002720b 100644 --- a/panda/src/dxgsg8/dxTextureContext8.cxx +++ b/panda/src/dxgsg8/dxTextureContext8.cxx @@ -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(); diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index ce85034adb..92eb429ea9 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -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 diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 13cfe49afc..9dd673579d 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -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 diff --git a/panda/src/gobj/textureContext.I b/panda/src/gobj/textureContext.I index 5c1bb4066d..122614ae88 100644 --- a/panda/src/gobj/textureContext.I +++ b/panda/src/gobj/textureContext.I @@ -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 } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/gobj/textureContext.cxx b/panda/src/gobj/textureContext.cxx index df92f6f033..e1fcd71bd5 100644 --- a/panda/src/gobj/textureContext.cxx +++ b/panda/src/gobj/textureContext.cxx @@ -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; -} diff --git a/panda/src/gobj/textureContext.h b/panda/src/gobj/textureContext.h index 074c963f13..d955a35d90 100644 --- a/panda/src/gobj/textureContext.h +++ b/panda/src/gobj/textureContext.h @@ -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