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
4#include "qquickshapecurvenode_p.h"
5#include "qquickshapecurvenode_p_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace {
10}
11
12QQuickShapeCurveNode::QQuickShapeCurveNode()
13{
14 setFlag(OwnsGeometry, true);
15 setGeometry(new QSGGeometry(attributes(), 0, 0));
16
17 updateMaterial();
18}
19
20void QQuickShapeCurveNode::updateMaterial()
21{
22 m_material.reset(other: new QQuickShapeCurveMaterial(this));
23 setMaterial(m_material.data());
24}
25
26void QQuickShapeCurveNode::cookGeometry()
27{
28 QSGGeometry *g = geometry();
29 if (g->indexType() != QSGGeometry::UnsignedIntType) {
30 g = new QSGGeometry(attributes(),
31 m_uncookedVertexes.size(),
32 m_uncookedIndexes.size(),
33 QSGGeometry::UnsignedIntType);
34 setGeometry(g);
35 } else {
36 g->allocate(vertexCount: m_uncookedVertexes.size(), indexCount: m_uncookedIndexes.size());
37 }
38
39 g->setDrawingMode(QSGGeometry::DrawTriangles);
40 memcpy(dest: g->vertexData(),
41 src: m_uncookedVertexes.constData(),
42 n: g->vertexCount() * g->sizeOfVertex());
43 memcpy(dest: g->indexData(),
44 src: m_uncookedIndexes.constData(),
45 n: g->indexCount() * g->sizeOfIndex());
46
47 m_uncookedIndexes.clear();
48 m_uncookedVertexes.clear();
49}
50
51const QSGGeometry::AttributeSet &QQuickShapeCurveNode::attributes()
52{
53 static QSGGeometry::Attribute data[] = {
54 QSGGeometry::Attribute::createWithAttributeType(pos: 0, tupleSize: 2, primitiveType: QSGGeometry::FloatType, attributeType: QSGGeometry::PositionAttribute),
55 QSGGeometry::Attribute::createWithAttributeType(pos: 1, tupleSize: 3, primitiveType: QSGGeometry::FloatType, attributeType: QSGGeometry::TexCoordAttribute),
56 QSGGeometry::Attribute::createWithAttributeType(pos: 2, tupleSize: 4, primitiveType: QSGGeometry::FloatType, attributeType: QSGGeometry::UnknownAttribute),
57 QSGGeometry::Attribute::createWithAttributeType(pos: 3, tupleSize: 2, primitiveType: QSGGeometry::FloatType, attributeType: QSGGeometry::UnknownAttribute),
58 };
59 static QSGGeometry::AttributeSet attrs = { .count: 4, .stride: sizeof(CurveNodeVertex), .attributes: data };
60 return attrs;
61}
62
63QT_END_NAMESPACE
64

source code of qtdeclarative/src/quickshapes/qquickshapecurvenode.cpp