From 622114dfb539862e5fde11d5818a41399063ed67 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Thu, 12 Jan 2023 14:06:52 +0100 Subject: [PATCH] Move texture coordinate post processing into a method of RenderGeometry This allows us to reuse the code in other places. --- src/libkwineffects/kwineffects.cpp | 12 ++++++++++++ src/libkwineffects/kwineffects.h | 11 +++++++++++ src/scene/itemrenderer_opengl.cpp | 11 +---------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index d7cad1dae6..d8711b45ef 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -1182,6 +1182,18 @@ void RenderGeometry::appendSubQuad(const WindowQuad &quad, const QRectF &subquad append(vertices[2]); } +void RenderGeometry::postProcessTextureCoordinates(const QMatrix4x4 &textureMatrix) +{ + if (!textureMatrix.isIdentity()) { + const QVector2D coeff(textureMatrix(0, 0), textureMatrix(1, 1)); + const QVector2D offset(textureMatrix(0, 3), textureMatrix(1, 3)); + + for (auto &vertex : (*this)) { + vertex.texcoord = vertex.texcoord * coeff + offset; + } + } +} + /*************************************************************** Motion1D ***************************************************************/ diff --git a/src/libkwineffects/kwineffects.h b/src/libkwineffects/kwineffects.h index d7bc2a3557..7591d1ef4d 100644 --- a/src/libkwineffects/kwineffects.h +++ b/src/libkwineffects/kwineffects.h @@ -3051,6 +3051,17 @@ public: * device coordinates. */ void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale); + /** + * Modify this geometry's texture coordinates based on a matrix. + * + * This is primarily intended to convert from non-normalised to normalised + * texture coordinates. + * + * @param textureMatrix The texture matrix to use for modifying the + * texture coordinates. Note that only the 2D scale and + * translation are used. + */ + void postProcessTextureCoordinates(const QMatrix4x4 &textureMatrix); private: VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round; diff --git a/src/scene/itemrenderer_opengl.cpp b/src/scene/itemrenderer_opengl.cpp index 1cbee36816..3f8463efa1 100644 --- a/src/scene/itemrenderer_opengl.cpp +++ b/src/scene/itemrenderer_opengl.cpp @@ -304,16 +304,7 @@ void ItemRendererOpenGL::renderItem(Item *item, int mask, const QRegion ®ion, renderNode.firstVertex = v; renderNode.vertexCount = renderNode.geometry.count(); - const QMatrix4x4 textureMatrix = renderNode.texture->matrix(renderNode.coordinateType); - if (!textureMatrix.isIdentity()) { - // Adjust the vertex' texture coordinates with the specified matrix. - const QVector2D coeff(textureMatrix(0, 0), textureMatrix(1, 1)); - const QVector2D offset(textureMatrix(0, 3), textureMatrix(1, 3)); - - for (auto &vertex : renderNode.geometry) { - vertex.texcoord = vertex.texcoord * coeff + offset; - } - } + renderNode.geometry.postProcessTextureCoordinates(renderNode.texture->matrix(renderNode.coordinateType)); renderNode.geometry.copy(std::span(&map[v], renderNode.geometry.count())); v += renderNode.geometry.count();