mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-04 10:03:36 +00:00
Fix input texture checksum calculation.
This commit is contained in:
parent
154c06b14f
commit
5efd89ccd2
|
@ -89,7 +89,7 @@ extern const char * strTexrectDrawerFragmentShaderTex;
|
||||||
extern const char * strTexrectDrawerFragmentShaderClean;
|
extern const char * strTexrectDrawerFragmentShaderClean;
|
||||||
extern const char * strTextureCopyShader;
|
extern const char * strTextureCopyShader;
|
||||||
|
|
||||||
class CachedTexture;
|
struct CachedTexture;
|
||||||
class OGLRender
|
class OGLRender
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
112
src/Textures.cpp
112
src/Textures.cpp
|
@ -583,6 +583,7 @@ struct TileSizes
|
||||||
{
|
{
|
||||||
u32 maskWidth, clampWidth, width, realWidth;
|
u32 maskWidth, clampWidth, width, realWidth;
|
||||||
u32 maskHeight, clampHeight, height, realHeight;
|
u32 maskHeight, clampHeight, height, realHeight;
|
||||||
|
u32 bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@ -612,6 +613,7 @@ void _calcTileSizes(u32 _t, TileSizes & _sizes, gDPTile * _pLoadTile)
|
||||||
u32 width, height;
|
u32 width, height;
|
||||||
|
|
||||||
gDPLoadTileInfo &info = gDP.loadInfo[pTile->tmem];
|
gDPLoadTileInfo &info = gDP.loadInfo[pTile->tmem];
|
||||||
|
_sizes.bytes = info.bytes;
|
||||||
if (info.loadType == LOADTYPE_TILE) {
|
if (info.loadType == LOADTYPE_TILE) {
|
||||||
if (pTile->masks && ((maskWidth * maskHeight) <= maxTexels))
|
if (pTile->masks && ((maskWidth * maskHeight) <= maxTexels))
|
||||||
width = maskWidth; // Use mask width if set and valid
|
width = maskWidth; // Use mask width if set and valid
|
||||||
|
@ -1161,37 +1163,25 @@ struct TextureParams
|
||||||
{
|
{
|
||||||
u16 width;
|
u16 width;
|
||||||
u16 height;
|
u16 height;
|
||||||
u16 clampWidth;
|
u16 flags;
|
||||||
u16 clampHeight;
|
|
||||||
u8 maskS;
|
|
||||||
u8 maskT;
|
|
||||||
u8 mirrorS;
|
|
||||||
u8 mirrorT;
|
|
||||||
u8 clampS;
|
|
||||||
u8 clampT;
|
|
||||||
u8 format;
|
|
||||||
u8 size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static
|
static
|
||||||
u32 _calculateCRC(u32 t, const TextureParams & _params)
|
u32 _calculateCRC(u32 _t, const TextureParams & _params, u32 _bytes)
|
||||||
{
|
{
|
||||||
const u32 line = gSP.textureTile[t]->line;
|
const u64 *src = (u64*)&TMEM[gSP.textureTile[_t]->tmem];
|
||||||
const u32 lineBytes = line << 3;
|
|
||||||
|
|
||||||
const u64 *src = (u64*)&TMEM[gSP.textureTile[t]->tmem];
|
|
||||||
u32 crc = 0xFFFFFFFF;
|
u32 crc = 0xFFFFFFFF;
|
||||||
crc = CRC_Calculate(crc, src, _params.height*lineBytes);
|
crc = CRC_Calculate(crc, src, _bytes);
|
||||||
|
|
||||||
if (gSP.textureTile[t]->size == G_IM_SIZ_32b) {
|
if (gSP.textureTile[_t]->size == G_IM_SIZ_32b) {
|
||||||
src = (u64*)&TMEM[gSP.textureTile[t]->tmem + 256];
|
src = (u64*)&TMEM[gSP.textureTile[_t]->tmem + 256];
|
||||||
crc = CRC_Calculate(crc, src, _params.height*lineBytes);
|
crc = CRC_Calculate(crc, src, _bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gDP.otherMode.textureLUT != G_TT_NONE || gSP.textureTile[t]->format == G_IM_FMT_CI) {
|
if (gDP.otherMode.textureLUT != G_TT_NONE || gSP.textureTile[_t]->format == G_IM_FMT_CI) {
|
||||||
if (gSP.textureTile[t]->size == G_IM_SIZ_4b)
|
if (gSP.textureTile[_t]->size == G_IM_SIZ_4b)
|
||||||
crc = CRC_Calculate( crc, &gDP.paletteCRC16[gSP.textureTile[t]->palette], 4 );
|
crc = CRC_Calculate( crc, &gDP.paletteCRC16[gSP.textureTile[_t]->palette], 4 );
|
||||||
else if (gSP.textureTile[t]->size == G_IM_SIZ_8b)
|
else if (gSP.textureTile[_t]->size == G_IM_SIZ_8b)
|
||||||
crc = CRC_Calculate( crc, &gDP.paletteCRC256, 4 );
|
crc = CRC_Calculate( crc, &gDP.paletteCRC256, 4 );
|
||||||
}
|
}
|
||||||
const u8 tlutMode = gDP.otherMode.textureLUT;
|
const u8 tlutMode = gDP.otherMode.textureLUT;
|
||||||
|
@ -1410,16 +1400,16 @@ void TextureCache::update(u32 _t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gDPTile * const pTile = gSP.textureTile[_t];
|
||||||
switch(gSP.textureTile[_t]->textureMode) {
|
switch (pTile->textureMode) {
|
||||||
case TEXTUREMODE_BGIMAGE:
|
case TEXTUREMODE_BGIMAGE:
|
||||||
_updateBackground();
|
_updateBackground();
|
||||||
return;
|
return;
|
||||||
case TEXTUREMODE_FRAMEBUFFER:
|
case TEXTUREMODE_FRAMEBUFFER:
|
||||||
FrameBuffer_ActivateBufferTexture( _t, gSP.textureTile[_t]->frameBuffer );
|
FrameBuffer_ActivateBufferTexture( _t, pTile->frameBuffer );
|
||||||
return;
|
return;
|
||||||
case TEXTUREMODE_FRAMEBUFFER_BG:
|
case TEXTUREMODE_FRAMEBUFFER_BG:
|
||||||
FrameBuffer_ActivateBufferTextureBG( _t, gSP.textureTile[_t]->frameBuffer );
|
FrameBuffer_ActivateBufferTextureBG( _t, pTile->frameBuffer );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1436,27 +1426,19 @@ void TextureCache::update(u32 _t)
|
||||||
gSP.textureTile[0]->tmem == gSP.textureTile[1]->tmem)
|
gSP.textureTile[0]->tmem == gSP.textureTile[1]->tmem)
|
||||||
gSP.textureTile[0] = gSP.textureTile[1];
|
gSP.textureTile[0] = gSP.textureTile[1];
|
||||||
|
|
||||||
|
TextureParams params;
|
||||||
|
params.flags = pTile->masks |
|
||||||
|
(pTile->maskt << 4) |
|
||||||
|
(pTile->mirrors << 8) |
|
||||||
|
(pTile->mirrort << 9) |
|
||||||
|
(pTile->clamps << 10) |
|
||||||
|
(pTile->clampt << 11);
|
||||||
TileSizes sizes;
|
TileSizes sizes;
|
||||||
_calcTileSizes(_t, sizes, gDP.loadTile);
|
_calcTileSizes(_t, sizes, gDP.loadTile);
|
||||||
|
params.width = sizes.realWidth;
|
||||||
|
params.height = sizes.realHeight;
|
||||||
|
|
||||||
u32 crc;
|
const u32 crc = _calculateCRC(_t, params, sizes.bytes);
|
||||||
{
|
|
||||||
TextureParams params;
|
|
||||||
params.width = sizes.width;
|
|
||||||
params.height = sizes.height;
|
|
||||||
params.clampWidth = sizes.clampWidth;
|
|
||||||
params.clampHeight = sizes.clampHeight;
|
|
||||||
params.maskS = gSP.textureTile[_t]->masks;
|
|
||||||
params.maskT = gSP.textureTile[_t]->maskt;
|
|
||||||
params.mirrorS = gSP.textureTile[_t]->mirrors;
|
|
||||||
params.mirrorT = gSP.textureTile[_t]->mirrort;
|
|
||||||
params.clampS = gSP.textureTile[_t]->clamps;
|
|
||||||
params.clampT = gSP.textureTile[_t]->clampt;
|
|
||||||
params.format = gSP.textureTile[_t]->format;
|
|
||||||
params.size = gSP.textureTile[_t]->size;
|
|
||||||
|
|
||||||
crc = _calculateCRC( _t, params );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (current[_t] != nullptr && current[_t]->crc == crc) {
|
if (current[_t] != nullptr && current[_t]->crc == crc) {
|
||||||
activateTexture(_t, current[_t]);
|
activateTexture(_t, current[_t]);
|
||||||
|
@ -1469,18 +1451,10 @@ void TextureCache::update(u32 _t)
|
||||||
CachedTexture & current = *iter;
|
CachedTexture & current = *iter;
|
||||||
m_textures.splice(m_textures.begin(), m_textures, iter);
|
m_textures.splice(m_textures.begin(), m_textures, iter);
|
||||||
|
|
||||||
assert(current.width == sizes.width);
|
assert(current.realWidth == sizes.realWidth);
|
||||||
assert(current.height == sizes.height);
|
assert(current.realHeight == sizes.realHeight);
|
||||||
assert(current.clampWidth == sizes.clampWidth);
|
assert(current.format == pTile->format);
|
||||||
assert(current.clampHeight == sizes.clampHeight);
|
assert(current.size == pTile->size);
|
||||||
assert(current.maskS == gSP.textureTile[_t]->masks);
|
|
||||||
assert(current.maskT == gSP.textureTile[_t]->maskt);
|
|
||||||
assert(current.mirrorS == gSP.textureTile[_t]->mirrors);
|
|
||||||
assert(current.mirrorT == gSP.textureTile[_t]->mirrort);
|
|
||||||
assert(current.clampS == gSP.textureTile[_t]->clamps);
|
|
||||||
assert(current.clampT == gSP.textureTile[_t]->clampt);
|
|
||||||
assert(current.format == gSP.textureTile[_t]->format);
|
|
||||||
assert(current.size == gSP.textureTile[_t]->size);
|
|
||||||
|
|
||||||
activateTexture(_t, ¤t);
|
activateTexture(_t, ¤t);
|
||||||
m_hits++;
|
m_hits++;
|
||||||
|
@ -1495,10 +1469,10 @@ void TextureCache::update(u32 _t)
|
||||||
|
|
||||||
glBindTexture( GL_TEXTURE_2D, pCurrent->glName );
|
glBindTexture( GL_TEXTURE_2D, pCurrent->glName );
|
||||||
|
|
||||||
pCurrent->address = gDP.loadInfo[gSP.textureTile[_t]->tmem].texAddress;
|
pCurrent->address = gDP.loadInfo[pTile->tmem].texAddress;
|
||||||
|
|
||||||
pCurrent->format = gSP.textureTile[_t]->format;
|
pCurrent->format = pTile->format;
|
||||||
pCurrent->size = gSP.textureTile[_t]->size;
|
pCurrent->size = pTile->size;
|
||||||
|
|
||||||
pCurrent->width = sizes.width;
|
pCurrent->width = sizes.width;
|
||||||
pCurrent->height = sizes.height;
|
pCurrent->height = sizes.height;
|
||||||
|
@ -1506,21 +1480,21 @@ void TextureCache::update(u32 _t)
|
||||||
pCurrent->clampWidth = sizes.clampWidth;
|
pCurrent->clampWidth = sizes.clampWidth;
|
||||||
pCurrent->clampHeight = sizes.clampHeight;
|
pCurrent->clampHeight = sizes.clampHeight;
|
||||||
|
|
||||||
pCurrent->palette = gSP.textureTile[_t]->palette;
|
pCurrent->palette = pTile->palette;
|
||||||
/* pCurrent->fulS = gSP.textureTile[t]->fulS;
|
/* pCurrent->fulS = gSP.textureTile[t]->fulS;
|
||||||
pCurrent->fulT = gSP.textureTile[t]->fulT;
|
pCurrent->fulT = gSP.textureTile[t]->fulT;
|
||||||
pCurrent->ulS = gSP.textureTile[t]->ulS;
|
pCurrent->ulS = gSP.textureTile[t]->ulS;
|
||||||
pCurrent->ulT = gSP.textureTile[t]->ulT;
|
pCurrent->ulT = gSP.textureTile[t]->ulT;
|
||||||
pCurrent->lrS = gSP.textureTile[t]->lrS;
|
pCurrent->lrS = gSP.textureTile[t]->lrS;
|
||||||
pCurrent->lrT = gSP.textureTile[t]->lrT;*/
|
pCurrent->lrT = gSP.textureTile[t]->lrT;*/
|
||||||
pCurrent->maskS = gSP.textureTile[_t]->masks;
|
pCurrent->maskS = pTile->masks;
|
||||||
pCurrent->maskT = gSP.textureTile[_t]->maskt;
|
pCurrent->maskT = pTile->maskt;
|
||||||
pCurrent->mirrorS = gSP.textureTile[_t]->mirrors;
|
pCurrent->mirrorS = pTile->mirrors;
|
||||||
pCurrent->mirrorT = gSP.textureTile[_t]->mirrort;
|
pCurrent->mirrorT = pTile->mirrort;
|
||||||
pCurrent->clampS = gSP.textureTile[_t]->clamps;
|
pCurrent->clampS = pTile->clamps;
|
||||||
pCurrent->clampT = gSP.textureTile[_t]->clampt;
|
pCurrent->clampT = pTile->clampt;
|
||||||
pCurrent->line = gSP.textureTile[_t]->line;
|
pCurrent->line = pTile->line;
|
||||||
pCurrent->tMem = gSP.textureTile[_t]->tmem;
|
pCurrent->tMem = pTile->tmem;
|
||||||
pCurrent->lastDList = video().getBuffersSwapCount();
|
pCurrent->lastDList = video().getBuffersSwapCount();
|
||||||
pCurrent->frameBufferTexture = CachedTexture::fbNone;
|
pCurrent->frameBufferTexture = CachedTexture::fbNone;
|
||||||
|
|
||||||
|
|
|
@ -481,7 +481,8 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u32 width = (gDP.loadTile->lrs - gDP.loadTile->uls + 1) & 0x03FF;
|
const u32 width = (gDP.loadTile->lrs - gDP.loadTile->uls + 1) & 0x03FF;
|
||||||
u32 height = (gDP.loadTile->lrt - gDP.loadTile->ult + 1) & 0x03FF;
|
const u32 height = (gDP.loadTile->lrt - gDP.loadTile->ult + 1) & 0x03FF;
|
||||||
|
const u32 bpl = gDP.loadTile->line << 3;
|
||||||
|
|
||||||
gDPLoadTileInfo &info = gDP.loadInfo[gDP.loadTile->tmem];
|
gDPLoadTileInfo &info = gDP.loadInfo[gDP.loadTile->tmem];
|
||||||
info.texAddress = gDP.loadTile->imageAddress;
|
info.texAddress = gDP.loadTile->imageAddress;
|
||||||
|
@ -492,12 +493,12 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt)
|
||||||
info.texWidth = gDP.textureImage.width;
|
info.texWidth = gDP.textureImage.width;
|
||||||
info.size = gDP.textureImage.size;
|
info.size = gDP.textureImage.size;
|
||||||
info.loadType = LOADTYPE_TILE;
|
info.loadType = LOADTYPE_TILE;
|
||||||
|
info.bytes = bpl * height;
|
||||||
|
|
||||||
if (gDP.loadTile->line == 0)
|
if (gDP.loadTile->line == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
u32 address = gDP.textureImage.address + gDP.loadTile->ult * gDP.textureImage.bpl + (gDP.loadTile->uls << gDP.textureImage.size >> 1);
|
u32 address = gDP.textureImage.address + gDP.loadTile->ult * gDP.textureImage.bpl + (gDP.loadTile->uls << gDP.textureImage.size >> 1);
|
||||||
const u32 bpl = gDP.loadTile->line << 3;
|
|
||||||
u32 bpl2 = bpl;
|
u32 bpl2 = bpl;
|
||||||
if (gDP.loadTile->lrs > gDP.textureImage.width)
|
if (gDP.loadTile->lrs > gDP.textureImage.width)
|
||||||
bpl2 = (gDP.textureImage.width - gDP.loadTile->uls);
|
bpl2 = (gDP.textureImage.width - gDP.loadTile->uls);
|
||||||
|
@ -610,6 +611,8 @@ void gDPLoadBlock(u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt)
|
||||||
u32 bytes = (lrs - uls + 1) << gDP.loadTile->size >> 1;
|
u32 bytes = (lrs - uls + 1) << gDP.loadTile->size >> 1;
|
||||||
if ((bytes & 7) != 0)
|
if ((bytes & 7) != 0)
|
||||||
bytes = (bytes & (~7)) + 8;
|
bytes = (bytes & (~7)) + 8;
|
||||||
|
|
||||||
|
info.bytes = bytes;
|
||||||
u32 address = gDP.textureImage.address + ult * gDP.textureImage.bpl + (uls << gDP.textureImage.size >> 1);
|
u32 address = gDP.textureImage.address + ult * gDP.textureImage.bpl + (uls << gDP.textureImage.size >> 1);
|
||||||
|
|
||||||
if (bytes == 0 || (address + bytes) > RDRAMSize) {
|
if (bytes == 0 || (address + bytes) > RDRAMSize) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user