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// Qt-Security score:significant reason:default
4
7
8QT_BEGIN_NAMESPACE
9
10bool QSGCurveStrokeMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
11{
12 bool changed = false;
13 QByteArray *buf = state.uniformData();
14 Q_ASSERT(buf->size() >= 64);
15 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
16
17 auto *newMaterial = static_cast<QSGCurveStrokeMaterial *>(newEffect);
18 auto *oldMaterial = static_cast<QSGCurveStrokeMaterial *>(oldEffect);
19
20 auto *newNode = newMaterial != nullptr ? newMaterial->node() : nullptr;
21 auto *oldNode = oldMaterial != nullptr ? oldMaterial->node() : nullptr;
22
23 if (state.isMatrixDirty()) {
24 float localScale = newNode != nullptr ? newNode->localScale() : 1.0f;
25 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
26 QMatrix4x4 m = state.combinedMatrix(viewIndex);
27 m.scale(localScale);
28 memcpy(buf->data() + viewIndex * 64, m.constData(), 64);
29 }
30 // determinant is xscale * yscale, as long as Item.transform does not include shearing or rotation
31 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio() * localScale;
32 memcpy(buf->data() + matrixCount * 64, &matrixScale, 4);
33 float dpr = state.devicePixelRatio();
34 memcpy(buf->data() + matrixCount * 64 + 8, &dpr, 4);
35 changed = true;
36 }
37
38 if (state.isOpacityDirty()) {
39 const float opacity = state.opacity();
40 memcpy(buf->data() + matrixCount * 64 + 4, &opacity, 4);
41 changed = true;
42 }
43
44 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
45 float w = newNode->strokeWidth();
46 memcpy(buf->data() + matrixCount * 64 + 12, &w, 4);
47 changed = true;
48 }
49
50 int offset = matrixCount * 64 + 16;
51 if (newNode == nullptr)
52 return changed;
53
54 QVector4D newStrokeColor(newNode->color().redF(),
55 newNode->color().greenF(),
56 newNode->color().blueF(),
57 newNode->color().alphaF());
58 QVector4D oldStrokeColor = oldNode != nullptr
59 ? QVector4D(oldNode->color().redF(),
60 oldNode->color().greenF(),
61 oldNode->color().blueF(),
62 oldNode->color().alphaF())
63 : QVector4D{};
64
65 if (oldNode == nullptr || oldStrokeColor != newStrokeColor) {
66 memcpy(buf->data() + offset, &newStrokeColor, 16);
67 changed = true;
68 }
69 offset += 16;
70
71 if (oldNode == nullptr || newNode->debug() != oldNode->debug()) {
72 float w = newNode->debug();
73 memcpy(buf->data() + offset, &w, 4);
74 changed = true;
75 }
76
77 return changed;
78}
79
80int QSGCurveStrokeMaterial::compare(const QSGMaterial *other) const
81{
82 int typeDif = type() - other->type();
83 if (!typeDif) {
84 auto *othernode = static_cast<const QSGCurveStrokeMaterial*>(other)->node();
85 if (node()->color() != othernode->color())
86 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
87 if (node()->strokeWidth() != othernode->strokeWidth())
88 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
89 }
90 return typeDif;
91}
92
93QSGMaterialShader *QSGCurveStrokeMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
94{
95 Q_UNUSED(renderMode);
96 int variant = int(QSGCurveStrokeMaterialShader::Variant::Default);
97 if (m_strokeExpanding)
98 variant |= int(QSGCurveStrokeMaterialShader::Variant::Expanding);
99 if (node()->useStandardDerivatives())
100 variant |= int(QSGCurveStrokeMaterialShader::Variant::Derivatives);
101 return new QSGCurveStrokeMaterialShader(variant, viewCount());
102}
103
104QT_END_NAMESPACE