aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-05-11 15:14:59 +0200
committerArisotura <thetotalworm@gmail.com>2019-05-11 15:14:59 +0200
commit53b22629173b9147231e1305ea9701377344b172 (patch)
treeb0ac194f1f3c3dd2d9d33805e9a015ed8566787a
parent5c9df6a4e5dc507a1498a79ea30c3dea279e94bf (diff)
calculate hi-res vertex positions. reduces shaking of polygons when rendering at a higher res.
-rw-r--r--src/GPU3D.cpp10
-rw-r--r--src/GPU3D.h4
-rw-r--r--src/GPU3D_OpenGL43.cpp6
3 files changed, 19 insertions, 1 deletions
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index 68b9c7f..3be8ee1 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -1194,6 +1194,16 @@ void SubmitPolygon()
vtx->FinalPosition[0] = posX & 0x1FF;
vtx->FinalPosition[1] = posY & 0xFF;
+ // hi-res positions
+ if (w != 0)
+ {
+ posX = ((((s64)(vtx->Position[0] + w) * Viewport[4]) << 4) / (((s64)w) << 1)) + (Viewport[0] << 4);
+ posY = ((((s64)(-vtx->Position[1] + w) * Viewport[5]) << 4) / (((s64)w) << 1)) + (Viewport[3] << 4);
+
+ vtx->HiresPosition[0] = posX & 0x1FFF;
+ vtx->HiresPosition[1] = posY & 0xFFF;
+ }
+
vtx->FinalColor[0] = vtx->Color[0] >> 12;
if (vtx->FinalColor[0]) vtx->FinalColor[0] = ((vtx->FinalColor[0] << 4) + 0xF);
vtx->FinalColor[1] = vtx->Color[1] >> 12;
diff --git a/src/GPU3D.h b/src/GPU3D.h
index ecc23de..53712ad 100644
--- a/src/GPU3D.h
+++ b/src/GPU3D.h
@@ -39,6 +39,10 @@ typedef struct
s32 FinalPosition[2];
s32 FinalColor[3];
+ // hi-res position (4-bit fractional part)
+ // TODO maybe: hi-res color? (that survives clipping)
+ s32 HiresPosition[2];
+
} Vertex;
typedef struct
diff --git a/src/GPU3D_OpenGL43.cpp b/src/GPU3D_OpenGL43.cpp
index cc099f2..1e4f9d7 100644
--- a/src/GPU3D_OpenGL43.cpp
+++ b/src/GPU3D_OpenGL43.cpp
@@ -1120,9 +1120,13 @@ void BuildPolygons(RendererPolygon* polygons, int npolys)
u32 zshift = 0;
while (z > 0xFFFF) { z >>= 1; zshift++; }
+ u32 x = vtx->HiresPosition[0] >> 3;
+ u32 y = vtx->HiresPosition[1] >> 3;
+ *vptr++ = x | (y << 16);
+
// TODO hires-upgraded positions?
//*vptr++ = vtx->FinalPosition[0] | (vtx->FinalPosition[1] << 16);
- *vptr++ = (vtx->FinalPosition[0] << 1) | (vtx->FinalPosition[1] << 17);
+ //*vptr++ = (vtx->FinalPosition[0] << 1) | (vtx->FinalPosition[1] << 17);
//*vptr++ = (vtx->FinalPosition[0] << 2) | (vtx->FinalPosition[1] << 18);
*vptr++ = z | (w << 16);