From 3f5399437221259bf0940e9bb2d3eb1d4e3ece42 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 28 Sep 2016 00:00:22 +0200 Subject: [PATCH] Fix mipmap filtering issues in tinydisplay renderer --- doc/ReleaseNotes | 1 + panda/src/tinydisplay/zbuffer.cxx | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/doc/ReleaseNotes b/doc/ReleaseNotes index 5b0b4c6478..0728f34023 100644 --- a/doc/ReleaseNotes +++ b/doc/ReleaseNotes @@ -39,6 +39,7 @@ This issue fixes several bugs that were still found in 1.9.2. * Windows installer no longer clears %PATH% if longer than 1024 chars * Fix inoperative -tbn/-tbnall/-tbnauto options in egg-optchar * Fix tinydisplay texture errors on shutdown +* Fix mipmap filtering issues in tinydisplay renderer ------------------------ RELEASE 1.9.2 ------------------------ diff --git a/panda/src/tinydisplay/zbuffer.cxx b/panda/src/tinydisplay/zbuffer.cxx index 4623a85353..cc25320646 100644 --- a/panda/src/tinydisplay/zbuffer.cxx +++ b/panda/src/tinydisplay/zbuffer.cxx @@ -489,11 +489,11 @@ lookup_texture_mipmap_linear(ZTextureDef *texture_def, int s, int t, unsigned in level = max((int)level - 1, 0); p2 = ZB_LOOKUP_TEXTURE_MIPMAP_NEAREST(texture_def, s, t, level); - unsigned int bitsize = level + ZB_POINT_ST_FRAC_BITS; - r = LINEAR_FILTER_BITSIZE(PIXEL_R(p2), PIXEL_R(p1), level_dx, bitsize); - g = LINEAR_FILTER_BITSIZE(PIXEL_G(p2), PIXEL_G(p1), level_dx, bitsize); - b = LINEAR_FILTER_BITSIZE(PIXEL_B(p2), PIXEL_B(p1), level_dx, bitsize); - a = LINEAR_FILTER_BITSIZE(PIXEL_A(p2), PIXEL_A(p1), level_dx, bitsize); + unsigned int f = level_dx >> (level - 1); + r = LINEAR_FILTER(PIXEL_R(p1), PIXEL_R(p2), f); + g = LINEAR_FILTER(PIXEL_G(p1), PIXEL_G(p2), f); + b = LINEAR_FILTER(PIXEL_B(p1), PIXEL_B(p2), f); + a = LINEAR_FILTER(PIXEL_A(p1), PIXEL_A(p2), f); return RGBA_TO_PIXEL(r, g, b, a); } @@ -570,11 +570,11 @@ lookup_texture_mipmap_trilinear(ZTextureDef *texture_def, int s, int t, unsigned } int r, g, b, a; - unsigned int bitsize = level + ZB_POINT_ST_FRAC_BITS; - r = LINEAR_FILTER_BITSIZE(PIXEL_R(p2a), PIXEL_R(p1a), level_dx, bitsize); - g = LINEAR_FILTER_BITSIZE(PIXEL_G(p2a), PIXEL_G(p1a), level_dx, bitsize); - b = LINEAR_FILTER_BITSIZE(PIXEL_B(p2a), PIXEL_B(p1a), level_dx, bitsize); - a = LINEAR_FILTER_BITSIZE(PIXEL_A(p2a), PIXEL_A(p1a), level_dx, bitsize); + unsigned int f = level_dx >> (level - 1); + r = LINEAR_FILTER(PIXEL_R(p1a), PIXEL_R(p2a), f); + g = LINEAR_FILTER(PIXEL_G(p1a), PIXEL_G(p2a), f); + b = LINEAR_FILTER(PIXEL_B(p1a), PIXEL_B(p2a), f); + a = LINEAR_FILTER(PIXEL_A(p1a), PIXEL_A(p2a), f); return RGBA_TO_PIXEL(r, g, b, a); }