9bool QSGCurveStrokeMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
12 QByteArray *buf = state.uniformData();
13 Q_ASSERT(buf->size() >= 64);
14 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
16 auto *newMaterial =
static_cast<QSGCurveStrokeMaterial *>(newEffect);
17 auto *oldMaterial =
static_cast<QSGCurveStrokeMaterial *>(oldEffect);
19 auto *newNode = newMaterial !=
nullptr ? newMaterial->node() :
nullptr;
20 auto *oldNode = oldMaterial !=
nullptr ? oldMaterial->node() :
nullptr;
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);
27 memcpy(buf->data() + viewIndex * 64, m.constData(), 64);
30 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio() * localScale;
31 memcpy(buf->data() + matrixCount * 64, &matrixScale, 4);
32 float dpr = state.devicePixelRatio();
33 memcpy(buf->data() + matrixCount * 64 + 8, &dpr, 4);
37 if (state.isOpacityDirty()) {
38 const float opacity = state.opacity();
39 memcpy(buf->data() + matrixCount * 64 + 4, &opacity, 4);
43 if (oldNode ==
nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
44 float w = newNode->strokeWidth();
45 memcpy(buf->data() + matrixCount * 64 + 12, &w, 4);
49 int offset = matrixCount * 64 + 16;
50 if (newNode ==
nullptr)
53 QVector4D newStrokeColor(newNode->color().redF(),
54 newNode->color().greenF(),
55 newNode->color().blueF(),
56 newNode->color().alphaF());
57 QVector4D oldStrokeColor = oldNode !=
nullptr
58 ? QVector4D(oldNode->color().redF(),
59 oldNode->color().greenF(),
60 oldNode->color().blueF(),
61 oldNode->color().alphaF())
64 if (oldNode ==
nullptr || oldStrokeColor != newStrokeColor) {
65 memcpy(buf->data() + offset, &newStrokeColor, 16);
70 if (oldNode ==
nullptr || newNode->debug() != oldNode->debug()) {
71 float w = newNode->debug();
72 memcpy(buf->data() + offset, &w, 4);
79int QSGCurveStrokeMaterial::compare(
const QSGMaterial *other)
const
81 int typeDif = type() - other->type();
83 auto *othernode =
static_cast<
const QSGCurveStrokeMaterial*>(other)->node();
84 if (node()->color() != othernode->color())
85 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
86 if (node()->strokeWidth() != othernode->strokeWidth())
87 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;