Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgcurvestrokenode_p.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7QT_BEGIN_NAMESPACE
8
9bool QSGCurveStrokeMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
10{
11 bool changed = false;
12 QByteArray *buf = state.uniformData();
13 Q_ASSERT(buf->size() >= 64);
14 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
15
16 auto *newMaterial = static_cast<QSGCurveStrokeMaterial *>(newEffect);
17 auto *oldMaterial = static_cast<QSGCurveStrokeMaterial *>(oldEffect);
18
19 auto *newNode = newMaterial != nullptr ? newMaterial->node() : nullptr;
20 auto *oldNode = oldMaterial != nullptr ? oldMaterial->node() : nullptr;
21
22 if (state.isMatrixDirty()) {
23 float localScale = newNode != nullptr ? newNode->localScale() : 1.0f;
24 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
25 QMatrix4x4 m = state.combinedMatrix(viewIndex);
26 m.scale(localScale);
27 memcpy(buf->data() + viewIndex * 64, m.constData(), 64);
28 }
29 // determinant is xscale * yscale, as long as Item.transform does not include shearing or rotation
30 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio() * localScale;
31 memcpy(buf->data() + matrixCount * 64, &matrixScale, 4);
32 float dpr = state.devicePixelRatio();
33 memcpy(buf->data() + matrixCount * 64 + 8, &dpr, 4);
34 changed = true;
35 }
36
37 if (state.isOpacityDirty()) {
38 const float opacity = state.opacity();
39 memcpy(buf->data() + matrixCount * 64 + 4, &opacity, 4);
40 changed = true;
41 }
42
43 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
44 float w = newNode->strokeWidth();
45 memcpy(buf->data() + matrixCount * 64 + 12, &w, 4);
46 changed = true;
47 }
48
49 int offset = matrixCount * 64 + 16;
50 if (newNode == nullptr)
51 return changed;
52
53 QVector4D newStrokeColor(newNode->color().redF(),
54 newNode->color().greenF(),
55 newNode->color().blueF(),
56 newNode->color().alphaF());
57 QVector4D oldStrokeColor = oldNode != nullptr
58 ? QVector4D(oldNode->color().redF(),
59 oldNode->color().greenF(),
60 oldNode->color().blueF(),
61 oldNode->color().alphaF())
62 : QVector4D{};
63
64 if (oldNode == nullptr || oldStrokeColor != newStrokeColor) {
65 memcpy(buf->data() + offset, &newStrokeColor, 16);
66 changed = true;
67 }
68 offset += 16;
69
70 if (oldNode == nullptr || newNode->debug() != oldNode->debug()) {
71 float w = newNode->debug();
72 memcpy(buf->data() + offset, &w, 4);
73 changed = true;
74 }
75
76 return changed;
77}
78
79int QSGCurveStrokeMaterial::compare(const QSGMaterial *other) const
80{
81 int typeDif = type() - other->type();
82 if (!typeDif) {
83 auto *othernode = static_cast<const QSGCurveStrokeMaterial*>(other)->node();
84 if (node()->color() != othernode->color())
85 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
86 if (node()->strokeWidth() != othernode->strokeWidth())
87 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
88 }
89 return typeDif;
90}
91
92QT_END_NAMESPACE