Skip to content

Commit

Permalink
Add pixel mapping detection for through mode RECT primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 11, 2024
1 parent 6e12465 commit 944b3c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions GPU/Common/SoftwareTransformCommon.cpp
Expand Up @@ -497,7 +497,7 @@ void SoftwareTransform::BuildDrawingParams(int prim, int vertexCount, u32 vertTy
bool useBufferedRendering = fbman->UseBufferedRendering();

if (prim == GE_PRIM_RECTANGLES) {
ExpandRectangles(vertexCount, maxIndex, inds, transformed, transformedExpanded, numTrans, throughmode);
ExpandRectangles(vertexCount, maxIndex, inds, transformed, transformedExpanded, numTrans, throughmode, &result->pixelMapped);
result->drawBuffer = transformedExpanded;
result->drawIndexed = true;

Expand All @@ -518,14 +518,17 @@ void SoftwareTransform::BuildDrawingParams(int prim, int vertexCount, u32 vertTy
ExpandPoints(vertexCount, maxIndex, inds, transformed, transformedExpanded, numTrans, throughmode);
result->drawBuffer = transformedExpanded;
result->drawIndexed = true;
result->pixelMapped = false;
} else if (prim == GE_PRIM_LINES) {
ExpandLines(vertexCount, maxIndex, inds, transformed, transformedExpanded, numTrans, throughmode);
result->drawBuffer = transformedExpanded;
result->drawIndexed = true;
result->pixelMapped = false;
} else {
// We can simply draw the unexpanded buffer.
numTrans = vertexCount;
result->drawIndexed = true;
result->pixelMapped = false;

// If we don't support custom cull in the shader, process it here.
if (!gstate_c.Use(GPU_USE_CULL_DISTANCE) && vertexCount > 0 && !throughmode) {
Expand Down Expand Up @@ -611,7 +614,7 @@ void SoftwareTransform::CalcCullParams(float &minZValue, float &maxZValue) {
std::swap(minZValue, maxZValue);
}

void SoftwareTransform::ExpandRectangles(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) {
void SoftwareTransform::ExpandRectangles(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode, bool *pixelMappedExactly) {
// Rectangles always need 2 vertices, disregard the last one if there's an odd number.
vertexCount = vertexCount & ~1;
numTrans = 0;
Expand All @@ -630,10 +633,21 @@ void SoftwareTransform::ExpandRectangles(int vertexCount, int &maxIndex, u16 *&i
vscale /= gstate_c.curTextureHeight;
}

bool pixelMapped = true;

for (int i = 0; i < vertexCount; i += 2) {
const TransformedVertex &transVtxTL = transformed[indsIn[i + 0]];
const TransformedVertex &transVtxBR = transformed[indsIn[i + 1]];

float dx = transVtxBR.x - transVtxTL.x;
float dy = transVtxBR.y - transVtxTL.y;
float du = transVtxBR.u - transVtxTL.u;
float dv = transVtxBR.v - transVtxTL.v;

if (dx <= 0 || dy <= 0 || dx != du || dy != dv) {
pixelMapped = false;
}

// We have to turn the rectangle into two triangles, so 6 points.
// This is 4 verts + 6 indices.

Expand Down Expand Up @@ -676,12 +690,14 @@ void SoftwareTransform::ExpandRectangles(int vertexCount, int &maxIndex, u16 *&i
indsOut[3] = i * 2 + 3;
indsOut[4] = i * 2 + 0;
indsOut[5] = i * 2 + 2;

trans += 4;
indsOut += 6;

numTrans += 6;
}
inds = newInds;
*pixelMappedExactly = pixelMapped;
}

void SoftwareTransform::ExpandLines(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode) {
Expand Down
4 changes: 3 additions & 1 deletion GPU/Common/SoftwareTransformCommon.h
Expand Up @@ -45,6 +45,8 @@ struct SoftwareTransformResult {
TransformedVertex *drawBuffer;
int drawNumTrans;
bool drawIndexed;

bool pixelMapped;
};

struct SoftwareTransformParams {
Expand All @@ -70,7 +72,7 @@ class SoftwareTransform {

protected:
void CalcCullParams(float &minZValue, float &maxZValue);
void ExpandRectangles(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode);
void ExpandRectangles(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode, bool *pixelMappedExactly);
void ExpandLines(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode);
void ExpandPoints(int vertexCount, int &maxIndex, u16 *&inds, const TransformedVertex *transformed, TransformedVertex *transformedExpanded, int &numTrans, bool throughmode);

Expand Down

0 comments on commit 944b3c5

Please sign in to comment.