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.
This commit is contained in:
Arjen Hiemstra 2022-08-12 12:31:50 +02:00
parent 64e42bbd04
commit 2ad497c8f9

View file

@ -136,10 +136,14 @@ WindowQuadList SurfaceItem::buildQuads() const
for (const QRectF rect : region) { for (const QRectF rect : region) {
WindowQuad quad; WindowQuad quad;
const QPointF bufferTopLeft = m_surfaceToBufferMatrix.map(rect.topLeft()); // Use toPoint to round the device position to match what we eventually
const QPointF bufferTopRight = m_surfaceToBufferMatrix.map(rect.topRight()); // do for the geometry, otherwise we end up with mismatched UV
const QPointF bufferBottomRight = m_surfaceToBufferMatrix.map(rect.bottomRight()); // coordinates as the texture size is going to be in (rounded) device
const QPointF bufferBottomLeft = m_surfaceToBufferMatrix.map(rect.bottomLeft()); // 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[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()}); quad[1] = WindowVertex(rect.topRight(), QPointF{bufferTopRight.x() / size.width(), bufferTopRight.y() / size.height()});