6#include <QtGui/private/qtriangulator_p.h>
7#include <QtGui/private/qtriangulatingstroker_p.h>
9#include <QSGVertexColorMaterial>
10#include <QSGTextureProvider>
11#include <private/qsgplaintexture_p.h>
13#include <QtQuick/private/qsggradientcache_p.h>
34 c.getRgbF(&r, &g, &b, &a);
36 uchar(qRound(r * a * 255)),
37 uchar(qRound(g * a * 255)),
38 uchar(qRound(b * a * 255)),
39 uchar(qRound(a * 255))
47 setFlag(QSGNode::OwnsGeometry,
true);
48 setFlag(QSGNode::UsePreprocess,
true);
49 setGeometry(
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(), 0, 0));
50 activateMaterial(window, MatSolidColor);
52 qsgnode_set_description(
this, QLatin1String(
"stroke-fill"));
62 m_material.reset(QQuickShapeGenericMaterialFactory::createVertexColor(window));
64 case MatLinearGradient:
65 m_material.reset(QQuickShapeGenericMaterialFactory::createLinearGradient(window,
this));
67 case MatRadialGradient:
68 m_material.reset(QQuickShapeGenericMaterialFactory::createRadialGradient(window,
this));
70 case MatConicalGradient:
71 m_material.reset(QQuickShapeGenericMaterialFactory::createConicalGradient(window,
this));
74 m_material.reset(QQuickShapeGenericMaterialFactory::createTextureFill(window,
this));
77 qWarning(
"Unknown material %d", m);
81 if (material() != m_material.data())
82 setMaterial(m_material.data());
87 if (m_fillTextureProvider !=
nullptr) {
88 if (QSGDynamicTexture *texture = qobject_cast<QSGDynamicTexture *>(m_fillTextureProvider->texture()))
89 texture->updateTexture();
95 markDirty(QSGNode::DirtyMaterial);
100 m_fillTextureProvider =
nullptr;
101 markDirty(QSGNode::DirtyMaterial);
106 for (ShapePathData &d : m_sp) {
108 d.pendingFill->orphaned =
true;
110 d.pendingStroke->orphaned =
true;
119 for (
int i = totalCount; i < m_sp.size(); i++)
120 setFillTextureProvider(i,
nullptr);
122 if (m_sp.size() != totalCount) {
123 m_sp.resize(totalCount);
125 *countChanged =
true;
127 *countChanged =
false;
129 for (ShapePathData &d : m_sp)
135 ShapePathData &d(m_sp[index]);
142 ShapePathData &d(m_sp[index]);
143 const bool wasTransparent = d.strokeColor
.a == 0;
144 d.strokeColor = colorToColor4ub(color);
145 const bool isTransparent = d.strokeColor
.a == 0;
147 if (wasTransparent && !isTransparent)
153 ShapePathData &d(m_sp[index]);
162 ShapePathData &d(m_sp[index]);
163 d.pen.setCosmetic(c);
171 ShapePathData &d(m_sp[index]);
172 const bool wasTransparent = d.fillColor
.a == 0;
173 d.fillColor = colorToColor4ub(color);
174 const bool isTransparent = d.fillColor
.a == 0;
176 if (wasTransparent && !isTransparent)
182 ShapePathData &d(m_sp[index]);
183 d.fillRule = Qt::FillRule(fillRule);
189 ShapePathData &d(m_sp[index]);
190 d.pen.setJoinStyle(Qt::PenJoinStyle(joinStyle));
191 d.pen.setMiterLimit(miterLimit);
197 ShapePathData &d(m_sp[index]);
198 d.pen.setCapStyle(Qt::PenCapStyle(capStyle));
203 qreal dashOffset,
const QList<qreal> &dashPattern)
205 ShapePathData &d(m_sp[index]);
206 d.pen.setStyle(Qt::PenStyle(strokeStyle));
207 if (strokeStyle == QQuickShapePath::DashLine) {
208 d.pen.setDashPattern(dashPattern);
209 d.pen.setDashOffset(dashOffset);
217 Q_ASSERT(dst !=
nullptr);
218 if (gradient ==
nullptr)
219 return QQuickAbstractPathRenderer::NoGradient;
221 dst->stops = gradient->gradientStops();
222 dst->spread = QGradient::Spread(gradient->spread());
223 if (
const QQuickShapeLinearGradient *g = qobject_cast<
const QQuickShapeLinearGradient *>(gradient)) {
224 dst->a = QPointF(g->x1(), g->y1());
225 dst->b = QPointF(g->x2(), g->y2());
227 return QQuickAbstractPathRenderer::LinearGradient;
228 }
else if (
const QQuickShapeRadialGradient *g = qobject_cast<
const QQuickShapeRadialGradient *>(gradient)) {
229 dst->a = QPointF(g->centerX(), g->centerY());
230 dst->b = QPointF(g->focalX(), g->focalY());
231 dst->v0 = g->centerRadius();
232 dst->v1 = g->focalRadius();
234 return QQuickAbstractPathRenderer::RadialGradient;
235 }
else if (
const QQuickShapeConicalGradient *g = qobject_cast<
const QQuickShapeConicalGradient *>(gradient)) {
236 dst->a = QPointF(g->centerX(), g->centerY());
237 dst->v0 = g->angle();
239 return QQuickAbstractPathRenderer::ConicalGradient;
242 Q_UNREACHABLE_RETURN(QQuickAbstractPathRenderer::NoGradient);
247 ShapePathData &d(m_sp[index]);
248 d.fillGradientActive = copyGenericGradient(gradient, &d.fillGradient);
254 ShapePathData &d(m_sp[index]);
255 d.strokeGradientActive = copyGenericGradient(gradient, &d.strokeGradient);
261 ShapePathData &d(m_sp[index]);
262 if ((d.fillTextureProviderItem ==
nullptr) != (textureProviderItem ==
nullptr))
264 if (d.fillTextureProviderItem !=
nullptr)
265 QQuickItemPrivate::get(d.fillTextureProviderItem)->derefWindow();
266 d.fillTextureProviderItem = textureProviderItem;
267 if (d.fillTextureProviderItem !=
nullptr)
268 QQuickItemPrivate::get(d.fillTextureProviderItem)->refWindow(m_item->window());
274 for (
auto &pathData : m_sp) {
275 if (pathData.fillTextureProviderItem !=
nullptr) {
276 if (window ==
nullptr)
277 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->derefWindow();
279 QQuickItemPrivate::get(pathData.fillTextureProviderItem)->refWindow(window);
287 ShapePathData &d(m_sp[index]);
288 d.fillTransform = transform;
294 ShapePathData &d(m_sp[index]);
295 d.triangulationScale = scale;
314 m_asyncCallback = callback;
315 m_asyncCallbackData = data;
319static QThreadPool *pathWorkThreadPool =
nullptr;
321static void deletePathWorkThreadPool()
323 delete pathWorkThreadPool;
324 pathWorkThreadPool =
nullptr;
330#if !QT_CONFIG(thread)
336 bool didKickOffAsync =
false;
338 for (
int i = 0; i < m_sp.size(); ++i) {
339 ShapePathData &d(m_sp[i]);
343 m_accDirty |= d.syncDirty;
350 d.effectiveDirty |= d.syncDirty;
352 if (d.path.isEmpty()) {
353 d.fillVertices.clear();
354 d.fillIndices.clear();
355 d.strokeVertices.clear();
360 if (async && !pathWorkThreadPool) {
361 qAddPostRoutine(deletePathWorkThreadPool);
362 pathWorkThreadPool =
new QThreadPool;
363 const int idealCount = QThread::idealThreadCount();
364 pathWorkThreadPool->setMaxThreadCount(idealCount > 0 ? idealCount * 2 : 4);
375 const bool supportsElementIndexUint = m_rhiBackendInitialized ? m_supportsElementIndexUint :
true;
377 d.path.setFillRule(d.fillRule);
378 if (m_api == QSGRendererInterface::Unknown)
379 m_api = m_item->window()->rendererInterface()->graphicsApi();
382 r->setAutoDelete(
false);
389 r->triangulationScale = d.triangulationScale;
392 QObject::connect(r, &QQuickShapeFillRunnable::done, qApp, [
this, i](QQuickShapeFillRunnable *r) {
395 if (!r->orphaned && i < m_sp.size()) {
396 ShapePathData &d(m_sp[i]);
397 d.fillVertices = r->fillVertices;
398 d.fillIndices = r->fillIndices;
399 d.indexType = r->indexType;
400 d.pendingFill =
nullptr;
401 d.effectiveDirty |= DirtyFillGeom;
402 maybeUpdateAsyncItem();
406 didKickOffAsync =
true;
410 qtVectorPathForPath(r->path);
411 pathWorkThreadPool->start(r);
414 triangulateFill(d.path, d.fillColor, &d.fillVertices, &d.fillIndices, &d.indexType,
415 supportsElementIndexUint,
416 d.triangulationScale);
420 if ((d.syncDirty &
DirtyStrokeGeom) && d.strokeWidth > 0.0f && (d.strokeColor
.a || d.strokeGradientActive)) {
423 r->setAutoDelete(
false);
430 r->clipSize = QSize(m_item->width(), m_item->height());
431 r->triangulationScale = d.triangulationScale;
432 QObject::connect(r, &QQuickShapeStrokeRunnable::done, qApp, [
this, i](QQuickShapeStrokeRunnable *r) {
433 if (!r->orphaned && i < m_sp.size()) {
434 ShapePathData &d(m_sp[i]);
435 d.strokeVertices = r->strokeVertices;
436 d.pendingStroke =
nullptr;
437 d.effectiveDirty |= DirtyStrokeGeom;
438 maybeUpdateAsyncItem();
442 didKickOffAsync =
true;
446 qtVectorPathForPath(r->path);
447 pathWorkThreadPool->start(r);
450 triangulateStroke(d.path, d.pen, d.strokeColor, &d.strokeVertices,
451 QSize(m_item->width(), m_item->height()), d.triangulationScale);
456 if (!didKickOffAsync && async && m_asyncCallback)
457 m_asyncCallback(m_asyncCallbackData);
462 for (
const ShapePathData &d : std::as_const(m_sp)) {
463 if (d.pendingFill || d.pendingStroke)
469 m_asyncCallback(m_asyncCallbackData);
478 QSGGeometry::Type *indexType,
479 bool supportsElementIndexUint,
480 qreal triangulationScale)
482 const QVectorPath &vp = qtVectorPathForPath(path);
484 QTriangleSet ts = qTriangulate(vp, QTransform::fromScale(triangulationScale, triangulationScale), 1, supportsElementIndexUint);
485 const int vertexCount = ts.vertices.size() / 2;
486 fillVertices->resize(vertexCount);
488 const qreal *vsrc = ts.vertices.constData();
489 for (
int i = 0; i < vertexCount; ++i)
490 vdst[i]
.set(vsrc[i * 2] / triangulationScale
, vsrc[i * 2 + 1] / triangulationScale
, fillColor
);
492 size_t indexByteSize;
493 if (ts.indices.type() == QVertexIndexVector::UnsignedShort) {
494 *indexType = QSGGeometry::UnsignedShortType;
497 fillIndices->resize(ts.indices.size() / 2);
498 indexByteSize = ts.indices.size() *
sizeof(quint16);
500 *indexType = QSGGeometry::UnsignedIntType;
501 fillIndices->resize(ts.indices.size());
502 indexByteSize = ts.indices.size() *
sizeof(quint32);
504 memcpy(fillIndices->data(), ts.indices.data(), indexByteSize);
511 const QSize &clipSize,
512 qreal triangulationScale)
514 const QVectorPath &vp = qtVectorPathForPath(path);
515 const QRectF clip(QPointF(0, 0), clipSize);
516 const qreal inverseScale = 1.0 / triangulationScale;
518 QTriangulatingStroker stroker;
519 stroker.setInvScale(inverseScale);
521 if (pen.style() == Qt::SolidLine) {
522 stroker.process(vp, pen, clip, {});
524 QDashedStrokeProcessor dashStroker;
525 dashStroker.setInvScale(inverseScale);
526 dashStroker.process(vp, pen, clip, {});
527 QVectorPath dashStroke(dashStroker.points(), dashStroker.elementCount(),
528 dashStroker.elementTypes(), 0);
529 stroker.process(dashStroke, pen, clip, {});
532 if (!stroker.vertexCount()) {
533 strokeVertices->clear();
537 const int vertexCount = stroker.vertexCount() / 2;
538 strokeVertices->resize(vertexCount);
540 const float *vsrc = stroker.vertices();
541 for (
int i = 0; i < vertexCount; ++i)
542 vdst[i]
.set(vsrc[i * 2]
, vsrc[i * 2 + 1]
, strokeColor
);
547 if (m_rootNode != node) {
556 if (!m_rootNode || !m_accDirty)
560 if (!m_rhiBackendInitialized) {
561 auto findRHIBackend = [](QQuickItem *item) -> QRhi * {
562 if (
auto *w = item->window()) {
563 if (
auto *rhi = QQuickWindowPrivate::get(w)->rhi)
568 auto *rhi = findRHIBackend(m_item);
569 if (rhi !=
nullptr) {
570 m_rhiBackendInitialized =
true;
571 m_supportsElementIndexUint = rhi->isFeatureSupported(QRhi::ElementIndexUint);
588 for (ShapePathData &d : m_sp) {
591 *nodePtr =
new QQuickShapeGenericNode;
592 prevNode->m_next = *nodePtr;
593 prevNode->appendChildNode(*nodePtr);
596 QQuickShapeGenericNode *node = *nodePtr;
598 if (m_accDirty & DirtyList) {
599 d.effectiveDirty |= DirtyFillGeom | DirtyStrokeGeom | DirtyColor | DirtyFillGradient
600 | DirtyFillTransform | DirtyFillTexture | DirtyStrokeGradient;
603 if (!d.effectiveDirty) {
605 nodePtr = &node->m_next;
609 if (d.fillColor.a == 0) {
610 delete node->m_fillNode;
611 node->m_fillNode =
nullptr;
612 }
else if (!node->m_fillNode) {
613 node->m_fillNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
614 if (node->m_strokeNode)
615 node->removeChildNode(node->m_strokeNode);
616 node->appendChildNode(node->m_fillNode);
617 if (node->m_strokeNode)
618 node->appendChildNode(node->m_strokeNode);
619 d.effectiveDirty |= DirtyFillGeom;
622 if (d.strokeWidth <= 0.0f || d.strokeColor.a == 0) {
623 delete node->m_strokeNode;
624 node->m_strokeNode =
nullptr;
625 }
else if (!node->m_strokeNode) {
626 node->m_strokeNode =
new QQuickShapeGenericStrokeFillNode(m_item->window());
627 node->appendChildNode(node->m_strokeNode);
628 d.effectiveDirty |= DirtyStrokeGeom;
631 updateFillNode(&d, node);
632 updateStrokeNode(&d, node);
634 d.effectiveDirty = 0;
637 nodePtr = &node->m_next;
640 if (*nodePtr && prevNode) {
641 prevNode->removeChildNode(*nodePtr);
646 if (m_sp.isEmpty()) {
660 if (d->fillGradientActive) {
662 n->m_gradient = d->fillGradient;
666 bool needsUpdate = d->fillTextureProviderItem ==
nullptr && n->m_fillTextureProvider !=
nullptr;
668 && d->fillTextureProviderItem !=
nullptr
669 && n->m_fillTextureProvider != d->fillTextureProviderItem->textureProvider()) {
674 if (n->m_fillTextureProvider !=
nullptr) {
675 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
676 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
677 QObject::disconnect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
678 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
681 n->m_fillTextureProvider = d->fillTextureProviderItem ==
nullptr
683 : d->fillTextureProviderItem->textureProvider();
685 if (n->m_fillTextureProvider !=
nullptr) {
686 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::textureChanged,
687 n, &QQuickShapeGenericStrokeFillNode::handleTextureChanged);
688 QObject::connect(n->m_fillTextureProvider, &QSGTextureProvider::destroyed,
689 n, &QQuickShapeGenericStrokeFillNode::handleTextureProviderDestroyed);
694 n->m_fillTransform = d->fillTransform;
707 updateShadowDataInNode(d, n);
709 QSGGeometry *g = n->geometry();
710 if (d->fillVertices.isEmpty()) {
711 if (g->vertexCount() || g->indexCount()) {
713 n->markDirty(QSGNode::DirtyGeometry);
718 if (d->fillGradientActive) {
720 switch (d->fillGradientActive) {
727 case ConicalGradient:
731 Q_UNREACHABLE_RETURN();
733 n->activateMaterial(m_item->window(), gradMat);
736 n->markDirty(QSGNode::DirtyMaterial);
741 }
else if (d->fillTextureProviderItem !=
nullptr) {
744 n->markDirty(QSGNode::DirtyMaterial);
748 if ((d->effectiveDirty &
DirtyColor) && !(d->effectiveDirty &
DirtyFillGeom) && d->fillTextureProviderItem ==
nullptr) {
749 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
750 for (
int i = 0; i < g->vertexCount(); ++i)
752 n->markDirty(QSGNode::DirtyGeometry);
757 const int indexCount = d->indexType == QSGGeometry::UnsignedShortType
758 ? d->fillIndices.size() * 2 : d->fillIndices.size();
759 if (g->indexType() != d->indexType) {
760 g =
new QSGGeometry(QSGGeometry::defaultAttributes_ColoredPoint2D(),
761 d->fillVertices.size(), indexCount, d->indexType);
764 g->allocate(d->fillVertices.size(), indexCount);
766 g->setDrawingMode(QSGGeometry::DrawTriangles);
768 memcpy(g->vertexData(), d->fillVertices.constData(), g->vertexCount() * g->sizeOfVertex());
769 memcpy(g->indexData(), d->fillIndices.constData(), g->indexCount() * g->sizeOfIndex());
771 n->markDirty(QSGNode::DirtyGeometry);
782 if (d->strokeGradientActive) {
784 n->m_gradient = d->strokeGradient;
787 QSGGeometry *g = n->geometry();
788 if (d->strokeVertices.isEmpty()) {
789 if (g->vertexCount() || g->indexCount()) {
791 n->markDirty(QSGNode::DirtyGeometry);
796 n->markDirty(QSGNode::DirtyGeometry);
801 if (!g->vertexCount())
802 n->markDirty(QSGNode::DirtyMaterial);
804 if (d->strokeGradientActive) {
806 switch (d->strokeGradientActive) {
813 case ConicalGradient:
817 Q_UNREACHABLE_RETURN();
819 n->activateMaterial(m_item->window(), gradMat);
822 n->markDirty(QSGNode::DirtyMaterial);
830 ColoredVertex *vdst =
reinterpret_cast<ColoredVertex *>(g->vertexData());
831 for (
int i = 0; i < g->vertexCount(); ++i)
837 g->allocate(d->strokeVertices.size(), 0);
838 g->setDrawingMode(QSGGeometry::DrawTriangleStrip);
839 memcpy(g->vertexData(), d->strokeVertices.constData(), g->vertexCount() * g->sizeOfVertex());
844 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
846 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
847 return new QSGVertexColorMaterial;
849 qWarning(
"Vertex-color material: Unsupported graphics API %d", api);
856 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
858 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
861 qWarning(
"Linear gradient material: Unsupported graphics API %d", api);
868 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
870 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
873 qWarning(
"Radial gradient material: Unsupported graphics API %d", api);
880 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
882 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
885 qWarning(
"Conical gradient material: Unsupported graphics API %d", api);
892 QSGRendererInterface::GraphicsApi api = window->rendererInterface()->graphicsApi();
894 if (api == QSGRendererInterface::OpenGL || QSGRendererInterface::isApiRhiBased(api))
897 qWarning(
"Texture fill material: Unsupported graphics API %d", api);
903 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.vert.qsb"), viewCount);
904 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/lineargradient.frag.qsb"), viewCount);
908 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
910 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
912 bool changed =
false;
913 QByteArray *buf = state.uniformData();
914 Q_ASSERT(buf->size() >= 84 + 64);
915 const int shaderMatrixCount = newMaterial->viewCount();
916 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
918 if (state.isMatrixDirty()) {
919 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
920 const QMatrix4x4 m = state.combinedMatrix();
921 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
928 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
929 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
930 m_fillTransform = node->m_fillTransform;
934 if (!oldMaterial || m_gradA.x() != node->m_gradient.a.x() || m_gradA.y() != node->m_gradient.a.y()) {
935 m_gradA = QVector2D(node->m_gradient.a.x(), node->m_gradient.a.y());
936 Q_ASSERT(
sizeof(m_gradA) == 8);
937 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_gradA, 8);
941 if (!oldMaterial || m_gradB.x() != node->m_gradient.b.x() || m_gradB.y() != node->m_gradient.b.y()) {
942 m_gradB = QVector2D(node->m_gradient.b.x(), node->m_gradient.b.y());
943 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_gradB, 8);
947 if (state.isOpacityDirty()) {
948 const float opacity = state.opacity();
949 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &opacity, 4);
957 QSGMaterial *newMaterial, QSGMaterial *)
964 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
965 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
966 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
972 static QSGMaterialType type;
978 Q_ASSERT(other && type() == other->type());
987 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
988 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
990 if (
int d = ga->spread - gb->spread)
993 if (
int d = ga->a.x() - gb->a.x())
995 if (
int d = ga->a.y() - gb->a.y())
997 if (
int d = ga->b.x() - gb->b.x())
999 if (
int d = ga->b.y() - gb->b.y())
1002 if (
int d = ga->stops.size() - gb->stops.size())
1005 for (
int i = 0; i < ga->stops.size(); ++i) {
1006 if (
int d = ga->stops[i].first - gb->stops[i].first)
1008 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1012 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1020 Q_UNUSED(renderMode);
1026 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.vert.qsb"), viewCount);
1027 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/radialgradient.frag.qsb"), viewCount);
1031 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1033 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1035 bool changed =
false;
1036 QByteArray *buf = state.uniformData();
1037 Q_ASSERT(buf->size() >= 92 + 64);
1038 const int shaderMatrixCount = newMaterial->viewCount();
1039 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1041 if (state.isMatrixDirty()) {
1042 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1043 const QMatrix4x4 m = state.combinedMatrix();
1044 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1051 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1052 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1053 m_fillTransform = node->m_fillTransform;
1057 const QPointF centerPoint = node->m_gradient.a;
1058 const QPointF focalPoint = node->m_gradient.b;
1059 const QPointF focalToCenter = centerPoint - focalPoint;
1060 const float centerRadius = node->m_gradient.v0;
1061 const float focalRadius = node->m_gradient.v1;
1063 if (!oldMaterial || m_focalPoint.x() != focalPoint.x() || m_focalPoint.y() != focalPoint.y()) {
1064 m_focalPoint = QVector2D(focalPoint.x(), focalPoint.y());
1065 Q_ASSERT(
sizeof(m_focalPoint) == 8);
1066 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_focalPoint, 8);
1070 if (!oldMaterial || m_focalToCenter.x() != focalToCenter.x() || m_focalToCenter.y() != focalToCenter.y()) {
1071 m_focalToCenter = QVector2D(focalToCenter.x(), focalToCenter.y());
1072 Q_ASSERT(
sizeof(m_focalToCenter) == 8);
1073 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_focalToCenter, 8);
1077 if (!oldMaterial || m_centerRadius != centerRadius) {
1078 m_centerRadius = centerRadius;
1079 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8, &m_centerRadius, 4);
1083 if (!oldMaterial || m_focalRadius != focalRadius) {
1084 m_focalRadius = focalRadius;
1085 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4, &m_focalRadius, 4);
1089 if (state.isOpacityDirty()) {
1090 const float opacity = state.opacity();
1091 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 8 + 4 + 4, &opacity, 4);
1099 QSGMaterial *newMaterial, QSGMaterial *)
1106 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1107 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1108 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1114 static QSGMaterialType type;
1120 Q_ASSERT(other && type() == other->type());
1129 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1130 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1132 if (
int d = ga->spread - gb->spread)
1135 if (
int d = ga->a.x() - gb->a.x())
1137 if (
int d = ga->a.y() - gb->a.y())
1139 if (
int d = ga->b.x() - gb->b.x())
1141 if (
int d = ga->b.y() - gb->b.y())
1144 if (
int d = ga->v0 - gb->v0)
1146 if (
int d = ga->v1 - gb->v1)
1149 if (
int d = ga->stops.size() - gb->stops.size())
1152 for (
int i = 0; i < ga->stops.size(); ++i) {
1153 if (
int d = ga->stops[i].first - gb->stops[i].first)
1155 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1159 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1167 Q_UNUSED(renderMode);
1173 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.vert.qsb"), viewCount);
1174 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/conicalgradient.frag.qsb"), viewCount);
1178 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1180 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1182 bool changed =
false;
1183 QByteArray *buf = state.uniformData();
1184 Q_ASSERT(buf->size() >= 80 + 64);
1185 const int shaderMatrixCount = newMaterial->viewCount();
1186 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1188 if (state.isMatrixDirty()) {
1189 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1190 const QMatrix4x4 m = state.combinedMatrix();
1191 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1198 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1199 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1200 m_fillTransform = node->m_fillTransform;
1204 const QPointF centerPoint = node->m_gradient.a;
1205 const float angle = -qDegreesToRadians(node->m_gradient.v0);
1207 if (!oldMaterial || m_centerPoint.x() != centerPoint.x() || m_centerPoint.y() != centerPoint.y()) {
1208 m_centerPoint = QVector2D(centerPoint.x(), centerPoint.y());
1209 Q_ASSERT(
sizeof(m_centerPoint) == 8);
1210 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_centerPoint, 8);
1214 if (!oldMaterial || m_angle != angle) {
1216 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &m_angle, 4);
1220 if (state.isOpacityDirty()) {
1221 const float opacity = state.opacity();
1222 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8 + 4, &opacity, 4);
1230 QSGMaterial *newMaterial, QSGMaterial *)
1237 const QSGGradientCacheKey cacheKey(node->m_gradient.stops, QGradient::Spread(node->m_gradient.spread));
1238 QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
1239 t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1245 static QSGMaterialType type;
1251 Q_ASSERT(other && type() == other->type());
1260 const QSGGradientCache::GradientDesc *ga = &a->m_gradient;
1261 const QSGGradientCache::GradientDesc *gb = &b->m_gradient;
1263 if (
int d = ga->a.x() - gb->a.x())
1265 if (
int d = ga->a.y() - gb->a.y())
1268 if (
int d = ga->v0 - gb->v0)
1271 if (
int d = ga->stops.size() - gb->stops.size())
1274 for (
int i = 0; i < ga->stops.size(); ++i) {
1275 if (
int d = ga->stops[i].first - gb->stops[i].first)
1277 if (
int d = ga->stops[i].second.rgba() - gb->stops[i].second.rgba())
1281 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1289 Q_UNUSED(renderMode);
1295 setShaderFileName(VertexStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.vert.qsb"), viewCount);
1296 setShaderFileName(FragmentStage, QStringLiteral(
":/qt-project.org/shapes/shaders_ng/texturefill.frag.qsb"), viewCount);
1300 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
1302 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
1304 bool changed =
false;
1305 QByteArray *buf = state.uniformData();
1306 const int shaderMatrixCount = newMaterial->viewCount();
1307 const int matrixCount = qMin(state.projectionMatrixCount(), shaderMatrixCount);
1308 Q_ASSERT(buf->size() >= 64 * shaderMatrixCount + 64 + 8 + 4);
1310 if (state.isMatrixDirty()) {
1311 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
1312 const QMatrix4x4 m = state.combinedMatrix();
1313 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
1320 if (!oldMaterial || m_fillTransform != node->m_fillTransform) {
1321 memcpy(buf->data() + 64 * shaderMatrixCount, node->m_fillTransform.invertedData(), 64);
1322 m_fillTransform = node->m_fillTransform;
1326 const QSizeF boundsSize = node->m_fillTextureProvider !=
nullptr && node->m_fillTextureProvider->texture() !=
nullptr
1327 ? node->m_fillTextureProvider->texture()->textureSize()
1331 const QVector2D boundsVector(boundsSize.width() / state.devicePixelRatio(),
1332 boundsSize.height() / state.devicePixelRatio());
1333 if (!oldMaterial || m_boundsSize != boundsVector) {
1334 m_boundsSize = boundsVector;
1335 Q_ASSERT(
sizeof(m_boundsSize) == 8);
1336 memcpy(buf->data() + 64 * shaderMatrixCount + 64, &m_boundsSize, 8);
1340 if (state.isOpacityDirty()) {
1341 const float opacity = state.opacity();
1342 memcpy(buf->data() + 64 * shaderMatrixCount + 64 + 8, &opacity, 4);
1350 QSGMaterial *newMaterial, QSGMaterial *)
1357 if (node->m_fillTextureProvider !=
nullptr) {
1358 QSGTexture *providedTexture = node->m_fillTextureProvider->texture();
1359 if (providedTexture !=
nullptr) {
1360 if (providedTexture->isAtlasTexture()) {
1364 QSGTexture *newTexture = providedTexture->removedFromAtlas(state.resourceUpdateBatch());
1365 if (newTexture !=
nullptr)
1366 providedTexture = newTexture;
1369 providedTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1370 *texture = providedTexture;
1375 if (m->dummyTexture() ==
nullptr) {
1376 QSGPlainTexture *dummyTexture =
new QSGPlainTexture;
1377 dummyTexture->setFiltering(QSGTexture::Nearest);
1378 dummyTexture->setHorizontalWrapMode(QSGTexture::Repeat);
1379 dummyTexture->setVerticalWrapMode(QSGTexture::Repeat);
1380 QImage img(128, 128, QImage::Format_ARGB32_Premultiplied);
1382 dummyTexture->setImage(img);
1383 dummyTexture->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
1385 m->setDummyTexture(dummyTexture);
1388 *texture = m->dummyTexture();
1393 delete m_dummyTexture;
1398 static QSGMaterialType type;
1404 Q_ASSERT(other && type() == other->type());
1413 if (
int d = a->m_fillTransform.compareTo(b->m_fillTransform))
1416 const qintptr diff = qintptr(a->m_fillTextureProvider) - qintptr(b->m_fillTextureProvider);
1417 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
1422 Q_UNUSED(renderMode);
1428#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
QQuickShapeGenericRenderer::VertexContainerType fillVertices
QQuickShapeGenericRenderer::IndexContainerType fillIndices
QQuickShapeGenericStrokeFillNode * m_fillNode
QQuickShapeGenericStrokeFillNode * m_strokeNode
QQuickShapeGenericNode * m_next
void setAsyncCallback(void(*)(void *), void *) override
void setFillGradient(int index, QQuickShapeGradient *gradient) override
void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle, qreal dashOffset, const QList< qreal > &dashPattern) override
void setFillTransform(int index, const QSGTransform &transform) override
QList< quint32 > IndexContainerType
void setCosmeticStroke(int index, bool c) override
void setStrokeGradient(int index, QQuickShapeGradient *gradient) override
QList< QSGGeometry::ColoredPoint2D > VertexContainerType
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
void setFillTextureProvider(int index, QQuickItem *textureProviderItem) override
void setFillColor(int index, const QColor &color) override
void setTriangulationScale(int index, qreal scale) override
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 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
QQuickShapeGenericRenderer::VertexContainerType strokeVertices
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,...
Combined button and popup list for selecting options.
static QQuickShapeGenericRenderer::Color4ub colorToColor4ub(const QColor &c)
static QQuickAbstractPathRenderer::FillGradientType copyGenericGradient(const QQuickShapeGradient *gradient, QSGGradientCache::GradientDesc *dst)
#define QSG_RUNTIME_DESCRIPTION
void set(float nx, float ny, QQuickShapeGenericRenderer::Color4ub ncolor)