Skip to content

Commit

Permalink
Correct CheckAlpha() for un-rearranged textures.
Browse files Browse the repository at this point in the history
Fixes hrydgard#4403.  It was just not seeing the alpha when a texture had a large
bufw and a small w, and transparent only near the bottom - as in FF1's case.
  • Loading branch information
unknownbrackets committed Jan 27, 2014
1 parent cc48822 commit b626dac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
45 changes: 27 additions & 18 deletions GPU/GLES/TextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
ERROR_LOG_REPORT(G3D, "NO finalbuf! Will crash!");
}

if ((g_Config.iTexScalingLevel != 1 || !gl_extensions.EXT_unpack_subimage) && w != bufw) {
if (!(g_Config.iTexScalingLevel == 1 && gl_extensions.EXT_unpack_subimage) && w != bufw) {
int pixelSize;
switch (dstFmt) {
case GL_UNSIGNED_SHORT_4_4_4_4:
Expand Down Expand Up @@ -1447,7 +1447,7 @@ void *TextureCache::DecodeTextureLevel(GETextureFormat format, GEPaletteFormat c
return finalBuf;
}

void TextureCache::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFmt, int w, int h) {
void TextureCache::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFmt, int stride, int w, int h) {
// TODO: Could probably be optimized more.
u32 hitZeroAlpha = 0;
u32 hitSomeAlpha = 0;
Expand All @@ -1456,22 +1456,28 @@ void TextureCache::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFm
case GL_UNSIGNED_SHORT_4_4_4_4:
{
const u32 *p = pixelData;
for (int i = 0; i < (w * h + 1) / 2; ++i) {
u32 a = p[i] & 0x000F000F;
hitZeroAlpha |= a ^ 0x000F000F;
if (a != 0x000F000F && a != 0x0000000F && a != 0x000F0000 && a != 0) {
hitSomeAlpha = 1;
break;
for (int y = 0; y < h && hitSomeAlpha == 0; ++y) {
for (int i = 0; i < (w + 1) / 2; ++i) {
u32 a = p[i] & 0x000F000F;
hitZeroAlpha |= a ^ 0x000F000F;
if (a != 0x000F000F && a != 0x0000000F && a != 0x000F0000 && a != 0) {
hitSomeAlpha = 1;
break;
}
}
p += stride;
}
}
break;
case GL_UNSIGNED_SHORT_5_5_5_1:
{
const u32 *p = pixelData;
for (int i = 0; i < (w * h + 1) / 2; ++i) {
u32 a = p[i] & 0x00010001;
hitZeroAlpha |= a ^ 0x00010001;
for (int y = 0; y < h; ++y) {
for (int i = 0; i < (w + 1) / 2; ++i) {
u32 a = p[i] & 0x00010001;
hitZeroAlpha |= a ^ 0x00010001;
}
p += stride;
}
}
break;
Expand All @@ -1483,13 +1489,16 @@ void TextureCache::CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFm
default:
{
const u32 *p = pixelData;
for (int i = 0; i < w * h; ++i) {
u32 a = p[i] & 0xFF000000;
hitZeroAlpha |= a ^ 0xFF000000;
if (a != 0xFF000000 && a != 0) {
hitSomeAlpha = 1;
break;
for (int y = 0; y < h && hitSomeAlpha == 0; ++y) {
for (int i = 0; i < w; ++i) {
u32 a = p[i] & 0xFF000000;
hitZeroAlpha |= a ^ 0xFF000000;
if (a != 0xFF000000 && a != 0) {
hitSomeAlpha = 1;
break;
}
}
p += stride;
}
}
break;
Expand Down Expand Up @@ -1554,7 +1563,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, int level, bool replac
scaler.Scale(pixelData, dstFmt, w, h, scaleFactor);

if ((entry.status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0)
CheckAlpha(entry, pixelData, dstFmt, w, h);
CheckAlpha(entry, pixelData, dstFmt, useUnpack ? bufw : w, w, h);
else
entry.status |= TexCacheEntry::STATUS_ALPHA_UNKNOWN;

Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/TextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class TextureCache {
void LoadTextureLevel(TexCacheEntry &entry, int level, bool replaceImages, GLenum dstFmt);
GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
void *DecodeTextureLevel(GETextureFormat format, GEPaletteFormat clutformat, int level, u32 &texByteAlign, GLenum dstFmt, int *bufw = 0);
void CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFmt, int w, int h);
void CheckAlpha(TexCacheEntry &entry, u32 *pixelData, GLenum dstFmt, int stride, int w, int h);
template <typename T>
const T *GetCurrentClut();
u32 GetCurrentClutHash();
Expand Down

0 comments on commit b626dac

Please sign in to comment.