From 2f4fa23e61d6e2894aa703bfa131a3b3e474a15d Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Tue, 5 Jul 2022 13:27:48 +0200 Subject: [PATCH] Use normalized UV coordinates for SurfaceItem Relying on the texture matrix to normalize means we multiply every UV coordinate with 1/scale, which leads to floating point errors and thus errors in the UV coordinates. Instead, if we calculate normalized coordinates directly we avoid floating point error and get proper UV coordinates. Longer term the plan is to make all UV coordinates normalized and get rid of the CoordinateType altogether. --- src/scenes/opengl/scene_opengl.cpp | 2 +- src/surfaceitem.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/scenes/opengl/scene_opengl.cpp b/src/scenes/opengl/scene_opengl.cpp index d06ea5406b..890d33ca43 100644 --- a/src/scenes/opengl/scene_opengl.cpp +++ b/src/scenes/opengl/scene_opengl.cpp @@ -376,7 +376,7 @@ void SceneOpenGL::createRenderNode(Item *item, RenderContext *context) .transformMatrix = context->transformStack.top(), .opacity = context->opacityStack.top(), .hasAlpha = hasAlpha, - .coordinateType = UnnormalizedCoordinates, + .coordinateType = NormalizedCoordinates, }); } } diff --git a/src/surfaceitem.cpp b/src/surfaceitem.cpp index 8924702755..60bbf4d905 100644 --- a/src/surfaceitem.cpp +++ b/src/surfaceitem.cpp @@ -140,10 +140,12 @@ WindowQuadList SurfaceItem::buildQuads() const const QPointF bufferBottomRight = m_surfaceToBufferMatrix.map(rect.bottomRight()); const QPointF bufferBottomLeft = m_surfaceToBufferMatrix.map(rect.bottomLeft()); - quad[0] = WindowVertex(rect.topLeft(), bufferTopLeft); - quad[1] = WindowVertex(rect.topRight(), bufferTopRight); - quad[2] = WindowVertex(rect.bottomRight(), bufferBottomRight); - quad[3] = WindowVertex(rect.bottomLeft(), bufferBottomLeft); + const auto size = m_pixmap->size(); + + 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[2] = WindowVertex(rect.bottomRight(), QPointF{bufferBottomRight.x() / size.width(), bufferBottomRight.y() / size.height()}); + quad[3] = WindowVertex(rect.bottomLeft(), QPointF{bufferBottomLeft.x() / size.width(), bufferBottomLeft.y() / size.height()}); quads << quad; }