Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgcurvefillnode.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// Qt-Security score:significant reason:default
4
7
9
10QSGCurveFillNode::QSGCurveFillNode()
11{
12 setFlag(OwnsGeometry, true);
13 setFlag(UsePreprocess, true);
14 setGeometry(new QSGGeometry(attributes(), 0, 0));
15
16 updateMaterial();
17}
18
19void QSGCurveFillNode::updateMaterialFlags()
20{
21 Q_ASSERT(m_material != nullptr);
22
23 const bool wasFullMatrixEnabled = m_material->flags().testFlag(QSGMaterial::RequiresFullMatrix);
24 const bool needsFullMatrixEnabled =
25 m_gradientType != QGradient::NoGradient || m_textureProvider != nullptr;
26
27 if (wasFullMatrixEnabled == needsFullMatrixEnabled)
28 return;
29
30 m_material->setFlag(QSGMaterial::RequiresFullMatrix, needsFullMatrixEnabled);
31
32 // Clearing RequiresFullMatrix also clears RequiresFullMatrixExceptTranslate, so we need
33 // to restore it.
34 if (!needsFullMatrixEnabled)
35 m_material->setFlag(QSGMaterial::RequiresFullMatrixExceptTranslate, true);
36
37 markDirty(DirtyGeometry);
38}
39
40void QSGCurveFillNode::updateMaterial()
41{
42 m_material.reset(new QSGCurveFillMaterial(this));
43 setMaterial(m_material.data());
44 updateMaterialFlags();
45}
46
47void QSGCurveFillNode::cookGeometry()
48{
49 // The batch renderer can only merge geometry with 16-bit indices, so use
50 // those whenever the vertex count allows it.
51 const QSGGeometry::Type indexType = m_uncookedVertexes.size() <= 0xffff
52 ? QSGGeometry::UnsignedShortType
53 : QSGGeometry::UnsignedIntType;
54 QSGGeometry *g = geometry();
55 if (g->indexType() != indexType) {
56 g = new QSGGeometry(attributes(),
57 m_uncookedVertexes.size(),
58 m_uncookedIndexes.size(),
59 indexType);
60 setGeometry(g);
61 } else {
62 g->allocate(m_uncookedVertexes.size(), m_uncookedIndexes.size());
63 }
64
65 g->setDrawingMode(QSGGeometry::DrawTriangles);
66 memcpy(g->vertexData(),
67 m_uncookedVertexes.constData(),
68 g->vertexCount() * g->sizeOfVertex());
69 if (indexType == QSGGeometry::UnsignedShortType) {
70 quint16 *dst = static_cast<quint16 *>(g->indexData());
71 for (qsizetype i = 0; i < m_uncookedIndexes.size(); ++i)
72 dst[i] = quint16(m_uncookedIndexes.at(i));
73 } else {
74 memcpy(g->indexData(),
75 m_uncookedIndexes.constData(),
76 g->indexCount() * g->sizeOfIndex());
77 }
78
79 m_uncookedIndexes.clear();
80 m_uncookedIndexes.squeeze();
81 m_uncookedVertexes.clear();
82 m_uncookedVertexes.squeeze();
83}
84
85const QSGGeometry::AttributeSet &QSGCurveFillNode::attributes()
86{
87 static QSGGeometry::Attribute data[] = {
88 QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType, QSGGeometry::PositionAttribute),
89 QSGGeometry::Attribute::createWithAttributeType(1, 3, QSGGeometry::FloatType, QSGGeometry::TexCoordAttribute),
90 QSGGeometry::Attribute::createWithAttributeType(2, 4, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
91 QSGGeometry::Attribute::createWithAttributeType(3, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
92 };
93 static QSGGeometry::AttributeSet attrs = { 4, sizeof(CurveNodeVertex), data };
94 return attrs;
95}
96
97QT_END_NAMESPACE
98
99#include "moc_qsgcurvefillnode_p.cpp"
Combined button and popup list for selecting options.