Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickshapestrokenode_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
8
10
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(buf->data(), m.constData(), 64);
20
21 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio();
22 memcpy(buf->data()+64, &matrixScale, 4);
23 changed = true;
24 }
25
26 if (state.isOpacityDirty()) {
27 const float opacity = state.opacity();
28 memcpy(buf->data() + 64 + 4, &opacity, 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(buf->data() + offset, &newStrokeColor, 16);
56 changed = true;
57 }
58 offset += 16;
59
60 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
61 float w = newNode->strokeWidth();
62 memcpy(buf->data() + offset, &w, 4);
63 changed = true;
64 }
65 //offset += 16;
66
67 return changed;
68}
69
71{
72 int typeDif = type() - other->type();
73 if (!typeDif) {
74 auto *othernode = static_cast<const QQuickShapeStrokeMaterial*>(other)->node();
75 if (node()->color() != othernode->color())
76 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
77 if (node()->strokeWidth() != othernode->strokeWidth())
78 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
79 }
80 return typeDif;
81}
82
\inmodule QtCore
Definition qbytearray.h:57
QRgb rgb() const noexcept
Returns the RGB value of the color.
Definition qcolor.cpp:1439
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
bool updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
int compare(const QSGMaterial *other) const override
Compares this material to other and returns 0 if they are equal; -1 if this material should sort befo...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeStrokeNode * node() const
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
else opt state
[0]
Combined button and popup list for selecting options.
qfloat16 qSqrt(qfloat16 f)
Definition qfloat16.h:243
constexpr T qAbs(const T &t)
Definition qnumeric.h:328
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLuint GLintptr offset
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSharedPointer< T > other(t)
[5]