Centralize CLUT handling form gstate values.

This commit is contained in:
Unknown W. Brackets 2013-08-24 11:10:56 -07:00
parent 7f6cf3ec29
commit 5ab04a3076
5 changed files with 18 additions and 29 deletions

View File

@ -254,13 +254,6 @@ void TextureCache::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffe
}
}
static u32 GetClutIndex(u32 index) {
const u32 clutBase = gstate.getClutIndexStartPos();
const u32 clutMask = gstate.getClutIndexMask();
const u8 clutShift = gstate.getClutIndexShift();
return ((index >> clutShift) & clutMask) | clutBase;
}
void *TextureCache::UnswizzleFromMem(u32 texaddr, u32 bufw, u32 bytesPerPixel, u32 level) {
const u32 rowWidth = (bytesPerPixel > 0) ? (bufw * bytesPerPixel) : (bufw / 2);
const u32 pitch = rowWidth / 4;
@ -346,7 +339,7 @@ inline void DeIndexTexture(ClutT *dest, const IndexT *indexed, int length, const
}
} else {
for (int i = 0; i < length; ++i) {
*dest++ = clut[GetClutIndex(*indexed++)];
*dest++ = clut[gstate.transformClutIndex(*indexed++)];
}
}
}
@ -371,8 +364,8 @@ inline void DeIndexTexture4(ClutT *dest, const u8 *indexed, int length, const Cl
} else {
for (int i = 0; i < length; i += 2) {
u8 index = *indexed++;
dest[i + 0] = clut[GetClutIndex((index >> 0) & 0xf)];
dest[i + 1] = clut[GetClutIndex((index >> 4) & 0xf)];
dest[i + 0] = clut[gstate.transformClutIndex((index >> 0) & 0xf)];
dest[i + 1] = clut[gstate.transformClutIndex((index >> 4) & 0xf)];
}
}
}
@ -873,8 +866,8 @@ inline bool TextureCache::TexCacheEntry::Matches(u16 dim2, u8 format2, int maxLe
}
void TextureCache::LoadClut() {
u32 clutAddr = ((gstate.clutaddr & 0xFFFFFF) | ((gstate.clutaddrupper << 8) & 0x0F000000));
clutTotalBytes_ = (gstate.loadclut & 0x3f) * 32;
u32 clutAddr = gstate.getClutAddress();
clutTotalBytes_ = gstate.getClutLoadBytes();
if (Memory::IsValidAddress(clutAddr)) {
Memory::MemcpyUnchecked(clutBufRaw_, clutAddr, clutTotalBytes_);
} else {

View File

@ -284,10 +284,13 @@ struct GPUgstate
int getTextureEnvColR() const { return texenvcolor&0xFF; }
int getTextureEnvColG() const { return (texenvcolor>>8)&0xFF; }
int getTextureEnvColB() const { return (texenvcolor>>16)&0xFF; }
u32 getClutAddress() const { return (clutaddr & 0x00FFFFFF) | ((clutaddrupper << 8) & 0x0F000000); }
int getClutLoadBytes() const { return (loadclut & 0x3F) * 32; }
GEPaletteFormat getClutPaletteFormat() { return static_cast<GEPaletteFormat>(clutformat & 3); }
int getClutIndexShift() const { return (clutformat >> 2) & 0x1F; }
int getClutIndexMask() const { return (clutformat >> 8) & 0xFF; }
int getClutIndexStartPos() const { return ((clutformat >> 16) & 0x1F) << 4; }
int transformClutIndex(int index) const { return ((index >> getClutIndexShift()) & getClutIndexMask()) | getClutIndexStartPos(); }
bool isClutIndexSimple() const { return (clutformat & ~3) == 0xC500FF00; } // Meaning, no special mask, shift, or start pos.
bool isTextureSwizzled() const { return texmode & 1; }

View File

@ -265,7 +265,7 @@ void NullGPU::ExecuteOp(u32 op, u32 diff)
case GE_CMD_LOADCLUT:
// This could be used to "dirty" textures with clut.
{
u32 clutAddr = ((gstate.clutaddrupper & 0xFF0000)<<8) | (gstate.clutaddr & 0xFFFFFF);
u32 clutAddr = gstate.getClutAddress();
if (clutAddr)
{
DEBUG_LOG(G3D,"DL Clut load: %08x", clutAddr);

View File

@ -90,13 +90,6 @@ static inline u32 LookupColor(unsigned int index, unsigned int level)
}
}
static inline u32 GetClutIndex(u32 index) {
const u32 clutBase = gstate.getClutIndexStartPos();
const u32 clutMask = gstate.getClutIndexMask();
const u8 clutShift = gstate.getClutIndexShift();
return ((index >> clutShift) & clutMask) | clutBase;
}
static inline void GetTexelCoordinates(int level, float s, float t, unsigned int& u, unsigned int& v)
{
s *= getFloat24(gstate.texscaleu);
@ -185,25 +178,25 @@ static inline u32 SampleNearest(int level, unsigned int u, unsigned int v)
u32 val = srcptr[0] + (srcptr[1] << 8) + (srcptr[2] << 16) + (srcptr[3] << 24);
return LookupColor(GetClutIndex(val), level);
return LookupColor(gstate.transformClutIndex(val), level);
} else if (texfmt == GE_TFMT_CLUT16) {
srcptr += GetPixelDataOffset(16, texbufwidth*8, u, v);
u16 val = srcptr[0] + (srcptr[1] << 8);
return LookupColor(GetClutIndex(val), level);
return LookupColor(gstate.transformClutIndex(val), level);
} else if (texfmt == GE_TFMT_CLUT8) {
srcptr += GetPixelDataOffset(8, texbufwidth*8, u, v);
u8 val = *srcptr;
return LookupColor(GetClutIndex(val), level);
return LookupColor(gstate.transformClutIndex(val), level);
} else if (texfmt == GE_TFMT_CLUT4) {
srcptr += GetPixelDataOffset(4, texbufwidth*8, u, v);
u8 val = (u & 1) ? (srcptr[0] >> 4) : (srcptr[0] & 0xF);
return LookupColor(GetClutIndex(val), level);
return LookupColor(gstate.transformClutIndex(val), level);
} else {
ERROR_LOG(G3D, "Unsupported texture format: %x", texfmt);
return 0;
@ -404,7 +397,7 @@ static inline Vec4<int> GetTextureFunctionOutput(const Vec3<int>& prim_color_rgb
Vec3<int> out_rgb;
int out_a;
bool rgba = (gstate.texfunc & 0x100) != 0;
bool rgba = gstate.isTextureAlphaUsed();
switch (gstate.getTextureFunction()) {
case GE_TEXFUNC_MODULATE:

View File

@ -528,14 +528,14 @@ void SoftGPU::ExecuteOp(u32 op, u32 diff)
case GE_CMD_LOADCLUT:
{
u32 clutAddr = ((gstate.clutaddr & 0xFFFFF0) | ((gstate.clutaddrupper << 8) & 0xFF000000));
u32 clutTotalBytes_ = (gstate.loadclut & 0x3f) * 32;
u32 clutAddr = gstate.getClutAddress();
u32 clutTotalBytes = gstate.getClutLoadBytes();
if (Memory::IsValidAddress(clutAddr)) {
Memory::Memcpy(clut, clutAddr, clutTotalBytes_);
Memory::MemcpyUnchecked(clut, clutAddr, clutTotalBytes);
} else {
// TODO: Does this make any sense?
memset(clut, 0xFF, clutTotalBytes_);
memset(clut, 0xFF, clutTotalBytes);
}
if (clutAddr)