diff --git a/Combiner.cpp b/Combiner.cpp index 396a23a6..1983e8ae 100644 --- a/Combiner.cpp +++ b/Combiner.cpp @@ -457,13 +457,6 @@ DWORD64 Combiner_EncodeCombineMode( WORD saRGB0, WORD sbRGB0, WORD mRGB0, WORD a void Combiner_SelectCombine( u64 mux ) { - // Hack for the Banjo-Tooie shadow (framebuffer textures must be enabled too) - if ((gDP.otherMode.cycleType == G_CYC_1CYCLE) && (mux == 0x00ffe7ffffcf9fcf) && (cache.current[0]->frameBufferTexture)) - { - mux = EncodeCombineMode( 0, 0, 0, 0, TEXEL0, 0, PRIMITIVE, 0, - 0, 0, 0, 0, TEXEL0, 0, PRIMITIVE, 0 ); - } - CachedCombiner *current = combiner.root; CachedCombiner *parent = current; diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index d56d6e2c..e86a09e2 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -504,9 +504,9 @@ void FrameBuffer_ActivateBufferTexture( s16 t, FrameBuffer *buffer ) else buffer->texture->shiftScaleT = 1.0f; - const u32 shift = gDP.textureImage.address - buffer->startAddress; + const u32 shift = gSP.textureTile[t]->imageAddress - buffer->startAddress; const u32 factor = buffer->width << buffer->size >> 1; - if (gDP.loadType == LOADTYPE_TILE) + if (gSP.textureTile[t]->loadType == LOADTYPE_TILE) { buffer->texture->offsetS = gDP.loadTile->uls; buffer->texture->offsetT = (float)(buffer->height - (gDP.loadTile->ult + shift/factor)); diff --git a/Textures.cpp b/Textures.cpp index 0b657232..cb684170 100644 --- a/Textures.cpp +++ b/Textures.cpp @@ -863,15 +863,15 @@ void TextureCache_Update( u32 t ) TextureCache_Init(); } - switch(gDP.textureMode) { + switch(gSP.textureTile[t]->textureMode) { case TEXTUREMODE_BGIMAGE: TextureCache_UpdateBackground(); return; case TEXTUREMODE_FRAMEBUFFER: - FrameBuffer_ActivateBufferTexture( t, gDP.loadTile->frameBuffer ); + FrameBuffer_ActivateBufferTexture( t, gSP.textureTile[t]->frameBuffer ); return; case TEXTUREMODE_FRAMEBUFFER_BG: - FrameBuffer_ActivateBufferTextureBG( t, gDP.loadTile->frameBuffer ); + FrameBuffer_ActivateBufferTextureBG( t, gSP.textureTile[t]->frameBuffer ); return; } @@ -894,7 +894,7 @@ void TextureCache_Update( u32 t ) else lineHeight = 0; - if (gDP.textureMode == TEXTUREMODE_TEXRECT) + if (gSP.textureTile[t]->textureMode == TEXTUREMODE_TEXRECT) { u16 texRectWidth = gDP.texRect.width - gSP.textureTile[t]->uls; u16 texRectHeight = gDP.texRect.height - gSP.textureTile[t]->ult; @@ -912,7 +912,7 @@ void TextureCache_Update( u32 t ) width = gDP.texRect.width; else if ((texRectWidth * texRectHeight) <= maxTexels) width = gDP.texRect.width; - else if (gDP.loadType == LOADTYPE_TILE) + else if (gSP.textureTile[t]->loadType == LOADTYPE_TILE) width = loadWidth; else width = lineWidth; @@ -930,7 +930,7 @@ void TextureCache_Update( u32 t ) height = tileHeight; else if ((texRectWidth * texRectHeight) <= maxTexels) height = gDP.texRect.height; - else if (gDP.loadType == LOADTYPE_TILE) + else if (gSP.textureTile[t]->loadType == LOADTYPE_TILE) height = loadHeight; else height = lineHeight; @@ -944,7 +944,7 @@ void TextureCache_Update( u32 t ) width = maskWidth; // Use mask width if set and valid else if ((tileWidth * tileHeight) <= maxTexels) width = tileWidth; // else use tile width if valid - else if (gDP.loadType == LOADTYPE_TILE) + else if (gSP.textureTile[t]->loadType == LOADTYPE_TILE) width = loadWidth; // else use load width if load done with LoadTile else width = lineWidth; // else use line-based width @@ -953,7 +953,7 @@ void TextureCache_Update( u32 t ) height = maskHeight; else if ((tileWidth * tileHeight) <= maxTexels) height = tileHeight; - else if (gDP.loadType == LOADTYPE_TILE) + else if (gSP.textureTile[t]->loadType == LOADTYPE_TILE) height = loadHeight; else height = lineHeight; diff --git a/gDP.cpp b/gDP.cpp index 8ed50d92..4b4b490c 100644 --- a/gDP.cpp +++ b/gDP.cpp @@ -1,3 +1,4 @@ +#include #include "GLideN64.h" #include "N64.h" #include "GBI.h" @@ -523,6 +524,18 @@ void gDPSetTile( u32 format, u32 size, u32 line, u32 tmem, u32 tile, u32 palette if (!gDP.tiles[tile].masks) gDP.tiles[tile].clamps = 1; if (!gDP.tiles[tile].maskt) gDP.tiles[tile].clampt = 1; + if (tile == gSP.texture.tile || gSP.texture.tile + 1) { + u32 nTile = 7; + while(gDP.tiles[nTile].tmem != tmem && nTile > gSP.texture.tile + 1) + --nTile; + if (nTile > gSP.texture.tile + 1) { + gDP.tiles[tile].textureMode = gDP.tiles[nTile].textureMode; + gDP.tiles[tile].loadType = gDP.tiles[nTile].loadType; + gDP.tiles[tile].frameBuffer = gDP.tiles[nTile].frameBuffer; + gDP.tiles[tile].imageAddress = gDP.tiles[nTile].imageAddress; + } + } + #ifdef DEBUG DebugMsg( DEBUG_HIGH | DEBUG_HANDLED | DEBUG_TEXTURE, "gDPSetTile( %s, %s, %i, %i, %i, %i, %s%s, %s%s, %i, %i, %i, %i );\n", ImageFormatText[format], @@ -567,6 +580,37 @@ void gDPSetTileSize( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt ) #endif } +static +bool CheckForFrameBufferTexture(u32 _address) +{ + if (OGL.frameBufferTextures) { + FrameBuffer *pBuffer = FrameBuffer_FindBuffer( _address ); + if ((pBuffer != NULL) && + ((*(u32*)&RDRAM[pBuffer->startAddress] & 0xFFFEFFFE) == (pBuffer->startAddress & 0xFFFEFFFE))) + { + gDP.loadTile->frameBuffer = pBuffer; + gDP.loadTile->textureMode = TEXTUREMODE_FRAMEBUFFER; + gDP.changed |= CHANGED_TMEM; + + u32 nTile = 8;; + if (gDP.tiles[gSP.texture.tile].tmem == gDP.loadTile->tmem) + nTile = gSP.texture.tile; + else if (gDP.tiles[gSP.texture.tile + 1].tmem == gDP.loadTile->tmem) + nTile = gSP.texture.tile + 1; + if (nTile < 8) { + gDPTile & curTile = gDP.tiles[nTile]; + curTile.textureMode = gDP.loadTile->textureMode; + curTile.loadType = gDP.loadTile->loadType; + curTile.frameBuffer = gDP.loadTile->frameBuffer; + curTile.imageAddress = gDP.loadTile->imageAddress; + } + + return true; + } + } + return false; +} + void gDPLoadTile( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt ) { void (*Interleave)( void *mem, u32 numDWords ); @@ -577,6 +621,8 @@ void gDPLoadTile( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt ) gDPSetTileSize( tile, uls, ult, lrs, lrt ); gDP.loadTile = &gDP.tiles[tile]; + gDP.loadTile->loadType = LOADTYPE_TILE; + gDP.loadTile->imageAddress = gDP.textureImage.address; if (gDP.loadTile->line == 0) return; @@ -598,19 +644,8 @@ void gDPLoadTile( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt ) return; } - if (OGL.frameBufferTextures) - { - FrameBuffer *buffer; - if (((buffer = FrameBuffer_FindBuffer( address )) != NULL) && - ((*(u32*)&RDRAM[buffer->startAddress] & 0xFFFEFFFE) == (buffer->startAddress & 0xFFFEFFFE))) - { - gDP.loadTile->frameBuffer = buffer; - gDP.textureMode = TEXTUREMODE_FRAMEBUFFER; - gDP.loadType = LOADTYPE_TILE; - gDP.changed |= CHANGED_TMEM; - return; - } - } + if (CheckForFrameBufferTexture(address)) + return; // Line given for 32-bit is half what it seems it should since they split the // high and low words. I'm cheating by putting them together. @@ -634,8 +669,8 @@ void gDPLoadTile( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt ) dest += line; } - gDP.textureMode = TEXTUREMODE_NORMAL; - gDP.loadType = LOADTYPE_TILE; + gDP.loadTile->textureMode = TEXTUREMODE_NORMAL; + gDP.loadTile->frameBuffer = NULL; gDP.changed |= CHANGED_TMEM; #ifdef DEBUG @@ -648,6 +683,8 @@ void gDPLoadBlock( u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt ) { gDPSetTileSize( tile, uls, ult, lrs, dxt ); gDP.loadTile = &gDP.tiles[tile]; + gDP.loadTile->loadType = LOADTYPE_BLOCK; + gDP.loadTile->imageAddress = gDP.textureImage.address; u32 bytes = (lrs + 1) << gDP.loadTile->size >> 1; u32 address = gDP.textureImage.address + ult * gDP.textureImage.bpl + (uls << gDP.textureImage.size >> 1); @@ -665,19 +702,8 @@ void gDPLoadBlock( u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt ) return; } - if (OGL.frameBufferTextures) - { - FrameBuffer *buffer; - if (((buffer = FrameBuffer_FindBuffer( address )) != NULL) && - ((*(u32*)&RDRAM[buffer->startAddress] & 0xFFFEFFFE) == (buffer->startAddress & 0xFFFEFFFE))) - { - gDP.loadTile->frameBuffer = buffer; - gDP.textureMode = TEXTUREMODE_FRAMEBUFFER; - gDP.loadType = LOADTYPE_BLOCK; - gDP.changed |= CHANGED_TMEM; - return; - } - } + if (CheckForFrameBufferTexture(address)) + return; u64* src = (u64*)&RDRAM[address]; u64* dest = &TMEM[gDP.loadTile->tmem]; @@ -707,8 +733,8 @@ void gDPLoadBlock( u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt ) else UnswapCopy( src, dest, bytes ); - gDP.textureMode = TEXTUREMODE_NORMAL; - gDP.loadType = LOADTYPE_BLOCK; + gDP.loadTile->textureMode = TEXTUREMODE_NORMAL; + gDP.loadTile->frameBuffer = NULL; gDP.changed |= CHANGED_TMEM; #ifdef DEBUG @@ -856,6 +882,11 @@ void gDPTextureRectangle( f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, f32 s, f gSP.textureTile[0] = &gDP.tiles[tile]; gSP.textureTile[1] = &gDP.tiles[tile < 7 ? tile + 1 : tile]; + if (gSP.textureTile[0]->textureMode == TEXTUREMODE_NORMAL) + gSP.textureTile[0]->textureMode = TEXTUREMODE_TEXRECT; + if (gSP.textureTile[1]->textureMode == TEXTUREMODE_NORMAL) + gSP.textureTile[1]->textureMode = TEXTUREMODE_TEXRECT; + // HACK ALERT! if ((int(s) == 512) && (gDP.colorImage.width < 512)) s = 0.0f; @@ -863,9 +894,6 @@ void gDPTextureRectangle( f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, f32 s, f f32 lrs = s + (lrx - ulx - 1) * dsdx; f32 lrt = t + (lry - uly - 1) * dtdy; - if (gDP.textureMode == TEXTUREMODE_NORMAL) - gDP.textureMode = TEXTUREMODE_TEXRECT; - gDP.texRect.width = (u32)(max( lrs, s ) + dsdx); gDP.texRect.height = (u32)(max( lrt, t ) + dtdy); diff --git a/gDP.h b/gDP.h index 6bc57dac..d2be44d8 100644 --- a/gDP.h +++ b/gDP.h @@ -82,11 +82,15 @@ struct gDPTile }; }; - FrameBuffer *frameBuffer; u32 maskt, masks; u32 shiftt, shifts; f32 fuls, fult, flrs, flrt; u32 uls, ult, lrs, lrt; + + u32 textureMode; + u32 loadType; + u32 imageAddress; + FrameBuffer *frameBuffer; }; struct gDPInfo @@ -228,8 +232,6 @@ struct gDPInfo u32 paletteCRC16[16]; u32 paletteCRC256; u32 half_1, half_2; - u32 textureMode; - u32 loadType; }; extern gDPInfo gDP; diff --git a/gSP.cpp b/gSP.cpp index 4388ea2c..d7fe2b86 100644 --- a/gSP.cpp +++ b/gSP.cpp @@ -1451,7 +1451,7 @@ void loadBGImage(const uObjScaleBg * _bgInfo, bool _loadScale) gSP.bgImage.format = _bgInfo->imageFmt; gSP.bgImage.size = _bgInfo->imageSiz; gSP.bgImage.palette = _bgInfo->imagePal; - gDP.textureMode = TEXTUREMODE_BGIMAGE; + gDP.tiles[0].textureMode = TEXTUREMODE_BGIMAGE; gSP.bgImage.imageX = _FIXED2FLOAT( _bgInfo->imageX, 5 ); gSP.bgImage.imageY = _FIXED2FLOAT( _bgInfo->imageY, 5 ); if (_loadScale) { @@ -1466,9 +1466,9 @@ void loadBGImage(const uObjScaleBg * _bgInfo, bool _loadScale) if (((buffer = FrameBuffer_FindBuffer( gSP.bgImage.address )) != NULL) && ((*(u32*)&RDRAM[buffer->startAddress] & 0xFFFEFFFE) == (buffer->startAddress & 0xFFFEFFFE))) { - gDP.loadTile->frameBuffer = buffer; - gDP.textureMode = TEXTUREMODE_FRAMEBUFFER_BG; - gDP.loadType = LOADTYPE_TILE; + gDP.tiles[0].frameBuffer = buffer; + gDP.tiles[0].textureMode = TEXTUREMODE_FRAMEBUFFER_BG; + gDP.tiles[0].loadType = LOADTYPE_TILE; gDP.changed |= CHANGED_TMEM; } }