From a371c8f1e07095e67ff2f4b30e88e8265be43db7 Mon Sep 17 00:00:00 2001 From: Jaklyy <102590697+Jaklyy@users.noreply.github.com> Date: Sun, 26 Nov 2023 20:17:03 -0500 Subject: [PATCH] first vertex clipped against last becomes last vertex theory i had. fixes clipped horizontal line polygons --- src/GPU3D.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp index b00e6fd2..8d7050e2 100644 --- a/src/GPU3D.cpp +++ b/src/GPU3D.cpp @@ -769,6 +769,8 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta temp[1] = vertices[1]; } + Vertex holdit; + bool heldit = false; for (int i = clipstart; i < nverts; i++) { prev = i-1; if (prev < 0) prev = nverts-1; @@ -782,8 +784,16 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta Vertex* vprev = &vertices[prev]; if (vprev->Position[comp] <= vprev->Position[3]) { - ClipSegment(&temp[c], &vtx, vprev); - c++; + if (i == 0) + { + ClipSegment(&holdit, &vtx, vprev); + heldit = true; + } + else + { + ClipSegment(&temp[c], &vtx, vprev); + c++; + } } Vertex* vnext = &vertices[next]; @@ -797,6 +807,12 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta temp[c++] = vtx; } + if (heldit) + { + temp[c++] = holdit; + } + heldit = false; + nverts = c; c = clipstart; for (int i = clipstart; i < nverts; i++) { @@ -809,8 +825,17 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta Vertex* vprev = &temp[prev]; if (vprev->Position[comp] >= -vprev->Position[3]) { - ClipSegment(&vertices[c], &vtx, vprev); - c++; + + if (i == 0) + { + ClipSegment(&holdit, &vtx, vprev); + heldit = true; + } + else + { + ClipSegment(&vertices[c], &vtx, vprev); + c++; + } } Vertex* vnext = &temp[next]; @@ -823,6 +848,11 @@ int ClipAgainstPlane(const GPU3D& gpu, Vertex* vertices, int nverts, int clipsta else vertices[c++] = vtx; } + + if (heldit) + { + vertices[c++] = holdit; + } // checkme for (int i = 0; i < c; i++)