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:
parent
db7283ee5c
commit
622114dfb5
3 changed files with 24 additions and 10 deletions
|
@ -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
|
||||
***************************************************************/
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue