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
4#include "qquickshapestrokenode_p_p.h"
5#include "qquickshapestrokenode_p.h"
6
7#include "qquickshapegenericrenderer_p.h"
8
9QT_BEGIN_NAMESPACE
10
11bool QQuickShapeStrokeMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
12{
13 bool changed = false;
14 QByteArray *buf = state.uniformData();
15 Q_ASSERT(buf->size() >= 64);
16
17 if (state.isMatrixDirty()) {
18 const QMatrix4x4 m = state.combinedMatrix();
19 memcpy(dest: buf->data(), src: m.constData(), n: 64);
20
21 float matrixScale = qSqrt(v: qAbs(t: state.determinant())) * state.devicePixelRatio();
22 memcpy(dest: buf->data()+64, src: &matrixScale, n: 4);
23 changed = true;
24 }
25
26 if (state.isOpacityDirty()) {
27 const float opacity = state.opacity();
28 memcpy(dest: buf->data() + 64 + 4, src: &opacity, n: 4);
29 changed = true;
30 }
31
32 int offset = 64+16;
33
34 auto *newMaterial = static_cast<QQuickShapeStrokeMaterial *>(newEffect);
35 auto *oldMaterial = static_cast<QQuickShapeStrokeMaterial *>(oldEffect);
36
37 auto *newNode = newMaterial != nullptr ? newMaterial->node() : nullptr;
38 auto *oldNode = oldMaterial != nullptr ? oldMaterial->node() : nullptr;
39
40 if (newNode == nullptr)
41 return changed;
42
43 QVector4D newStrokeColor(newNode->color().redF(),
44 newNode->color().greenF(),
45 newNode->color().blueF(),
46 newNode->color().alphaF());
47 QVector4D oldStrokeColor = oldNode != nullptr
48 ? QVector4D(oldNode->color().redF(),
49 oldNode->color().greenF(),
50 oldNode->color().blueF(),
51 oldNode->color().alphaF())
52 : QVector4D{};
53
54 if (oldNode == nullptr || oldStrokeColor != newStrokeColor) {
55 memcpy(dest: buf->data() + offset, src: &newStrokeColor, n: 16);
56 changed = true;
57 }
58 offset += 16;
59
60 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
61 float w = newNode->strokeWidth();
62 memcpy(dest: buf->data() + offset, src: &w, n: 4);
63 changed = true;
64 }
65 offset += 4;
66 if (oldNode == nullptr || newNode->debug() != oldNode->debug()) {
67 float w = newNode->debug();
68 memcpy(dest: buf->data() + offset, src: &w, n: 4);
69 changed = true;
70 }
71// offset += 4;
72
73 return changed;
74}
75
76int QQuickShapeStrokeMaterial::compare(const QSGMaterial *other) const
77{
78 int typeDif = type() - other->type();
79 if (!typeDif) {
80 auto *othernode = static_cast<const QQuickShapeStrokeMaterial*>(other)->node();
81 if (node()->color() != othernode->color())
82 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
83 if (node()->strokeWidth() != othernode->strokeWidth())
84 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
85 }
86 return typeDif;
87}
88
89QT_END_NAMESPACE
90

source code of qtdeclarative/src/quickshapes/qquickshapestrokenode_p.cpp