first vertex clipped against last becomes last vertex

theory i had.
fixes clipped horizontal line polygons
This commit is contained in:
Jaklyy 2023-11-26 20:17:03 -05:00
parent ad7b1a8c61
commit a371c8f1e0

View File

@ -769,6 +769,8 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta
temp[1] = vertices[1]; temp[1] = vertices[1];
} }
Vertex holdit;
bool heldit = false;
for (int i = clipstart; i < nverts; i++) for (int i = clipstart; i < nverts; i++)
{ {
prev = i-1; if (prev < 0) prev = nverts-1; prev = i-1; if (prev < 0) prev = nverts-1;
@ -781,10 +783,18 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta
Vertex* vprev = &vertices[prev]; Vertex* vprev = &vertices[prev];
if (vprev->Position[comp] <= vprev->Position[3]) if (vprev->Position[comp] <= vprev->Position[3])
{
if (i == 0)
{
ClipSegment<comp, 1, attribs>(&holdit, &vtx, vprev);
heldit = true;
}
else
{ {
ClipSegment<comp, 1, attribs>(&temp[c], &vtx, vprev); ClipSegment<comp, 1, attribs>(&temp[c], &vtx, vprev);
c++; c++;
} }
}
Vertex* vnext = &vertices[next]; Vertex* vnext = &vertices[next];
if (vnext->Position[comp] <= vnext->Position[3]) if (vnext->Position[comp] <= vnext->Position[3])
@ -797,6 +807,12 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta
temp[c++] = vtx; temp[c++] = vtx;
} }
if (heldit)
{
temp[c++] = holdit;
}
heldit = false;
nverts = c; c = clipstart; nverts = c; c = clipstart;
for (int i = clipstart; i < nverts; i++) for (int i = clipstart; i < nverts; i++)
{ {
@ -808,10 +824,19 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta
{ {
Vertex* vprev = &temp[prev]; Vertex* vprev = &temp[prev];
if (vprev->Position[comp] >= -vprev->Position[3]) if (vprev->Position[comp] >= -vprev->Position[3])
{
if (i == 0)
{
ClipSegment<comp, -1, attribs>(&holdit, &vtx, vprev);
heldit = true;
}
else
{ {
ClipSegment<comp, -1, attribs>(&vertices[c], &vtx, vprev); ClipSegment<comp, -1, attribs>(&vertices[c], &vtx, vprev);
c++; c++;
} }
}
Vertex* vnext = &temp[next]; Vertex* vnext = &temp[next];
if (vnext->Position[comp] >= -vnext->Position[3]) if (vnext->Position[comp] >= -vnext->Position[3])
@ -824,6 +849,11 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta
vertices[c++] = vtx; vertices[c++] = vtx;
} }
if (heldit)
{
vertices[c++] = holdit;
}
// checkme // checkme
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++)
{ {