From d12112b7a569ad8094d3e3c8d3c3087b07a6220c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 11 Aug 2024 19:54:22 +0300 Subject: [PATCH] scene: Make ImageItem provide device texture coordinates The main motivation behind this change is to make the ItemRendererOpenGL use a homogeneous coordinate space for texture coordinates in order to simplify rendering code. The device pixels have been chosen because they are more agnostic about the graphics api. --- src/scene/imageitem.cpp | 11 +++++++---- src/scene/itemrenderer_opengl.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/scene/imageitem.cpp b/src/scene/imageitem.cpp index 72df2ccc94..ea669ad3da 100644 --- a/src/scene/imageitem.cpp +++ b/src/scene/imageitem.cpp @@ -24,6 +24,7 @@ QImage ImageItem::image() const void ImageItem::setImage(const QImage &image) { m_image = image; + discardQuads(); } ImageItemOpenGL::ImageItemOpenGL(Item *parent) @@ -68,11 +69,13 @@ WindowQuadList ImageItemOpenGL::buildQuads() const return WindowQuadList{}; } + const QRectF imageRect = m_image.rect(); + WindowQuad quad; - quad[0] = WindowVertex(geometry.topLeft(), QPointF(0, 0)); - quad[1] = WindowVertex(geometry.topRight(), QPointF(1, 0)); - quad[2] = WindowVertex(geometry.bottomRight(), QPointF(1, 1)); - quad[3] = WindowVertex(geometry.bottomLeft(), QPointF(0, 1)); + quad[0] = WindowVertex(geometry.topLeft(), imageRect.topLeft()); + quad[1] = WindowVertex(geometry.topRight(), imageRect.topRight()); + quad[2] = WindowVertex(geometry.bottomRight(), imageRect.bottomRight()); + quad[3] = WindowVertex(geometry.bottomLeft(), imageRect.bottomLeft()); WindowQuadList ret; ret.append(quad); diff --git a/src/scene/itemrenderer_opengl.cpp b/src/scene/itemrenderer_opengl.cpp index 94dbcbba6c..01105abe8c 100644 --- a/src/scene/itemrenderer_opengl.cpp +++ b/src/scene/itemrenderer_opengl.cpp @@ -210,7 +210,7 @@ void ItemRendererOpenGL::createRenderNode(Item *item, RenderContext *context) .transformMatrix = context->transformStack.top(), .opacity = context->opacityStack.top(), .hasAlpha = imageItem->image().hasAlphaChannel(), - .coordinateType = NormalizedCoordinates, + .coordinateType = UnnormalizedCoordinates, .colorDescription = item->colorDescription(), .renderingIntent = item->renderingIntent(), .bufferReleasePoint = nullptr,