Move texture coordinate post processing into a method of RenderGeometry

This allows us to reuse the code in other places.
This commit is contained in:
Arjen Hiemstra 2023-01-12 14:06:52 +01:00
parent db7283ee5c
commit 622114dfb5
3 changed files with 24 additions and 10 deletions

View file

@ -1182,6 +1182,18 @@ void RenderGeometry::appendSubQuad(const WindowQuad &quad, const QRectF &subquad
append(vertices[2]); 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 Motion1D
***************************************************************/ ***************************************************************/

View file

@ -3051,6 +3051,17 @@ public:
* device coordinates. * device coordinates.
*/ */
void appendSubQuad(const WindowQuad &quad, const QRectF &subquad, qreal deviceScale); 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: private:
VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round; VertexSnappingMode m_vertexSnappingMode = VertexSnappingMode::Round;

View file

@ -304,16 +304,7 @@ void ItemRendererOpenGL::renderItem(Item *item, int mask, const QRegion &region,
renderNode.firstVertex = v; renderNode.firstVertex = v;
renderNode.vertexCount = renderNode.geometry.count(); renderNode.vertexCount = renderNode.geometry.count();
const QMatrix4x4 textureMatrix = renderNode.texture->matrix(renderNode.coordinateType); renderNode.geometry.postProcessTextureCoordinates(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.copy(std::span(&map[v], renderNode.geometry.count())); renderNode.geometry.copy(std::span(&map[v], renderNode.geometry.count()));
v += renderNode.geometry.count(); v += renderNode.geometry.count();