5#include <QtGui/private/qtriangulator_p.h>
6#include <QtGui/private/qtriangulatingstroker_p.h>
8#include <QSGVertexColorMaterial>
9#include <QSGTextureProvider>
10#include <private/qsgplaintexture_p.h>
12#include <QtQuick/private/qsggradientcache_p.h>
33 c.getRgbF(&r, &g, &b, &a);
35 uchar(qRound(r * a * 255)),
36 uchar(qRound(g * a * 255)),
37 uchar(qRound(b * a * 255)),
38 uchar(qRound(a * 255))
46 setFlag(QSGNode::OwnsGeometry,
true);
47 setFlag(QSGNode::UsePreprocess,
true);
48 setGeometry(
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(), 0, 0));
49 activateMaterial(window, MatSolidColor);
51 qsgnode_set_description(
this, QLatin1String(
"stroke-fill"));
61 m_material.reset(QQuickShapeGenericMaterialFactory::createVertexColor(window));
63 case MatLinearGradient:
64 m_material.reset(QQuickShapeGenericMaterialFactory::createLinearGradient(window,
this));
66 case MatRadialGradient:
67 m_material.reset(QQuickShapeGenericMaterialFactory::createRadialGradient(window,
this));
69 case MatConicalGradient:
70 m_material.reset(QQuickShapeGenericMaterialFactory::createConicalGradient(window,
this));
73 m_material.reset(QQuickShapeGenericMaterialFactory::createTextureFill(window,
this));
76 qWarning(
"Unknown material %d", m);
80 if (material() != m_material.data())
81 setMaterial(m_material.data());
86 if (m_fillTextureProvider !=
nullptr) {
87 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_fillTextureProvider->texture()))
88 texture->updateTexture();
94 markDirty(QSGNode::DirtyMaterial);
99 m_fillTextureProvider =
nullptr;
100 markDirty(QSGNode::DirtyMaterial);
105 for (ShapePathData &d : m_sp) {
107 d.pendingFill->orphaned =
true;
109 d.pendingStroke->orphaned =
true;
118 for (
int i = totalCount; i < m_sp.size(); i++)
119 setFillTextureProvider(i,
nullptr);
121 if (m_sp.size() != totalCount) {
122 m_sp.resize(totalCount);
124 *countChanged =
true;
126 *countChanged =
false;
128 for (ShapePathData &d : m_sp)
134 ShapePathData &d(m_sp[index]);
141 ShapePathData &d(m_sp[index]);
142 const bool wasTransparent = d.strokeColor
.a == 0;
143 d.strokeColor = colorToColor4ub(color);
144 const bool isTransparent = d.strokeColor
.a == 0;
146 if (wasTransparent && !isTransparent)
152 ShapePathData &d(m_sp[index]);
161 ShapePathData &d(m_sp[index]);
162 d.pen.setCosmetic(c);
170 ShapePathData &d(m_sp[index]);
171 const bool wasTransparent = d.fillColor
.a == 0;
172 d.fillColor = colorToColor4ub(color);
173 const bool isTransparent = d.fillColor
.a == 0;
175 if (wasTransparent && !isTransparent)
181 ShapePathData &d(m_sp[index]);
182 d.fillRule = Qt::FillRule(fillRule);
188 ShapePathData &d(m_sp[index]);
189 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
190 d.pen.setMiterLimit(miterLimit);
196 ShapePathData &d(m_sp[index]);
197 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
202 qreal dashOffset,
const QVector<qreal> &dashPattern)
204 ShapePathData &d(m_sp[index]);
205 d.pen.setStyle(Qt::PenStyle(strokeStyle));
206 if (strokeStyle == QQuickShapePath::DashLine) {
207 d.pen.setDashPattern(dashPattern);
208 d.pen.setDashOffset(dashOffset);
215 ShapePathData &d(m_sp[index]);
217 d.fillGradient.stops = gradient->gradientStops();
218 d.fillGradient.spread = QGradient::Spread(gradient->spread());
219 if (QQuickShapeLinearGradient *g = qobject_cast<QQuickShapeLinearGradient *>(gradient)) {
220 d.fillGradientActive = LinearGradient;
221 d.fillGradient.a = QPointF(g->x1(), g->y1());
222 d.fillGradient.b = QPointF(g->x2(), g->y2());
223 }
else if (QQuickShapeRadialGradient *g = qobject_cast<QQuickShapeRadialGradient *>(gradient)) {
224 d.fillGradientActive = RadialGradient;
225 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
226 d.fillGradient.b = QPointF(g->focalX(), g->focalY());
227 d.fillGradient.v0 = g->centerRadius();
228 d.fillGradient.v1 = g->focalRadius();
229 }
else if (QQuickShapeConicalGradient *g = qobject_cast<QQuickShapeConicalGradient *>(gradient)) {
230 d.fillGradientActive = ConicalGradient;
231 d.fillGradient.a = QPointF(g->centerX(), g->centerY());
232 d.fillGradient.v0 = g->angle();
237 d.fillGradientActive = NoGradient;
244 ShapePathData &d(m_sp[index]);
245 if ((d.fillTextureProviderItem ==
nullptr) != (textureProviderItem ==
nullptr))
247 if (d.fillTextureProviderItem !=
nullptr)
248 QQuickItemPrivate::get(d.fillTextureProviderItem)->derefWindow();
249 d.fillTextureProviderItem = textureProviderItem;
250 if (d.fillTextureProviderItem !=
nullptr)
251 QQuickItemPrivate::get(d.fillTextureProviderItem)->refWindow(m_item->window());
257 for (
auto &pathData : m_sp) {
258 if (pathData.fillTextureProviderItem !=
nullptr) {
259 if (window ==
nullptr)
260 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->derefWindow();
262 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->refWindow(window);
270 ShapePathData &d(m_sp[index]);
271 d.fillTransform = transform;
278 m_triangulationScale = scale;
283 QQuickShapeGenericRenderer::triangulateFill(path, fillColor, &fillVertices, &fillIndices, &indexType,
284 supportsElementIndexUint, triangulationScale);
290 QQuickShapeGenericRenderer::triangulateStroke(path, pen, strokeColor, &strokeVertices, clipSize, triangulationScale);
296 m_asyncCallback = callback;
297 m_asyncCallbackData = data;
301static QThreadPool *pathWorkThreadPool =
nullptr;
303static void deletePathWorkThreadPool()
305 delete pathWorkThreadPool;
306 pathWorkThreadPool =
nullptr;
312#if !QT_CONFIG(thread)
318 bool didKickOffAsync =
false;
320 for (
int i = 0; i < m_sp.size(); ++i) {
321 ShapePathData &d(m_sp[i]);
325 m_accDirty |= d.syncDirty;
332 d.effectiveDirty |= d.syncDirty;
334 if (d.path.isEmpty()) {
335 d.fillVertices.clear();
336 d.fillIndices.clear();
337 d.strokeVertices.clear();
342 if (async && !pathWorkThreadPool) {
343 qAddPostRoutine(deletePathWorkThreadPool);
344 pathWorkThreadPool =
new QThreadPool;
345 const int idealCount = QThread::idealThreadCount();
346 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
349 auto testFeatureIndexUint = [](QQuickItem *item) ->
bool {
350 if (
auto *w = item->window()) {
351 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
352 return rhi->isFeatureSupported(QRhi::ElementIndexUint);
356 static bool supportsElementIndexUint = testFeatureIndexUint(m_item);
358 d.path.setFillRule(d.fillRule);
359 if (m_api == QSGRendererInterface::Unknown)
360 m_api = m_item->window()->rendererInterface()->graphicsApi();
363 r->setAutoDelete(
false);
370 r->triangulationScale = m_triangulationScale;
373 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
376 if (!r->orphaned && i < m_sp.size()) {
377 ShapePathData &d(m_sp[i]);
378 d.fillVertices = r->fillVertices;
379 d.fillIndices = r->fillIndices;
380 d.indexType = r->indexType;
381 d.pendingFill =
nullptr;
382 d.effectiveDirty |= DirtyFillGeom;
383 maybeUpdateAsyncItem();
387 didKickOffAsync =
true;
391 qtVectorPathForPath(r->path);
392 pathWorkThreadPool->start(r);
395 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
396 supportsElementIndexUint,
397 m_triangulationScale);
401 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && d.strokeColor
.a) {
404 r->setAutoDelete(
false);
411 r->clipSize = QSize(m_item->width(), m_item->height());
412 r->triangulationScale = m_triangulationScale;
413 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
414 if (!r->orphaned && i < m_sp.size()) {
415 ShapePathData &d(m_sp[i]);
416 d.strokeVertices = r->strokeVertices;
417 d.pendingStroke =
nullptr;
418 d.effectiveDirty |= DirtyStrokeGeom;
419 maybeUpdateAsyncItem();
423 didKickOffAsync =
true;
427 qtVectorPathForPath(r->path);
428 pathWorkThreadPool->start(r);
431 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
432 QSize(m_item->width(), m_item->height()), m_triangulationScale);
437 if (!didKickOffAsync && async && m_asyncCallback)
438 m_asyncCallback(m_asyncCallbackData);
443 for (
const ShapePathData &d : std::as_const(m_sp)) {
444 if (d.pendingFill || d.pendingStroke)
450 m_asyncCallback(m_asyncCallbackData);
459 QSGGeometry::Type *indexType,
460 bool supportsElementIndexUint,
461 qreal triangulationScale)
463 const QVectorPath &vp = qtVectorPathForPath(path);
465 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
466 const int vertexCount = ts.vertices.size() / 2;
467 fillVertices->resize(vertexCount);
469 const qreal *vsrc = ts.vertices.constData();
470 for (
int i = 0; i < vertexCount; ++i)
471 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
473 size_t indexByteSize;
474 if (ts.indices.type() == QVertexIndexVector::UnsignedShort) {
475 *indexType = QSGGeometry::UnsignedShortType;
478 fillIndices->resize(ts.indices.size() / 2);
479 indexByteSize = ts.indices.size() *
sizeof(quint16);
481 *indexType = QSGGeometry::UnsignedIntType;
482 fillIndices->resize(ts.indices.size());
483 indexByteSize = ts.indices.size() *
sizeof(quint32);
485 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
492 const QSize &clipSize,
493 qreal triangulationScale)
495 const QVectorPath &vp = qtVectorPathForPath(path);
496 const QRectF clip(QPointF(0, 0), clipSize);
497 const qreal inverseScale = 1.0 / triangulationScale;
499 QTriangulatingStroker stroker;
500 stroker.setInvScale(inverseScale);
502 if (pen.style() == Qt::SolidLine) {
503 stroker.process(vp, pen, clip, {});
505 QDashedStrokeProcessor dashStroker;
506 dashStroker.setInvScale(inverseScale);
507 dashStroker.process(vp, pen, clip, {});
508 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
509 dashStroker.elementTypes(), 0);
510 stroker.process(dashStroke, pen, clip, {});
513 if (!stroker.vertexCount()) {
514 strokeVertices->clear();
518 const int vertexCount = stroker.vertexCount() / 2;
519 strokeVertices->resize(vertexCount);
521 const float *vsrc = stroker.vertices();
522 for (
int i = 0; i < vertexCount; ++i)
523 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
528 if (m_rootNode != node) {
537 if (!m_rootNode || !m_accDirty)
553 for (ShapePathData &d : m_sp) {
556 *nodePtr =
new QQuickShapeGenericNode;
557 prevNode->m_next = *nodePtr;
558 prevNode->appendChildNode(*nodePtr);
561 QQuickShapeGenericNode *node = *nodePtr;
563 if (m_accDirty & DirtyList)
564 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient | DirtyFillTransform | DirtyFillTexture;
566 if (!d.effectiveDirty) {
568 nodePtr = &node->m_next;
572 if (d.fillColor.a == 0) {
573 delete node->m_fillNode;
574 node->m_fillNode =
nullptr;
575 }
else if (!node->m_fillNode) {
576 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
577 if (node->m_strokeNode)
578 node->removeChildNode(node->m_strokeNode);
579 node->appendChildNode(node->m_fillNode);
580 if (node->m_strokeNode)
581 node->appendChildNode(node->m_strokeNode);
582 d.effectiveDirty |= DirtyFillGeom;
585 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
586 delete node->m_strokeNode;
587 node->m_strokeNode =
nullptr;
588 }
else if (!node->m_strokeNode) {
589 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
590 node->appendChildNode(node->m_strokeNode);
591 d.effectiveDirty |= DirtyStrokeGeom;
594 updateFillNode(&d, node);
595 updateStrokeNode(&d, node);
597 d.effectiveDirty = 0;
600 nodePtr = &node->m_next;
603 if (*nodePtr && prevNode) {
604 prevNode->removeChildNode(*nodePtr);
609 if (m_sp.isEmpty()) {
623 if (d->fillGradientActive) {
625 n->m_fillGradient = d->fillGradient;
628 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
630 && d->fillTextureProviderItem !=
nullptr
631 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
636 if (n->m_fillTextureProvider !=
nullptr) {
637 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
638 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
639 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
640 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
643 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
645 : d->fillTextureProviderItem->textureProvider();
647 if (n->m_fillTextureProvider !=
nullptr) {
648 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
649 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
650 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
651 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
656 n->m_fillTransform = d->fillTransform;
669 updateShadowDataInNode(d, n);
671 QSGGeometry *g = n->geometry();
672 if (d->fillVertices.isEmpty()) {
673 if (g->vertexCount() || g->indexCount()) {
675 n->markDirty(QSGNode::DirtyGeometry);
680 if (d->fillGradientActive) {
682 switch (d->fillGradientActive) {
689 case ConicalGradient:
693 Q_UNREACHABLE_RETURN();
695 n->activateMaterial(m_item->window(), gradMat);
698 n->markDirty(QSGNode::DirtyMaterial);
703 }
else if (d->fillTextureProviderItem !=
nullptr) {
704 n->activateMaterial(m_item->window(), QQuickShapeGenericStrokeFillNode::MatTextureFill);
705 if (d->effectiveDirty & DirtyFillTexture)
706 n->markDirty(QSGNode::DirtyMaterial);
708 n->activateMaterial(m_item->window(), QQuickShapeGenericStrokeFillNode::MatSolidColor);
710 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
711 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
712 for (
int i = 0; i < g->vertexCount(); ++i)
714 n->markDirty(QSGNode::DirtyGeometry);
719 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
720 ? d->fillIndices.size() * 2 : d->fillIndices.size();
721 if (g->indexType() != d->indexType) {
722 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
723 d->fillVertices.size(), indexCount, d->indexType);
726 g->allocate(d->fillVertices.size(), indexCount);
728 g->setDrawingMode(QSGGeometry::DrawTriangles);
730 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
731 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
733 n->markDirty(QSGNode::DirtyGeometry);
744 QSGGeometry *g = n->geometry();
745 if (d->strokeVertices.isEmpty()) {
746 if (g->vertexCount() || g->indexCount()) {
748 n->markDirty(QSGNode::DirtyGeometry);
753 n->markDirty(QSGNode::DirtyGeometry);
758 if (!g->vertexCount())
759 n->markDirty(QSGNode::DirtyMaterial);
762 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
763 for (
int i = 0; i < g->vertexCount(); ++i)
768 g->allocate(d->strokeVertices.size(), 0);
769 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
770 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
775 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
777 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
778 return new QSGVertexColorMaterial;
780 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
787 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
789 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
792 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
799 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
801 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
804 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
811 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
813 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
816 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
823 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
825 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
828 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
834 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
835 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
839 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
841 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
843 bool changed =
false;
844 QByteArray *buf = state.uniformData();
845 Q_ASSERT(buf->size() >= 84 + 64);
846 const int shaderMatrixCount = newMaterial->viewCount();
847 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
849 if (state.isMatrixDirty()) {
850 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
851 const QMatrix4x4 m = state.combinedMatrix();
852 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
859 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
860 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
861 m_fillTransform = node->m_fillTransform;
865 if (!oldMaterial || m_gradA.x() != node->m_fillGradient.a.x() || m_gradA.y() != node->m_fillGradient.a.y()) {
866 m_gradA = QVector2D(node->m_fillGradient.a.x(), node->m_fillGradient.a.y());
867 Q_ASSERT(
sizeof(m_gradA) == 8);
868 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
872 if (!oldMaterial || m_gradB.x() != node->m_fillGradient.b.x() || m_gradB.y() != node->m_fillGradient.b.y()) {
873 m_gradB = QVector2D(node->m_fillGradient.b.x(), node->m_fillGradient.b.y());
874 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
878 if (state.isOpacityDirty()) {
879 const float opacity = state.opacity();
880 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
888 QSGMaterial *newMaterial, QSGMaterial *)
895 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
896 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
897 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
903 static QSGMaterialType type;
909 Q_ASSERT(other && type() == other->type());
918 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
919 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
921 if (
int d = ga->spread - gb->spread)
924 if (
int d = ga->a.x() - gb->a.x())
926 if (
int d = ga->a.y() - gb->a.y())
928 if (
int d = ga->b.x() - gb->b.x())
930 if (
int d = ga->b.y() - gb->b.y())
933 if (
int d = ga->stops.size() - gb->stops.size())
936 for (
int i = 0; i < ga->stops.size(); ++i) {
937 if (
int d = ga->stops[i].first - gb->stops[i].first)
939 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
943 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
951 Q_UNUSED(renderMode);
957 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
958 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
962 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
964 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
966 bool changed =
false;
967 QByteArray *buf = state.uniformData();
968 Q_ASSERT(buf->size() >= 92 + 64);
969 const int shaderMatrixCount = newMaterial->viewCount();
970 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
972 if (state.isMatrixDirty()) {
973 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
974 const QMatrix4x4 m = state.combinedMatrix();
975 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
982 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
983 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
984 m_fillTransform = node->m_fillTransform;
988 const QPointF centerPoint = node->m_fillGradient.a;
989 const QPointF focalPoint = node->m_fillGradient.b;
990 const QPointF focalToCenter = centerPoint - focalPoint;
991 const float centerRadius = node->m_fillGradient.v0;
992 const float focalRadius = node->m_fillGradient.v1;
994 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
995 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
996 Q_ASSERT(
sizeof(m_focalPoint) == 8);
997 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1001 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1002 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1003 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1004 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1008 if (!oldMaterial || m_centerRadius != centerRadius) {
1009 m_centerRadius = centerRadius;
1010 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1014 if (!oldMaterial || m_focalRadius != focalRadius) {
1015 m_focalRadius = focalRadius;
1016 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1020 if (state.isOpacityDirty()) {
1021 const float opacity = state.opacity();
1022 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1030 QSGMaterial *newMaterial, QSGMaterial *)
1037 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1038 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1039 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1045 static QSGMaterialType type;
1051 Q_ASSERT(other && type() == other->type());
1060 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1061 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1063 if (
int d = ga->spread - gb->spread)
1066 if (
int d = ga->a.x() - gb->a.x())
1068 if (
int d = ga->a.y() - gb->a.y())
1070 if (
int d = ga->b.x() - gb->b.x())
1072 if (
int d = ga->b.y() - gb->b.y())
1075 if (
int d = ga->v0 - gb->v0)
1077 if (
int d = ga->v1 - gb->v1)
1080 if (
int d = ga->stops.size() - gb->stops.size())
1083 for (
int i = 0; i < ga->stops.size(); ++i) {
1084 if (
int d = ga->stops[i].first - gb->stops[i].first)
1086 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1090 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1098 Q_UNUSED(renderMode);
1104 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1105 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1109 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1111 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1113 bool changed =
false;
1114 QByteArray *buf = state.uniformData();
1115 Q_ASSERT(buf->size() >= 80 + 64);
1116 const int shaderMatrixCount = newMaterial->viewCount();
1117 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1119 if (state.isMatrixDirty()) {
1120 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1121 const QMatrix4x4 m = state.combinedMatrix();
1122 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1129 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1130 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1131 m_fillTransform = node->m_fillTransform;
1135 const QPointF centerPoint = node->m_fillGradient.a;
1136 const float angle = -qDegreesToRadians(node->m_fillGradient.v0);
1138 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1139 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1140 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1141 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1145 if (!oldMaterial || m_angle != angle) {
1147 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1151 if (state.isOpacityDirty()) {
1152 const float opacity = state.opacity();
1153 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1161 QSGMaterial *newMaterial, QSGMaterial *)
1168 const QSGGradientCacheKey cacheKey(node->m_fillGradient.stops, QGradient::Spread(node->m_fillGradient.spread));
1169 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1170 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1176 static QSGMaterialType type;
1182 Q_ASSERT(other && type() == other->type());
1191 const QSGGradientCache::GradientDesc *ga = &a->m_fillGradient;
1192 const QSGGradientCache::GradientDesc *gb = &b->m_fillGradient;
1194 if (
int d = ga->a.x() - gb->a.x())
1196 if (
int d = ga->a.y() - gb->a.y())
1199 if (
int d = ga->v0 - gb->v0)
1202 if (
int d = ga->stops.size() - gb->stops.size())
1205 for (
int i = 0; i < ga->stops.size(); ++i) {
1206 if (
int d = ga->stops[i].first - gb->stops[i].first)
1208 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1212 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1220 Q_UNUSED(renderMode);
1226 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1227 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1231 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1233 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1235 bool changed =
false;
1236 QByteArray *buf = state.uniformData();
1237 const int shaderMatrixCount = newMaterial->viewCount();
1238 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1239 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1241 if (state.isMatrixDirty()) {
1242 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1243 const QMatrix4x4 m = state.combinedMatrix();
1244 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1251 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1252 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1253 m_fillTransform = node->m_fillTransform;
1257 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1258 ? node->m_fillTextureProvider->texture()->textureSize()
1262 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1263 boundsSize.height() / state.devicePixelRatio());
1264 if (!oldMaterial || m_boundsSize != boundsVector) {
1265 m_boundsSize = boundsVector;
1266 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1267 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1271 if (state.isOpacityDirty()) {
1272 const float opacity = state.opacity();
1273 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1281 QSGMaterial *newMaterial, QSGMaterial *)
1288 if (node->m_fillTextureProvider !=
nullptr) {
1289 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1290 if (providedTexture !=
nullptr) {
1291 if (providedTexture->isAtlasTexture()) {
1295 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1296 if (newTexture !=
nullptr)
1297 providedTexture = newTexture;
1300 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1301 *texture = providedTexture;
1306 if (m->dummyTexture() ==
nullptr) {
1307 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1308 dummyTexture->setFiltering(QSGTexture::Nearest);
1309 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1310 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1311 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1313 dummyTexture->setImage(img);
1314 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1316 m->setDummyTexture(dummyTexture);
1319 *texture = m->dummyTexture();
1324 delete m_dummyTexture;
1329 static QSGMaterialType type;
1335 Q_ASSERT(other && type() == other->type());
1344 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1347 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1348 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1353 Q_UNUSED(renderMode);
1359#include "moc_qquickshapegenericrenderer_p.cpp"
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeConicalGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
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...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeConicalGradientRhiShader(int viewCount)
bool supportsElementIndexUint
QQuickShapeGenericRenderer::Color4ub fillColor
QQuickShapeGenericStrokeFillNode * m_fillNode
QQuickShapeGenericStrokeFillNode * m_strokeNode
QQuickShapeGenericNode * m_next
void setAsyncCallback(void(*)(void *), void *) override
void setTriangulationScale(qreal scale) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setFillTransform(int index, const QSGTransform &transform) override
void setCosmeticStroke(int index, bool c) override
void setPath(int index, const QPainterPath &path, QQuickShapePath::PathHints pathHints={}) override
void setStrokeColor(int index, const QColor &color) override
void setFillRule(int index, QQuickShapePath::FillRule fillRule) override
QVector< quint32 > IndexContainerType
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setFillColor(int index, const QColor &color) override
QVector< QSGGeometry::ColoredPoint2D > VertexContainerType
void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override
void setStrokeWidth(int index, qreal w) override
~QQuickShapeGenericRenderer()
void setRootNode(QQuickShapeGenericNode *node)
void handleSceneChange(QQuickWindow *window) override
void beginSync(int totalCount, bool *countChanged) override
void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override
void updateNode() override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QVector< qreal > &dashPattern) override
void endSync(bool async) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
void activateMaterial(QQuickWindow *window, Material m)
QQuickShapeLinearGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
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...
QQuickShapeGenericStrokeFillNode * node() const
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QQuickShapeLinearGradientRhiShader(int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeGenericStrokeFillNode * node() const
QQuickShapeRadialGradientMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
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...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QQuickShapeRadialGradientRhiShader(int viewCount)
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
QQuickShapeGenericRenderer::Color4ub strokeColor
QQuickShapeTextureFillMaterial(QQuickShapeGenericStrokeFillNode *node)
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
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...
QQuickShapeGenericStrokeFillNode * node() const
~QQuickShapeTextureFillMaterial() override
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
QQuickShapeTextureFillRhiShader(int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
static QQuickShapeGenericRenderer::Color4ub colorToColor4ub(const QColor &c)
#define QSG_RUNTIME_DESCRIPTION
void set(float nx, float ny, QQuickShapeGenericRenderer::Color4ub ncolor)