31std::array<QVector2D, 3> QSGCurveStrokeNode::curveABC(
const std::array<QVector2D, 3> &p)
51void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
52 const std::array<QVector2D, 3> &ctl,
53 const std::array<QVector2D, 3> &normal,
54 const std::array<
float, 3> &extrusions)
56 auto abc = curveABC(ctl);
58 int currentVertex = m_uncookedVertexes.count();
60 for (
int i = 0; i < 3; ++i) {
61 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
62 abc[0].x(), abc[0].y(), abc[1].x(), abc[1].y(), abc[2].x(), abc[2].y(),
63 normal[i].x(), normal[i].y(), extrusions[i] } );
65 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
78void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
79 const std::array<QVector2D, 2> &ctl,
80 const std::array<QVector2D, 3> &normal,
81 const std::array<
float, 3> &extrusions)
87 auto A = ctl[1] - ctl[0];
88 auto B = QVector2D(0., 0.);
91 int currentVertex = m_uncookedVertexes.count();
93 for (
int i = 0; i < 3; ++i) {
94 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
95 A.x(), A.y(), B.x(), B.y(), C.x(), C.y(),
96 normal[i].x(), normal[i].y(), extrusions[i] } );
98 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
101void QSGCurveStrokeNode::cookGeometry()
104 QSGGeometry *g = geometry();
105 if (g->indexType() != QSGGeometry::UnsignedIntType) {
106 g =
new QSGGeometry(attributes(),
107 m_uncookedVertexes.size(),
108 m_uncookedIndexes.size(),
109 QSGGeometry::UnsignedIntType);
112 g->allocate(m_uncookedVertexes.size(), m_uncookedIndexes.size());
115 g->setDrawingMode(QSGGeometry::DrawTriangles);
116 memcpy(g->vertexData(),
117 m_uncookedVertexes.constData(),
118 g->vertexCount() * g->sizeOfVertex());
119 memcpy(g->indexData(),
120 m_uncookedIndexes.constData(),
121 g->indexCount() * g->sizeOfIndex());
123 m_uncookedIndexes.clear();
124 m_uncookedIndexes.squeeze();
125 m_uncookedVertexes.clear();
126 m_uncookedVertexes.squeeze();
129const QSGGeometry::AttributeSet &QSGCurveStrokeNode::attributes()
131 static QSGGeometry::Attribute data[] = {
132 QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType, QSGGeometry::PositionAttribute),
133 QSGGeometry::Attribute::createWithAttributeType(1, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
134 QSGGeometry::Attribute::createWithAttributeType(2, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
135 QSGGeometry::Attribute::createWithAttributeType(3, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
136 QSGGeometry::Attribute::createWithAttributeType(4, 3, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
138 static QSGGeometry::AttributeSet attrs = { 5,
sizeof(StrokeVertex), data };