From 2ad497c8f94f91b6913c5cd1d57a0c3a68fa3af9 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Fri, 12 Aug 2022 12:31:50 +0200 Subject: [PATCH] Round buffer positions when calculating normalised UV coordinates Otherwise we end up with UVs that are slightly off as the position is fractional while the size is integer. --- src/surfaceitem.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/surfaceitem.cpp b/src/surfaceitem.cpp index eeb0fad253..06a8c0278b 100644 --- a/src/surfaceitem.cpp +++ b/src/surfaceitem.cpp @@ -136,10 +136,14 @@ WindowQuadList SurfaceItem::buildQuads() const for (const QRectF rect : region) { WindowQuad quad; - const QPointF bufferTopLeft = m_surfaceToBufferMatrix.map(rect.topLeft()); - const QPointF bufferTopRight = m_surfaceToBufferMatrix.map(rect.topRight()); - const QPointF bufferBottomRight = m_surfaceToBufferMatrix.map(rect.bottomRight()); - const QPointF bufferBottomLeft = m_surfaceToBufferMatrix.map(rect.bottomLeft()); + // Use toPoint to round the device position to match what we eventually + // do for the geometry, otherwise we end up with mismatched UV + // coordinates as the texture size is going to be in (rounded) device + // coordinates as well. + const QPointF bufferTopLeft = m_surfaceToBufferMatrix.map(rect.topLeft()).toPoint(); + const QPointF bufferTopRight = m_surfaceToBufferMatrix.map(rect.topRight()).toPoint(); + const QPointF bufferBottomRight = m_surfaceToBufferMatrix.map(rect.bottomRight()).toPoint(); + const QPointF bufferBottomLeft = m_surfaceToBufferMatrix.map(rect.bottomLeft()).toPoint(); quad[0] = WindowVertex(rect.topLeft(), QPointF{bufferTopLeft.x() / size.width(), bufferTopLeft.y() / size.height()}); quad[1] = WindowVertex(rect.topRight(), QPointF{bufferTopRight.x() / size.width(), bufferTopRight.y() / size.height()});