summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software/Tev.cpp
diff options
context:
space:
mode:
authorPokechu22 <Pokechu022@gmail.com>2021-04-08 18:10:13 -0700
committerPokechu22 <Pokechu022@gmail.com>2021-05-07 16:28:09 -0700
commit16c17ed9cead8f2cafd5d027d5f4957cd906246c (patch)
treefd9ab32ad96e862244a695f799d8d595c36ae831 /Source/Core/VideoBackends/Software/Tev.cpp
parentf6cf85a8bca13d3e8a075f2f823a142b7b9d115d (diff)
Software: Fix OOB tex coord indices
Previously we set the texture coordinate to zero, now we set the texture coordinate *index* to zero. This fixes the ripple effect of the Mario painting in Luigi's Mansion.
Diffstat (limited to 'Source/Core/VideoBackends/Software/Tev.cpp')
-rw-r--r--Source/Core/VideoBackends/Software/Tev.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/Source/Core/VideoBackends/Software/Tev.cpp b/Source/Core/VideoBackends/Software/Tev.cpp
index 30258f6cd3..be6f14d610 100644
--- a/Source/Core/VideoBackends/Software/Tev.cpp
+++ b/Source/Core/VideoBackends/Software/Tev.cpp
@@ -6,6 +6,7 @@
#include <algorithm>
#include <cmath>
+#include <cstring>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
@@ -559,9 +560,16 @@ void Tev::Draw()
const int stageNum2 = stageNum >> 1;
const int stageOdd = stageNum & 1;
- const u32 texcoordSel = bpmem.tevindref.getTexCoord(stageNum);
+ u32 texcoordSel = bpmem.tevindref.getTexCoord(stageNum);
const u32 texmap = bpmem.tevindref.getTexMap(stageNum);
+ // Quirk: when the tex coord is not less than the number of tex gens (i.e. the tex coord does
+ // not exist), then tex coord 0 is used (though sometimes glitchy effects happen on console).
+ // This affects the Mario portrait in Luigi's Mansion, where the developers forgot to set
+ // the number of tex gens to 2 (bug 11462).
+ if (texcoordSel >= bpmem.genMode.numtexgens)
+ texcoordSel = 0;
+
const TEXSCALE& texscale = bpmem.texscale[stageNum2];
const s32 scaleS = stageOdd ? texscale.ss1 : texscale.ss0;
const s32 scaleT = stageOdd ? texscale.ts1 : texscale.ts0;
@@ -592,8 +600,13 @@ void Tev::Draw()
const TevStageCombiner::ColorCombiner& cc = bpmem.combiners[stageNum].colorC;
const TevStageCombiner::AlphaCombiner& ac = bpmem.combiners[stageNum].alphaC;
- const int texcoordSel = order.getTexCoord(stageOdd);
- const int texmap = order.getTexMap(stageOdd);
+ u32 texcoordSel = order.getTexCoord(stageOdd);
+ const u32 texmap = order.getTexMap(stageOdd);
+
+ // Quirk: when the tex coord is not less than the number of tex gens (i.e. the tex coord does
+ // not exist), then tex coord 0 is used (though sometimes glitchy effects happen on console).
+ if (texcoordSel >= bpmem.genMode.numtexgens)
+ texcoordSel = 0;
Indirect(stageNum, Uv[texcoordSel].s, Uv[texcoordSel].t);
@@ -603,8 +616,17 @@ void Tev::Draw()
// RGBA
u8 texel[4];
- TextureSampler::Sample(TexCoord.s, TexCoord.t, TextureLod[stageNum], TextureLinear[stageNum],
- texmap, texel);
+ if (bpmem.genMode.numtexgens > 0)
+ {
+ TextureSampler::Sample(TexCoord.s, TexCoord.t, TextureLod[stageNum],
+ TextureLinear[stageNum], texmap, texel);
+ }
+ else
+ {
+ // It seems like the result is always black when no tex coords are enabled, but further
+ // hardware testing is needed.
+ std::memset(texel, 0, 4);
+ }
#if ALLOW_TEV_DUMPS
if (g_ActiveConfig.bDumpTevTextureFetches)