Skip to content

Commit a0d0983

Browse files
committed
Fix R_ListImages_f() image size
Account for mipmaps to report more accurate memory data.
1 parent f989ce9 commit a0d0983

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

src/engine/renderer/tr_image.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void R_ListImages_f()
348348
type = imageTypeName.at( image->type );
349349
}
350350

351-
int imageDataSize = image->uploadWidth * image->uploadHeight * image->numLayers;
351+
int imageDataSize = 0;
352352
texels += imageDataSize;
353353

354354
if ( !imageFormatNameSize.count( image->internalFormat ) )
@@ -372,14 +372,51 @@ void R_ListImages_f()
372372
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
373373
case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
374374
case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
375+
{
375376
format = imageFormatNameSize.at( image->internalFormat ).first;
376-
imageDataSize = ceil( image->uploadWidth / 4.0 ) * ceil( image->uploadHeight / 4.0 ) * image->numLayers
377-
* imageFormatNameSize.at( image->internalFormat ).second;
377+
378+
uint16_t imageWidth = image->uploadWidth;
379+
uint16_t imageHeight = image->uploadHeight;
380+
uint16_t imageLayers = image->numLayers;
381+
382+
int numMips = 1;
383+
if ( image->filterType == filterType_t::FT_DEFAULT ) {
384+
numMips = log2f( std::max( std::max( imageWidth, imageHeight ), imageLayers ) ) + 1;
385+
}
386+
387+
for ( int j = 0; j < numMips; j++ ) {
388+
imageDataSize += ceil( imageWidth / 4.0 ) * ceil( imageHeight / 4.0 ) * imageLayers;
389+
imageWidth >>= imageWidth > 1 ? 1 : 0;
390+
imageHeight >>= imageHeight > 1 ? 1 : 0;
391+
imageLayers >>= imageLayers > 1 ? 1 : 0;
392+
}
393+
394+
imageDataSize *= imageFormatNameSize.at( image->internalFormat ).second;
378395
break;
396+
}
379397
default:
398+
{
380399
format = imageFormatNameSize.at( image->internalFormat ).first;
400+
401+
uint16_t imageWidth = image->uploadWidth;
402+
uint16_t imageHeight = image->uploadHeight;
403+
uint16_t imageLayers = image->numLayers;
404+
405+
int numMips = 1;
406+
if ( image->filterType == filterType_t::FT_DEFAULT ) {
407+
numMips = log2f( std::max( std::max( imageWidth, imageHeight ), imageLayers ) ) + 1;
408+
}
409+
410+
for ( int j = 0; j < numMips; j++ ) {
411+
imageDataSize += imageWidth * imageHeight * imageLayers;
412+
imageWidth >>= imageWidth > 1 ? 1 : 0;
413+
imageHeight >>= imageHeight > 1 ? 1 : 0;
414+
imageLayers >>= imageLayers > 1 ? 1 : 0;
415+
}
416+
381417
imageDataSize *= imageFormatNameSize.at( image->internalFormat ).second;
382418
break;
419+
}
383420
}
384421
}
385422

0 commit comments

Comments
 (0)