Browse Source

Apply tobspr's texture memory calculation fixes to 1.9 branch

rdb 10 years ago
parent
commit
47de3542f6
2 changed files with 17 additions and 8 deletions
  1. 2 0
      panda/src/glstuff/glGraphicsStateGuardian_src.cxx
  2. 15 8
      panda/src/gobj/texture.cxx

+ 2 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -10854,6 +10854,8 @@ upload_texture(CLP(TextureContext) *gtc, bool force, bool uses_mipmaps) {
       gtc->_width = width;
       gtc->_width = width;
       gtc->_height = height;
       gtc->_height = height;
       gtc->_depth = depth;
       gtc->_depth = depth;
+      gtc->update_data_size_bytes(get_texture_memory_size(gtc));
+
       needs_reload = false;
       needs_reload = false;
     }
     }
   } else {
   } else {

+ 15 - 8
panda/src/gobj/texture.cxx

@@ -489,7 +489,7 @@ read(const Filename &fullpath, const Filename &alpha_fullpath,
 size_t Texture::
 size_t Texture::
 estimate_texture_memory() const {
 estimate_texture_memory() const {
   CDReader cdata(_cycler);
   CDReader cdata(_cycler);
-  size_t pixels = cdata->_x_size * cdata->_y_size;
+  size_t pixels = cdata->_x_size * cdata->_y_size * cdata->_z_size;
 
 
   size_t bpp = 4;
   size_t bpp = 4;
   switch (cdata->_format) {
   switch (cdata->_format) {
@@ -503,22 +503,25 @@ estimate_texture_memory() const {
   case Texture::F_blue:
   case Texture::F_blue:
   case Texture::F_luminance:
   case Texture::F_luminance:
   case Texture::F_sluminance:
   case Texture::F_sluminance:
+  case Texture::F_r8i:
     bpp = 1;
     bpp = 1;
     break;
     break;
 
 
   case Texture::F_luminance_alpha:
   case Texture::F_luminance_alpha:
   case Texture::F_luminance_alphamask:
   case Texture::F_luminance_alphamask:
   case Texture::F_sluminance_alpha:
   case Texture::F_sluminance_alpha:
+  case Texture::F_rgba4:
+  case Texture::F_rgb5:
+  case Texture::F_rgba5:
     bpp = 2;
     bpp = 2;
     break;
     break;
 
 
   case Texture::F_rgba:
   case Texture::F_rgba:
-  case Texture::F_rgba4:
   case Texture::F_rgbm:
   case Texture::F_rgbm:
   case Texture::F_rgb:
   case Texture::F_rgb:
-  case Texture::F_rgb5:
-  case Texture::F_rgba5:
   case Texture::F_srgb:
   case Texture::F_srgb:
+    // Most of the above formats have only 3 bytes, but they are most likely to
+    // get padded by the driver
     bpp = 4;
     bpp = 4;
     break;
     break;
 
 
@@ -536,9 +539,15 @@ estimate_texture_memory() const {
     break;
     break;
 
 
   case Texture::F_depth_component:
   case Texture::F_depth_component:
+  case Texture::F_depth_component16:
     bpp = 2;
     bpp = 2;
     break;
     break;
 
 
+  case Texture::F_depth_component24: // Gets padded
+  case Texture::F_depth_component32:
+    bpp = 4;
+    break;
+
   case Texture::F_rgba12:
   case Texture::F_rgba12:
   case Texture::F_rgb12:
   case Texture::F_rgb12:
     bpp = 8;
     bpp = 8;
@@ -552,7 +561,6 @@ estimate_texture_memory() const {
     break;
     break;
 
 
   case Texture::F_r16:
   case Texture::F_r16:
-  case Texture::F_r8i:
   case Texture::F_rg8i:
   case Texture::F_rg8i:
     bpp = 2;
     bpp = 2;
     break;
     break;
@@ -564,15 +572,14 @@ estimate_texture_memory() const {
     break;
     break;
 
 
   case Texture::F_r32i:
   case Texture::F_r32i:
-    bpp = 4;
-    break;
-
   case Texture::F_r32:
   case Texture::F_r32:
     bpp = 4;
     bpp = 4;
     break;
     break;
+
   case Texture::F_rg32:
   case Texture::F_rg32:
     bpp = 8;
     bpp = 8;
     break;
     break;
+
   case Texture::F_rgb32:
   case Texture::F_rgb32:
     bpp = 12;
     bpp = 12;
     break;
     break;