all repos — mgba @ 400ac04d42bfa058e33f61176a53148a39b7ca34

mGBA Game Boy Advance Emulator

GBA Video: Fix some small cases in sprite optimization
Jeffrey Pfau jeffrey@endrift.com
Tue, 16 Aug 2016 22:40:03 -0700
commit

400ac04d42bfa058e33f61176a53148a39b7ca34

parent

c6dd9b6e6498059f28b8a5847ddb8826d07f782d

1 files changed, 32 insertions(+), 28 deletions(-)

jump to
M src/gba/renderers/software-obj.csrc/gba/renderers/software-obj.c

@@ -208,35 +208,39 @@ condition = end;

} // Clip off early pixels - if ((xAccum >> 8) < -(width >> 1)) { - int32_t diffX = -(width << 7) - xAccum; - int32_t x = mat.a ? diffX / mat.a : 0; - xAccum += mat.a * x; - yAccum += mat.c * x; - outX += x; - inX += x; - } else if ((xAccum >> 8) >= (width >> 1)) { - int32_t diffX = (width << 7) - xAccum; - int32_t x = mat.a ? diffX / mat.a : 0; - xAccum += mat.a * x; - yAccum += mat.c * x; - outX += x; - inX += x; + if (mat.a) { + if ((xAccum >> 8) < -(width >> 1)) { + int32_t diffX = -(width << 7) - xAccum - 1; + int32_t x = mat.a ? diffX / mat.a : 0; + xAccum += mat.a * x; + yAccum += mat.c * x; + outX += x; + inX += x; + } else if ((xAccum >> 8) >= (width >> 1)) { + int32_t diffX = (width << 7) - xAccum; + int32_t x = mat.a ? diffX / mat.a : 0; + xAccum += mat.a * x; + yAccum += mat.c * x; + outX += x; + inX += x; + } } - if ((yAccum >> 8) < -(height >> 1)) { - int32_t diffY = -(height << 7) - yAccum; - int32_t y = mat.c ? diffY / mat.c : 0; - xAccum += mat.a * y; - yAccum += mat.c * y; - outX += y; - inX += y; - } else if ((yAccum >> 8) >= (height >> 1)) { - int32_t diffY = (height << 7) - yAccum; - int32_t y = mat.c ? diffY / mat.c : 0; - xAccum += mat.a * y; - yAccum += mat.c * y; - outX += y; - inX += y; + if (mat.c) { + if ((yAccum >> 8) < -(height >> 1)) { + int32_t diffY = -(height << 7) - yAccum - 1; + int32_t y = mat.c ? diffY / mat.c : 0; + xAccum += mat.a * y; + yAccum += mat.c * y; + outX += y; + inX += y; + } else if ((yAccum >> 8) >= (height >> 1)) { + int32_t diffY = (height << 7) - yAccum; + int32_t y = mat.c ? diffY / mat.c : 0; + xAccum += mat.a * y; + yAccum += mat.c * y; + outX += y; + inX += y; + } } if (!GBAObjAttributesAIs256Color(sprite->a)) {