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 "qsgcurvestrokenode_p_p.h"
5#include "qsgcurvestrokenode_p.h"
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(a: state.projectionMatrixCount(), b: 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(index: viewIndex);
26 m.scale(factor: localScale);
27 memcpy(dest: buf->data() + viewIndex * 64, src: m.constData(), n: 64);
28 }
29 float matrixScale = qSqrt(v: qAbs(t: state.determinant())) * state.devicePixelRatio() * localScale;
30 memcpy(dest: buf->data() + matrixCount * 64, src: &matrixScale, n: 4);
31 changed = true;
32 }
33
34 if (state.isOpacityDirty()) {
35 const float opacity = state.opacity();
36 memcpy(dest: buf->data() + matrixCount * 64 + 4, src: &opacity, n: 4);
37 changed = true;
38 }
39
40 int offset = matrixCount * 64 + 16;
41 if (newNode == nullptr)
42 return changed;
43
44 QVector4D newStrokeColor(newNode->color().redF(),
45 newNode->color().greenF(),
46 newNode->color().blueF(),
47 newNode->color().alphaF());
48 QVector4D oldStrokeColor = oldNode != nullptr
49 ? QVector4D(oldNode->color().redF(),
50 oldNode->color().greenF(),
51 oldNode->color().blueF(),
52 oldNode->color().alphaF())
53 : QVector4D{};
54
55 if (oldNode == nullptr || oldStrokeColor != newStrokeColor) {
56 memcpy(dest: buf->data() + offset, src: &newStrokeColor, n: 16);
57 changed = true;
58 }
59 offset += 16;
60
61 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
62 float w = newNode->strokeWidth();
63 memcpy(dest: buf->data() + offset, src: &w, n: 4);
64 changed = true;
65 }
66 offset += 4;
67 if (oldNode == nullptr || newNode->debug() != oldNode->debug()) {
68 float w = newNode->debug();
69 memcpy(dest: buf->data() + offset, src: &w, n: 4);
70 changed = true;
71 }
72// offset += 4;
73
74 return changed;
75}
76
77int QSGCurveStrokeMaterial::compare(const QSGMaterial *other) const
78{
79 int typeDif = type() - other->type();
80 if (!typeDif) {
81 auto *othernode = static_cast<const QSGCurveStrokeMaterial*>(other)->node();
82 if (node()->color() != othernode->color())
83 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
84 if (node()->strokeWidth() != othernode->strokeWidth())
85 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
86 }
87 return typeDif;
88}
89
90QT_END_NAMESPACE
91

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtdeclarative/src/quick/scenegraph/qsgcurvestrokenode_p.cpp