Go to the documentation of this file.
44#include <private/qbezier_p.h>
51 vertexArrayStops.reset();
52 boundingRectDirty =
true;
58 if (boundingRectDirty) {
65void QOpenGL2PEXVertexArray::addClosingLine(
int index)
67 const QPointF point(vertexArray.at(index));
68 if (point != QPointF(vertexArray.last())) {
73void QOpenGL2PEXVertexArray::addCentroid(
const QVectorPath &path,
int subPathIndex)
75 const auto *
const points =
reinterpret_cast<const QPointF *
>(path.points());
76 const QPainterPath::ElementType *
const elements = path.elements();
78 QPointF sum = points[subPathIndex];
81 for (
int i = subPathIndex + 1; i < path.elementCount() && (!elements || elements[i] != QPainterPath::MoveToElement); ++i) {
86 const QPointF centroid = sum / qreal(count);
87 vertexArray.add(QOpenGLPoint{centroid});
92 const auto*
const points =
reinterpret_cast<const QPointF*
>(path.points());
93 const QPainterPath::ElementType*
const elements = path.elements();
95 if (boundingRectDirty) {
96 minX = maxX =
static_cast<float>(points[0].x());
97 minY = maxY =
static_cast<float>(points[0].y());
98 boundingRectDirty =
false;
101 if (!outline && !path.isConvex())
102 addCentroid(path, 0);
104 int lastMoveTo =
static_cast<int>(vertexArray.size());
112 for (
int i=1; i<path.elementCount(); ++i) {
120 for (
int i=1; i<path.elementCount(); ++i) {
121 switch (elements[i]) {
122 case QPainterPath::MoveToElement:
124 addClosingLine(lastMoveTo);
126 vertexArrayStops.add(
static_cast<int>(vertexArray.size()));
128 if (!path.isConvex()) {
129 addCentroid(path, i);
131 lastMoveTo =
static_cast<int>(vertexArray.size());
135 case QPainterPath::LineToElement:
139 case QPainterPath::CurveToElement: {
140 const QBezier b = QBezier::fromPoints(*(
static_cast<const QPointF *
>(points) + i - 1),
144 const QRectF bounds = b.bounds();
147 int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14F / (curveInverseScale * 6));
148 threshold = std::max(threshold, 3);
149 const qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1);
150 for (
int t=0; t<threshold; ++t) {
151 const QPointF pt = b.pointAt(t * one_over_threshold_minus_1);
163 addClosingLine(lastMoveTo);
164 vertexArrayStops.add(
static_cast<int>(vertexArray.size()));
169 const auto x =
static_cast<float>(point.x());
170 const auto y =
static_cast<float>(point.y());
void lineToArray(QPointF point)
void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline=true)
QOpenGLRect boundingRect() const