From 68fdb522cbf85247b315ff11a041fe43c04145df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 1 Dec 2024 16:02:48 +0100 Subject: [PATCH] Fix small accuracy issue in through-mode 2D culling --- GPU/Common/DrawEngineCommon.cpp | 52 ++++++++++++++++----------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index d78bdfc9f4..4b9659c45a 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -587,17 +587,6 @@ bool DrawEngineCommon::TestBoundingBoxThrough(const void *vdata, int vertexCount VertexDecoder *dec = GetVertexDecoder(vertType); int stride = dec->VertexSize(); int offset = dec->posoff; - switch (vertType & GE_VTYPE_POS_MASK) { - case GE_VTYPE_POS_FLOAT: - { - for (int i = 0; i < vertexCount; i++) { - memcpy(&verts[i * 3], (const u8 *)vdata + stride * i + offset, sizeof(float) * 3); - } - break; - } - default: - _dbg_assert_(false); - } bool allOutsideLeft = true; bool allOutsideTop = true; @@ -607,27 +596,36 @@ bool DrawEngineCommon::TestBoundingBoxThrough(const void *vdata, int vertexCount const float top = gstate.getScissorY1(); const float right = gstate.getScissorX2(); const float bottom = gstate.getScissorY2(); - for (int i = 0; i < vertexCount; i++) { - const float *pos = verts + i * 3; - float x = pos[0]; - float y = pos[1]; - if (x >= left) { - allOutsideLeft = false; + + switch (vertType & GE_VTYPE_POS_MASK) { + case GE_VTYPE_POS_FLOAT: + { + for (int i = 0; i < vertexCount; i++) { + float *pos = (float*)((const u8 *)vdata + stride * i + offset); + float x = pos[0]; + float y = pos[1]; + if (x >= left) { + allOutsideLeft = false; + } + if (x <= right + 1) { + allOutsideRight = false; + } + if (y >= top) { + allOutsideTop = false; + } + if (y <= bottom + 1) { + allOutsideBottom = false; + } } - if (x <= right) { - allOutsideRight = false; - } - if (y >= top) { - allOutsideTop = false; - } - if (y <= bottom) { - allOutsideBottom = false; + if (allOutsideLeft || allOutsideTop || allOutsideRight || allOutsideBottom) { + return false; } + return true; } - if (allOutsideLeft || allOutsideTop || allOutsideRight || allOutsideBottom) { + default: + _dbg_assert_(false); return false; } - return true; } // TODO: This probably is not the best interface.