From 8779421a3e0f373b0c73d56d28b9a9a4d370d6da Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 25 Apr 2022 08:54:02 -0700 Subject: [PATCH] GLES: Reverse alphamask when comparing to CLUT. The CLUT is already reversed. --- GPU/Common/TextureCacheCommon.cpp | 23 ++++++++++++----------- GPU/Common/TextureCacheCommon.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 415245bd71..4a651746ed 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1405,12 +1405,12 @@ static CheckAlphaResult DecodeDXTBlocks(uint8_t *out, int outPitch, uint32_t tex } } -inline u32 ClutFormatToFullAlpha(GEPaletteFormat fmt) { +inline u32 ClutFormatToFullAlpha(GEPaletteFormat fmt, bool reverseColors) { switch (fmt) { - case GE_CMODE_16BIT_ABGR4444: return 0xF000; - case GE_CMODE_16BIT_ABGR5551: return 0x8000; + case GE_CMODE_16BIT_ABGR4444: return reverseColors ? 0x000F : 0xF000; + case GE_CMODE_16BIT_ABGR5551: return reverseColors ? 0x0001 : 0x8000; case GE_CMODE_32BIT_ABGR8888: return 0xFF000000; - case GE_CMODE_16BIT_BGR5650: + case GE_CMODE_16BIT_BGR5650: return 0; default: return 0; } } @@ -1420,7 +1420,7 @@ inline u32 TfmtRawToFullAlpha(GETextureFormat fmt) { case GE_TFMT_4444: return 0xF000; case GE_TFMT_5551: return 0x8000; case GE_TFMT_8888: return 0xFF000000; - case GE_TFMT_5650: + case GE_TFMT_5650: return 0; default: return 0; } } @@ -1489,7 +1489,8 @@ CheckAlphaResult TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, G DeIndexTexture4((u32 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, expandClut_, &alphaSum); } } else { - fullAlphaMask = ClutFormatToFullAlpha(clutformat); + // If we're reversing colors, the CLUT was already reversed. + fullAlphaMask = ClutFormatToFullAlpha(clutformat, reverseColors); for (int y = 0; y < h; ++y) { DeIndexTexture4((u16 *)(out + outPitch * y), texptr + (bufw * y) / 2, w, clut, &alphaSum); } @@ -1521,13 +1522,13 @@ CheckAlphaResult TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, G break; case GE_TFMT_CLUT8: - return ReadIndexedTex(out, outPitch, level, texptr, 1, bufw, expandTo32bit); + return ReadIndexedTex(out, outPitch, level, texptr, 1, bufw, reverseColors, expandTo32bit); case GE_TFMT_CLUT16: - return ReadIndexedTex(out, outPitch, level, texptr, 2, bufw, expandTo32bit); + return ReadIndexedTex(out, outPitch, level, texptr, 2, bufw, reverseColors, expandTo32bit); case GE_TFMT_CLUT32: - return ReadIndexedTex(out, outPitch, level, texptr, 4, bufw, expandTo32bit); + return ReadIndexedTex(out, outPitch, level, texptr, 4, bufw, reverseColors, expandTo32bit); case GE_TFMT_4444: case GE_TFMT_5551: @@ -1643,7 +1644,7 @@ CheckAlphaResult TextureCacheCommon::DecodeTextureLevel(u8 *out, int outPitch, G return AlphaSumIsFull(alphaSum, fullAlphaMask) ? CHECKALPHA_FULL : CHECKALPHA_ANY; } -CheckAlphaResult TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, int bufw, bool expandTo32Bit) { +CheckAlphaResult TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, int bufw, bool reverseColors, bool expandTo32Bit) { int w = gstate.getTextureWidth(level); int h = gstate.getTextureHeight(level); @@ -1665,7 +1666,7 @@ CheckAlphaResult TextureCacheCommon::ReadIndexedTex(u8 *out, int outPitch, int l } u32 alphaSum = 0xFFFFFFFF; - u32 fullAlphaMask = ClutFormatToFullAlpha(palFormat); + u32 fullAlphaMask = ClutFormatToFullAlpha(palFormat, reverseColors); switch (palFormat) { case GE_CMODE_16BIT_BGR5650: diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 1c56656e27..7fb47e25ca 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -284,7 +284,7 @@ protected: CheckAlphaResult DecodeTextureLevel(u8 *out, int outPitch, GETextureFormat format, GEPaletteFormat clutformat, uint32_t texaddr, int level, int bufw, bool reverseColors, bool useBGRA, bool expandTo32Bit); void UnswizzleFromMem(u32 *dest, u32 destPitch, const u8 *texptr, u32 bufw, u32 height, u32 bytesPerPixel); - CheckAlphaResult ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, int bufw, bool expandTo32Bit); + CheckAlphaResult ReadIndexedTex(u8 *out, int outPitch, int level, const u8 *texptr, int bytesPerIndex, int bufw, bool reverseColors, bool expandTo32Bit); ReplacedTexture &FindReplacement(TexCacheEntry *entry, int &w, int &h); template