26std::array<QVector2D, 3> QSGCurveStrokeNode::curveABC(
const std::array<QVector2D, 3> &p)
46void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
47 const std::array<QVector2D, 3> &ctl,
48 const std::array<QVector2D, 3> &normal,
49 const std::array<
float, 3> &extrusions)
51 auto abc = curveABC(ctl);
53 int currentVertex = m_uncookedVertexes.count();
55 for (
int i = 0; i < 3; ++i) {
56 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
57 abc[0].x(), abc[0].y(), abc[1].x(), abc[1].y(), abc[2].x(), abc[2].y(),
58 normal[i].x(), normal[i].y(), extrusions[i] } );
60 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
73void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
74 const std::array<QVector2D, 2> &ctl,
75 const std::array<QVector2D, 3> &normal,
76 const std::array<
float, 3> &extrusions)
82 auto A = ctl[1] - ctl[0];
83 auto B = QVector2D(0., 0.);
86 int currentVertex = m_uncookedVertexes.count();
88 for (
int i = 0; i < 3; ++i) {
89 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
90 A.x(), A.y(), B.x(), B.y(), C.x(), C.y(),
91 normal[i].x(), normal[i].y(), extrusions[i] } );
93 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
96void QSGCurveStrokeNode::cookGeometry()
99 QSGGeometry *g = geometry();
100 if (g->indexType() != QSGGeometry::UnsignedIntType) {
101 g =
new QSGGeometry(attributes(),
102 m_uncookedVertexes.size(),
103 m_uncookedIndexes.size(),
104 QSGGeometry::UnsignedIntType);
107 g->allocate(m_uncookedVertexes.size(), m_uncookedIndexes.size());
110 g->setDrawingMode(QSGGeometry::DrawTriangles);
111 memcpy(g->vertexData(),
112 m_uncookedVertexes.constData(),
113 g->vertexCount() * g->sizeOfVertex());
114 memcpy(g->indexData(),
115 m_uncookedIndexes.constData(),
116 g->indexCount() * g->sizeOfIndex());
118 m_uncookedIndexes.clear();
119 m_uncookedIndexes.squeeze();
120 m_uncookedVertexes.clear();
121 m_uncookedVertexes.squeeze();
124const QSGGeometry::AttributeSet &QSGCurveStrokeNode::attributes()
126 static QSGGeometry::Attribute data[] = {
127 QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType, QSGGeometry::PositionAttribute),
128 QSGGeometry::Attribute::createWithAttributeType(1, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
129 QSGGeometry::Attribute::createWithAttributeType(2, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
130 QSGGeometry::Attribute::createWithAttributeType(3, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
131 QSGGeometry::Attribute::createWithAttributeType(4, 3, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
133 static QSGGeometry::AttributeSet attrs = { 5,
sizeof(StrokeVertex), data };