Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
8
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 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio() * localScale;
30 memcpy(buf->data() + matrixCount * 64, &matrixScale, 4);
31 changed = true;
32 }
33
34 if (state.isOpacityDirty()) {
35 const float opacity = state.opacity();
36 memcpy(buf->data() + matrixCount * 64 + 4, &opacity, 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(buf->data() + offset, &newStrokeColor, 16);
57 changed = true;
58 }
59 offset += 16;
60
61 if (oldNode == nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
62 float w = newNode->strokeWidth();
63 memcpy(buf->data() + offset, &w, 4);
64 changed = true;
65 }
66 offset += 4;
67 if (oldNode == nullptr || newNode->debug() != oldNode->debug()) {
68 float w = newNode->debug();
69 memcpy(buf->data() + offset, &w, 4);
70 changed = true;
71 }
72// offset += 4;
73
74 return changed;
75}
76
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
\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
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
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...
QSGCurveStrokeNode * node() const
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
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...
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:289
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
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]