1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | // |
50 | |
51 | #ifndef QOPENGL2PEXVERTEXARRAY_P_H |
52 | #define QOPENGL2PEXVERTEXARRAY_P_H |
53 | |
54 | #include <QRectF> |
55 | |
56 | #include <private/qdatabuffer_p.h> |
57 | #include <private/qvectorpath_p.h> |
58 | #include <private/qopenglcontext_p.h> |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | class QOpenGLPoint |
63 | { |
64 | public: |
65 | QOpenGLPoint(GLfloat new_x, GLfloat new_y) : |
66 | x(new_x), y(new_y) {} |
67 | |
68 | QOpenGLPoint(const QPointF &p) : |
69 | x(p.x()), y(p.y()) {} |
70 | |
71 | QOpenGLPoint(const QPointF* p) : |
72 | x(p->x()), y(p->y()) {} |
73 | |
74 | GLfloat x; |
75 | GLfloat y; |
76 | |
77 | operator QPointF() {return QPointF(x,y);} |
78 | operator QPointF() const {return QPointF(x,y);} |
79 | }; |
80 | |
81 | struct QOpenGLRect |
82 | { |
83 | QOpenGLRect(const QRectF &r) |
84 | : left(r.left()), top(r.top()), right(r.right()), bottom(r.bottom()) {} |
85 | |
86 | QOpenGLRect(GLfloat l, GLfloat t, GLfloat r, GLfloat b) |
87 | : left(l), top(t), right(r), bottom(b) {} |
88 | |
89 | GLfloat left; |
90 | GLfloat top; |
91 | GLfloat right; |
92 | GLfloat bottom; |
93 | |
94 | operator QRectF() const {return QRectF(left, top, right-left, bottom-top);} |
95 | }; |
96 | |
97 | class QOpenGL2PEXVertexArray |
98 | { |
99 | public: |
100 | QOpenGL2PEXVertexArray() : |
101 | vertexArray(0), vertexArrayStops(0), |
102 | maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10), |
103 | boundingRectDirty(true) |
104 | { } |
105 | |
106 | inline void addRect(const QRectF &rect) |
107 | { |
108 | qreal top = rect.top(); |
109 | qreal left = rect.left(); |
110 | qreal bottom = rect.bottom(); |
111 | qreal right = rect.right(); |
112 | |
113 | vertexArray << QOpenGLPoint(left, top) |
114 | << QOpenGLPoint(right, top) |
115 | << QOpenGLPoint(right, bottom) |
116 | << QOpenGLPoint(right, bottom) |
117 | << QOpenGLPoint(left, bottom) |
118 | << QOpenGLPoint(left, top); |
119 | } |
120 | |
121 | inline void addQuad(const QRectF &rect) |
122 | { |
123 | qreal top = rect.top(); |
124 | qreal left = rect.left(); |
125 | qreal bottom = rect.bottom(); |
126 | qreal right = rect.right(); |
127 | |
128 | vertexArray << QOpenGLPoint(left, top) |
129 | << QOpenGLPoint(right, top) |
130 | << QOpenGLPoint(left, bottom) |
131 | << QOpenGLPoint(right, bottom); |
132 | |
133 | } |
134 | |
135 | inline void addVertex(const GLfloat x, const GLfloat y) |
136 | { |
137 | vertexArray.add(QOpenGLPoint(x, y)); |
138 | } |
139 | |
140 | void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline = true); |
141 | void clear(); |
142 | |
143 | QOpenGLPoint* data() {return vertexArray.data();} |
144 | int *stops() const { return vertexArrayStops.data(); } |
145 | int stopCount() const { return vertexArrayStops.size(); } |
146 | QOpenGLRect boundingRect() const; |
147 | |
148 | int vertexCount() const { return vertexArray.size(); } |
149 | |
150 | void lineToArray(const GLfloat x, const GLfloat y); |
151 | |
152 | private: |
153 | QDataBuffer<QOpenGLPoint> vertexArray; |
154 | QDataBuffer<int> vertexArrayStops; |
155 | |
156 | GLfloat maxX; |
157 | GLfloat maxY; |
158 | GLfloat minX; |
159 | GLfloat minY; |
160 | bool boundingRectDirty; |
161 | void addClosingLine(int index); |
162 | void addCentroid(const QVectorPath &path, int subPathIndex); |
163 | }; |
164 | |
165 | QT_END_NAMESPACE |
166 | |
167 | #endif |
168 | |