10bool QSGCurveStrokeMaterialShader::updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
13 QByteArray *buf = state.uniformData();
14 Q_ASSERT(buf->size() >= 64);
15 const int matrixCount = qMin(state.projectionMatrixCount(), newEffect->viewCount());
17 auto *newMaterial =
static_cast<QSGCurveStrokeMaterial *>(newEffect);
18 auto *oldMaterial =
static_cast<QSGCurveStrokeMaterial *>(oldEffect);
20 auto *newNode = newMaterial !=
nullptr ? newMaterial->node() :
nullptr;
21 auto *oldNode = oldMaterial !=
nullptr ? oldMaterial->node() :
nullptr;
23 if (state.isMatrixDirty()) {
24 float localScale = newNode !=
nullptr ? newNode->localScale() : 1.0f;
25 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
26 QMatrix4x4 m = state.combinedMatrix(viewIndex);
28 memcpy(buf->data() + viewIndex * 64, m.constData(), 64);
31 float matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio() * localScale;
32 memcpy(buf->data() + matrixCount * 64, &matrixScale, 4);
33 float dpr = state.devicePixelRatio();
34 memcpy(buf->data() + matrixCount * 64 + 8, &dpr, 4);
38 if (state.isOpacityDirty()) {
39 const float opacity = state.opacity();
40 memcpy(buf->data() + matrixCount * 64 + 4, &opacity, 4);
44 if (oldNode ==
nullptr || newNode->strokeWidth() != oldNode->strokeWidth()) {
45 float w = newNode->strokeWidth();
46 memcpy(buf->data() + matrixCount * 64 + 12, &w, 4);
50 int offset = matrixCount * 64 + 16;
51 if (newNode ==
nullptr)
54 QVector4D newStrokeColor(newNode->color().redF(),
55 newNode->color().greenF(),
56 newNode->color().blueF(),
57 newNode->color().alphaF());
58 QVector4D oldStrokeColor = oldNode !=
nullptr
59 ? QVector4D(oldNode->color().redF(),
60 oldNode->color().greenF(),
61 oldNode->color().blueF(),
62 oldNode->color().alphaF())
65 if (oldNode ==
nullptr || oldStrokeColor != newStrokeColor) {
66 memcpy(buf->data() + offset, &newStrokeColor, 16);
71 if (oldNode ==
nullptr || newNode->debug() != oldNode->debug()) {
72 float w = newNode->debug();
73 memcpy(buf->data() + offset, &w, 4);
80int QSGCurveStrokeMaterial::compare(
const QSGMaterial *other)
const
82 int typeDif = type() - other->type();
84 auto *othernode =
static_cast<
const QSGCurveStrokeMaterial*>(other)->node();
85 if (node()->color() != othernode->color())
86 return node()->color().rgb() < othernode->color().rgb() ? -1 : 1;
87 if (node()->strokeWidth() != othernode->strokeWidth())
88 return node()->strokeWidth() < othernode->strokeWidth() ? -1 : 1;
93QSGMaterialShader *QSGCurveStrokeMaterial::createShader(QSGRendererInterface::RenderMode renderMode)
const
96 int variant =
int(QSGCurveStrokeMaterialShader::Variant::Default);
97 if (m_strokeExpanding)
98 variant |=
int(QSGCurveStrokeMaterialShader::Variant::Expanding);
99 if (node()->useStandardDerivatives())
100 variant |=
int(QSGCurveStrokeMaterialShader::Variant::Derivatives);
101 return new QSGCurveStrokeMaterialShader(variant, viewCount());