32std::array<QVector2D, 3> QSGCurveStrokeNode::curveABC(
const std::array<QVector2D, 3> &p)
52void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
53 const std::array<QVector2D, 3> &ctl,
54 const std::array<QVector2D, 3> &normal,
55 const std::array<
float, 3> &extrusions)
57 auto abc = curveABC(ctl);
59 int currentVertex = m_uncookedVertexes.count();
61 for (
int i = 0; i < 3; ++i) {
62 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
63 abc[0].x(), abc[0].y(), abc[1].x(), abc[1].y(), abc[2].x(), abc[2].y(),
64 normal[i].x(), normal[i].y(), extrusions[i] } );
66 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
79void QSGCurveStrokeNode::appendTriangle(
const std::array<QVector2D, 3> &vtx,
80 const std::array<QVector2D, 2> &ctl,
81 const std::array<QVector2D, 3> &normal,
82 const std::array<
float, 3> &extrusions)
88 auto A = ctl[1] - ctl[0];
89 auto B = QVector2D(0., 0.);
92 int currentVertex = m_uncookedVertexes.count();
94 for (
int i = 0; i < 3; ++i) {
95 m_uncookedVertexes.append( { vtx[i].x(), vtx[i].y(),
96 A.x(), A.y(), B.x(), B.y(), C.x(), C.y(),
97 normal[i].x(), normal[i].y(), extrusions[i] } );
99 m_uncookedIndexes << currentVertex << currentVertex + 1 << currentVertex + 2;
102void QSGCurveStrokeNode::cookGeometry()
105 QSGGeometry *g = geometry();
106 if (g->indexType() != QSGGeometry::UnsignedIntType) {
107 g =
new QSGGeometry(attributes(),
108 m_uncookedVertexes.size(),
109 m_uncookedIndexes.size(),
110 QSGGeometry::UnsignedIntType);
113 g->allocate(m_uncookedVertexes.size(), m_uncookedIndexes.size());
116 g->setDrawingMode(QSGGeometry::DrawTriangles);
117 memcpy(g->vertexData(),
118 m_uncookedVertexes.constData(),
119 g->vertexCount() * g->sizeOfVertex());
120 memcpy(g->indexData(),
121 m_uncookedIndexes.constData(),
122 g->indexCount() * g->sizeOfIndex());
124 m_uncookedIndexes.clear();
125 m_uncookedIndexes.squeeze();
126 m_uncookedVertexes.clear();
127 m_uncookedVertexes.squeeze();
130const QSGGeometry::AttributeSet &QSGCurveStrokeNode::attributes()
132 static QSGGeometry::Attribute data[] = {
133 QSGGeometry::Attribute::createWithAttributeType(0, 2, QSGGeometry::FloatType, QSGGeometry::PositionAttribute),
134 QSGGeometry::Attribute::createWithAttributeType(1, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
135 QSGGeometry::Attribute::createWithAttributeType(2, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
136 QSGGeometry::Attribute::createWithAttributeType(3, 2, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
137 QSGGeometry::Attribute::createWithAttributeType(4, 3, QSGGeometry::FloatType, QSGGeometry::UnknownAttribute),
139 static QSGGeometry::AttributeSet attrs = { 5,
sizeof(StrokeVertex), data };