From d93adbacbb60b5f571991bcc7874059db38e7490 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Fri, 3 Jan 2020 23:01:12 -0300 Subject: [PATCH] Fix GetTextureUsed --- src/hardware/r_opengl/r_opengl.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 129bf5678..9fa49cf76 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2275,14 +2275,30 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) EXPORT INT32 HWRAPI(GetTextureUsed) (void) { - FTextureInfo* tmp = gr_cachehead; - INT32 res = 0; + FTextureInfo *tmp = gr_cachehead; + INT32 res = 0; while (tmp) { - res += tmp->height*tmp->width*(screen_depth/8); + // Figure out the correct bytes-per-pixel for this texture + // I don't know which one the game actually _uses_ but this + // follows format2bpp in hw_cache.c + int bpp = 1; + int format = tmp->grInfo.format; + if (format == GR_RGBA) + bpp = 4; + else if (format == GR_TEXFMT_RGB_565 + || format == GR_TEXFMT_ARGB_1555 + || format == GR_TEXFMT_ARGB_4444 + || format == GR_TEXFMT_ALPHA_INTENSITY_88 + || format == GR_TEXFMT_AP_88) + bpp = 2; + + // Add it up! + res += tmp->height*tmp->width*bpp; tmp = tmp->nextmipmap; } + return res; }