Skip to content

Commit

Permalink
Check small triangle draws in through-mode for pixel mapping too
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 11, 2024
1 parent 09d8bc5 commit 8de7a97
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions GPU/Common/SoftwareTransformCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,35 @@ void SoftwareTransform::BuildDrawingParams(int prim, int vertexCount, u32 vertTy

inds = newInds;
}
} else if (throughmode) {
// We check some common cases for pixel mapping.
// TODO: It's not really optimal that some previous step has removed the triangle strip.
if (vertexCount <= 6 && prim == GE_PRIM_TRIANGLES) {
// It's enough to check UV deltas vs pos deltas between vertex pairs:
// 0-1 1-3 3-2 2-0. Maybe can even skip the last one. Probably some simple math can get us that sequence.
// Unfortunately we need to reverse the previous UV scaling operation. Fortunately these are powers of two
// so the operations are exact.
bool pmapped = true;
const u16 *indsIn = (const u16 *)inds;
for (int t = 0; t < vertexCount; t += 3) {
float uscale = gstate_c.curTextureWidth;
float vscale = gstate_c.curTextureHeight;
struct { int a; int b; } pairs[] = { {0, 1}, {1, 2}, {2, 0} };

for (int i = 0; i < ARRAY_SIZE(pairs); i++) {
int a = indsIn[t + pairs[i].a];
int b = indsIn[t + pairs[i].b];
float du = fabsf((transformed[a].u - transformed[b].u) * uscale);
float dv = fabsf((transformed[a].v - transformed[b].v) * vscale);
float dx = fabsf(transformed[a].x - transformed[b].x);
float dy = fabsf(transformed[a].y - transformed[b].y);
if (du != dx || dv != dy) {
pmapped = false;
}
}
}
result->pixelMapped = pmapped;
}
}
}

Expand Down

0 comments on commit 8de7a97

Please sign in to comment.