1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Fix for texture issues in Stunt Racer, reported by DonelBueno in #1885

Stunt Racer uses combiner with two textures for track polygons, but actually loads only T0.
T1 replaced by T0 because of LOD flags in othermode.
This situation was not checked in the main code and ClampWrapMirror shader got wrong parameters,
which lead to the glitches.
This commit is contained in:
Sergey Lipskiy 2019-08-16 18:44:49 +07:00
parent 947fedcbb5
commit c28ea61b8f
4 changed files with 15 additions and 5 deletions

View File

@ -926,12 +926,14 @@ public:
std::array<f32, 2> aTexMirror[2] = { { 0.0f, 0.0f}, { 0.0f, 0.0f } };
std::array<f32, 2> aTexScale[2] = { { 1.0f, 1.0f },{ 1.0f, 1.0f } };
TextureCache & cache = textureCache();
const bool replaceTex1ByTex0 = needReplaceTex1ByTex0();
for (u32 t = 0; t < 2; ++t) {
if (!m_useTile[t])
continue;
const gDPTile * pTile = gSP.textureTile[t];
CachedTexture * pTexture = cache.current[t];
const u32 tile = replaceTex1ByTex0 ? 0 : t;
const gDPTile * pTile = gSP.textureTile[tile];
CachedTexture * pTexture = cache.current[tile];
if (pTile == nullptr || pTexture == nullptr)
continue;

View File

@ -1448,7 +1448,7 @@ void TextureCache::update(u32 _t)
return;
}
if (gDP.otherMode.textureLOD == G_TL_LOD && gSP.texture.level == 0 && !currentCombiner()->usesLOD() && _t == 1) {
if (_t == 1 && needReplaceTex1ByTex0()) {
current[1] = current[0];
if (current[1] != nullptr) {
activateTexture(1, current[1]);
@ -1573,3 +1573,8 @@ void getTextureShiftScale(u32 t, const TextureCache & cache, f32 & shiftScaleS,
else if (gSP.textureTile[t]->shiftt > 0)
shiftScaleT /= (f32)(1 << gSP.textureTile[t]->shiftt);
}
bool needReplaceTex1ByTex0()
{
return gSP.texture.level == 0 && gDP.otherMode.textureLOD == G_TL_LOD && gDP.otherMode.textureDetail == G_TD_CLAMP;
}

View File

@ -109,6 +109,9 @@ private:
void getTextureShiftScale(u32 tile, const TextureCache & cache, f32 & shiftScaleS, f32 & shiftScaleT);
// Check for situation when Tex0 is used instead of Tex1
bool needReplaceTex1ByTex0();
inline TextureCache & textureCache()
{
return TextureCache::get();

View File

@ -854,7 +854,7 @@ void gDPTextureRectangle(f32 ulx, f32 uly, f32 lrx, f32 lry, s32 tile, s16 s, s1
textureTileOrg[0] = gSP.textureTile[0];
textureTileOrg[1] = gSP.textureTile[1];
gSP.textureTile[0] = &gDP.tiles[tile];
gSP.textureTile[1] = &gDP.tiles[(tile + 1) & 7];
gSP.textureTile[1] = needReplaceTex1ByTex0() ? &gDP.tiles[tile] : &gDP.tiles[(tile + 1) & 7];
// HACK ALERT!
if (s == 0x4000 && (gDP.colorImage.width + gSP.textureTile[0]->uls < 512))
@ -953,7 +953,7 @@ void gDPLLETriangle(u32 _w1, u32 _w2, int _shade, int _texture, int _zbuffer, u3
textureTileOrg[0] = gSP.textureTile[0];
textureTileOrg[1] = gSP.textureTile[1];
gSP.textureTile[0] = &gDP.tiles[tile];
gSP.textureTile[1] = &gDP.tiles[(tile + 1) & 7];
gSP.textureTile[1] = needReplaceTex1ByTex0() ? &gDP.tiles[tile] : &gDP.tiles[(tile + 1) & 7];
int j;
int xleft, xright, xleft_inc, xright_inc;