From dfed20701a168d431a7c1bc72a406b2128012e5b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 15 Apr 2017 19:52:17 -0700 Subject: [PATCH] SoftGPU: Correct negative coord handling. Fixes #5159 - we need this signed to handle negative values properly. --- GPU/Software/Clipper.cpp | 8 ++++---- GPU/Software/Rasterizer.cpp | 4 ++-- GPU/Software/TransformUnit.cpp | 4 ++-- GPU/Software/TransformUnit.h | 11 +++++------ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/GPU/Software/Clipper.cpp b/GPU/Software/Clipper.cpp index f0bbacdd71..818113efdb 100644 --- a/GPU/Software/Clipper.cpp +++ b/GPU/Software/Clipper.cpp @@ -128,10 +128,10 @@ static inline int CalcClipMask(const ClipCoords& v) } static void RotateUVThrough(const VertexData &tl, const VertexData &br, VertexData &tr, VertexData &bl) { - const fixed16 x1 = tl.screenpos.x; - const fixed16 x2 = br.screenpos.x; - const fixed16 y1 = tl.screenpos.y; - const fixed16 y2 = br.screenpos.y; + const int x1 = tl.screenpos.x; + const int x2 = br.screenpos.x; + const int y1 = tl.screenpos.y; + const int y2 = br.screenpos.y; if ((x1 < x2 && y1 > y2) || (x1 > x2 && y1 < y2)) { std::swap(bl.texturecoords, tr.texturecoords); diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 9d190a8cfb..a88ec11a98 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -509,14 +509,14 @@ static inline bool DepthTestPassed(int x, int y, u16 z) } } -static inline bool IsRightSideOrFlatBottomLine(const Vec2& vertex, const Vec2& line1, const Vec2& line2) +static inline bool IsRightSideOrFlatBottomLine(const Vec2& vertex, const Vec2& line1, const Vec2& line2) { if (line1.y == line2.y) { // just check if vertex is above us => bottom line parallel to x-axis return vertex.y < line1.y; } else { // check if vertex is on our left => right side - return vertex.x < line1.x + ((int)line2.x - (int)line1.x) * ((int)vertex.y - (int)line1.y) / ((int)line2.y - (int)line1.y); + return vertex.x < line1.x + (line2.x - line1.x) * (vertex.y - line1.y) / (line2.y - line1.y); } } diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 5fd39c6974..06f2208d24 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -191,8 +191,8 @@ VertexData TransformUnit::ReadVertex(VertexReader& vreader) Lighting::Process(vertex, vreader.hasColor0()); } else { - vertex.screenpos.x = (u32)pos[0] * 16 + gstate.getOffsetX16(); - vertex.screenpos.y = (u32)pos[1] * 16 + gstate.getOffsetY16(); + vertex.screenpos.x = (int)(pos[0] * 16) + gstate.getOffsetX16(); + vertex.screenpos.y = (int)(pos[1] * 16) + gstate.getOffsetY16(); vertex.screenpos.z = pos[2]; vertex.clippos.w = 1.f; vertex.fogdepth = 1.f; diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index 84ca3a2cdb..b0b77833e1 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -23,7 +23,6 @@ using namespace Math3D; -typedef u16 fixed16; typedef u16 u10; // TODO: erm... :/ typedef Vec3 ModelCoords; @@ -36,17 +35,17 @@ struct SplinePatch; struct ScreenCoords { ScreenCoords() {} - ScreenCoords(fixed16 x, fixed16 y, u16 z) : x(x), y(y), z(z) {} + ScreenCoords(int x, int y, u16 z) : x(x), y(y), z(z) {} - fixed16 x; - fixed16 y; + int x; + int y; u16 z; - Vec2 xy() const { return Vec2(x, y); } + Vec2 xy() const { return Vec2(x, y); } ScreenCoords operator * (const float t) const { - return ScreenCoords((fixed16)(x * t), (fixed16)(y * t), (u16)(z * t)); + return ScreenCoords((int)(x * t), (int)(y * t), (u16)(z * t)); } ScreenCoords operator / (const int t) const