Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qopengl2pexvertexarray.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
5
6#include <private/qbezier_p.h>
7
9
11{
12 vertexArray.reset();
13 vertexArrayStops.reset();
14 boundingRectDirty = true;
15}
16
17
19{
20 if (boundingRectDirty)
21 return QOpenGLRect(0.0, 0.0, 0.0, 0.0);
22 else
23 return QOpenGLRect(minX, minY, maxX, maxY);
24}
25
26void QOpenGL2PEXVertexArray::addClosingLine(int index)
27{
28 QPointF point(vertexArray.at(index));
29 if (point != QPointF(vertexArray.last()))
30 vertexArray.add(point);
31}
32
33void QOpenGL2PEXVertexArray::addCentroid(const QVectorPath &path, int subPathIndex)
34{
35 const QPointF *const points = reinterpret_cast<const QPointF *>(path.points());
36 const QPainterPath::ElementType *const elements = path.elements();
37
38 QPointF sum = points[subPathIndex];
39 int count = 1;
40
41 for (int i = subPathIndex + 1; i < path.elementCount() && (!elements || elements[i] != QPainterPath::MoveToElement); ++i) {
42 sum += points[i];
43 ++count;
44 }
45
46 const QPointF centroid = sum / qreal(count);
47 vertexArray.add(centroid);
48}
49
50void QOpenGL2PEXVertexArray::addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline)
51{
52 const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
53 const QPainterPath::ElementType* const elements = path.elements();
54
55 if (boundingRectDirty) {
56 minX = maxX = points[0].x();
57 minY = maxY = points[0].y();
58 boundingRectDirty = false;
59 }
60
61 if (!outline && !path.isConvex())
62 addCentroid(path, 0);
63
64 int lastMoveTo = vertexArray.size();
65 vertexArray.add(points[0]); // The first element is always a moveTo
66
67 do {
68 if (!elements) {
69// qDebug("QVectorPath has no elements");
70 // If the path has a null elements pointer, the elements implicitly
71 // start with a moveTo (already added) and continue with lineTos:
72 for (int i=1; i<path.elementCount(); ++i)
73 lineToArray(points[i].x(), points[i].y());
74
75 break;
76 }
77// qDebug("QVectorPath has element types");
78
79 for (int i=1; i<path.elementCount(); ++i) {
80 switch (elements[i]) {
82 if (!outline)
83 addClosingLine(lastMoveTo);
84// qDebug("element[%d] is a MoveToElement", i);
85 vertexArrayStops.add(vertexArray.size());
86 if (!outline) {
87 if (!path.isConvex()) addCentroid(path, i);
88 lastMoveTo = vertexArray.size();
89 }
90 lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex
91 break;
93// qDebug("element[%d] is a LineToElement", i);
94 lineToArray(points[i].x(), points[i].y());
95 break;
97 QBezier b = QBezier::fromPoints(*(((const QPointF *) points) + i - 1),
98 points[i],
99 points[i+1],
100 points[i+2]);
101 QRectF bounds = b.bounds();
102 // threshold based on same algorithm as in qtriangulatingstroker.cpp
103 int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14f / (curveInverseScale * 6));
104 if (threshold < 3) threshold = 3;
105 qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1);
106 for (int t=0; t<threshold; ++t) {
107 QPointF pt = b.pointAt(t * one_over_threshold_minus_1);
108 lineToArray(pt.x(), pt.y());
109 }
110 i += 2;
111 break; }
112 default:
113 break;
114 }
115 }
116 } while (0);
117
118 if (!outline)
119 addClosingLine(lastMoveTo);
120 vertexArrayStops.add(vertexArray.size());
121}
122
124{
125 vertexArray.add(QOpenGLPoint(x, y));
126
127 if (x > maxX)
128 maxX = x;
129 else if (x < minX)
130 minX = x;
131 if (y > maxY)
132 maxY = y;
133 else if (y < minY)
134 minY = y;
135}
136
static QBezier fromPoints(const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &p4)
Definition qbezier_p.h:33
void add(const Type &t)
Type & at(qsizetype i)
qsizetype size() const
Type & last()
void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline=true)
void lineToArray(const GLfloat x, const GLfloat y)
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
Combined button and popup list for selecting options.
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
typedef GLfloat(GL_APIENTRYP PFNGLGETPATHLENGTHNVPROC)(GLuint path
GLfloat GLfloat GLfloat GLfloat GLfloat maxY
GLuint index
[2]
GLenum GLenum GLsizei count
GLfloat minY
GLint y
GLfloat GLfloat GLfloat GLfloat maxX
GLfixed GLfixed GLint GLint GLfixed points
GLdouble GLdouble t
Definition qopenglext.h:243
GLsizei const GLchar *const * path
static const QTextHtmlElement elements[Html_NumElements]
double qreal
Definition qtypes.h:187