From e1de3407f15fd1e5e2f4494395c3784e613e1acd Mon Sep 17 00:00:00 2001 From: Vincent Pelletier Date: Fri, 22 Jul 2016 06:19:41 +0200 Subject: [PATCH] TINYGL: Make scissors follow Common::Rect semantics. As per Common::Rect data model, right and bottom border are excluded, so: - Make FrameBuffer::scissorPixel reject bottom & right borders. - Update bounding rectangle definition for dirty rectangle operations ClearBufferDrawCall::getDirtyRegion is already correct. - zblit was almost following, except for an off-by-one mistake. --- graphics/tinygl/zblit.cpp | 4 ++-- graphics/tinygl/zbuffer.h | 2 +- graphics/tinygl/zdirtyrect.cpp | 26 +++++--------------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/graphics/tinygl/zblit.cpp b/graphics/tinygl/zblit.cpp index 063def717d0..99934a1e0d7 100644 --- a/graphics/tinygl/zblit.cpp +++ b/graphics/tinygl/zblit.cpp @@ -163,13 +163,13 @@ public: return false; } - if (dstX + width > c->_scissorRect.right) { + if (dstX + width >= c->_scissorRect.right) { clampWidth = c->_scissorRect.right - dstX; } else { clampWidth = width; } - if (dstY + height > c->_scissorRect.bottom) { + if (dstY + height >= c->_scissorRect.bottom) { clampHeight = c->_scissorRect.bottom - dstY; } else { clampHeight = height; diff --git a/graphics/tinygl/zbuffer.h b/graphics/tinygl/zbuffer.h index 07fc7497f03..6d6a4de3a07 100644 --- a/graphics/tinygl/zbuffer.h +++ b/graphics/tinygl/zbuffer.h @@ -226,7 +226,7 @@ struct FrameBuffer { } FORCEINLINE bool scissorPixel(int x, int y) { - return x < _clipRectangle.left || x > _clipRectangle.right || y < _clipRectangle.top || y > _clipRectangle.bottom; + return !_clipRectangle.contains(x, y); } FORCEINLINE void writePixel(int pixel, byte aSrc, byte rSrc, byte gSrc, byte bSrc) { diff --git a/graphics/tinygl/zdirtyrect.cpp b/graphics/tinygl/zdirtyrect.cpp index 743b5ea6fa1..b5f5757acb4 100644 --- a/graphics/tinygl/zdirtyrect.cpp +++ b/graphics/tinygl/zdirtyrect.cpp @@ -54,11 +54,11 @@ static void tglDrawRectangle(Common::Rect rect, int r, int g, int b) { for(int x = rect.left; x < rect.right; x++) { c->fb->writePixel(rect.top * c->fb->xsize + x, 255, r, g, b); - c->fb->writePixel(rect.bottom * c->fb->xsize + x, 255, r, g, b); + c->fb->writePixel((rect.bottom - 1) * c->fb->xsize + x, 255, r, g, b); } for(int y = rect.top; y < rect.bottom; y++) { c->fb->writePixel(y * c->fb->xsize + rect.left, 255, r, g, b); - c->fb->writePixel(y * c->fb->xsize + rect.right, 255, r, g, b); + c->fb->writePixel(y * c->fb->xsize + rect.right - 1, 255, r, g, b); } } #endif @@ -302,7 +302,7 @@ void RasterizationDrawCall::computeDirtyRegion() { int width = c->fb->xsize; int height = c->fb->ysize; - int left = width, right = 0, top = height, bottom = 0; + int left = width - 1, right = 0, top = height - 1, bottom = 0; bool pointInsideVolume = false; @@ -339,37 +339,21 @@ void RasterizationDrawCall::computeDirtyRegion() { if (left < 0) { left = 0; - if (right < left) { - left = 0; - right = width - 1; - } } if (right >= width) { right = width - 1; - if (left > right) { - left = 0; - right = width - 1; - } } if (top < 0) { top = 0; - if (bottom < top) { - top = 0; - bottom = height - 1; - } } if (bottom >= height) { bottom = height - 1; - if (top > bottom) { - top = 0; - bottom = height - 1; - } } - _dirtyRegion = Common::Rect(left, top, right, bottom); + _dirtyRegion = Common::Rect(left, top, right + 1, bottom + 1); // This takes into account precision issues that occur during rasterization. _dirtyRegion.left -= 2; _dirtyRegion.top -= 2; @@ -648,7 +632,7 @@ const Common::Rect BlittingDrawCall::getDirtyRegion() const { tglGetBlitImageSize(_image, blitWidth, blitHeight); } } - return Common::Rect(_transform._destinationRectangle.left, _transform._destinationRectangle.top, _transform._destinationRectangle.left + blitWidth, _transform._destinationRectangle.top + blitHeight); + return Common::Rect(_transform._destinationRectangle.left, _transform._destinationRectangle.top, _transform._destinationRectangle.left + blitWidth + 1, _transform._destinationRectangle.top + blitHeight + 1); } bool BlittingDrawCall::operator==(const BlittingDrawCall &other) const {