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 QtGui 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 <QtGui/private/qtguiglobal_p.h>
55#include <QRectF>
56
57#include <private/qdatabuffer_p.h>
58#include <private/qvectorpath_p.h>
59#include <private/qopenglcontext_p.h>
60
61QT_BEGIN_NAMESPACE
62
63class QOpenGLPoint
64{
65public:
66 QOpenGLPoint(GLfloat new_x, GLfloat new_y) :
67 x(new_x), y(new_y) {};
68
69 QOpenGLPoint(const QPointF &p) :
70 x(p.x()), y(p.y()) {};
71
72 QOpenGLPoint(const QPointF* p) :
73 x(p->x()), y(p->y()) {};
74
75 GLfloat x;
76 GLfloat y;
77
78 operator QPointF() {return QPointF(x,y);}
79 operator QPointF() const {return QPointF(x,y);}
80};
81
82struct QOpenGLRect
83{
84 QOpenGLRect(const QRectF &r)
85 : left(r.left()), top(r.top()), right(r.right()), bottom(r.bottom()) {}
86
87 QOpenGLRect(GLfloat l, GLfloat t, GLfloat r, GLfloat b)
88 : left(l), top(t), right(r), bottom(b) {}
89
90 GLfloat left;
91 GLfloat top;
92 GLfloat right;
93 GLfloat bottom;
94
95 operator QRectF() const {return QRectF(left, top, right-left, bottom-top);}
96};
97
98class QOpenGL2PEXVertexArray
99{
100public:
101 QOpenGL2PEXVertexArray() :
102 vertexArray(0), vertexArrayStops(0),
103 maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10),
104 boundingRectDirty(true)
105 { }
106
107 inline void addRect(const QRectF &rect)
108 {
109 qreal top = rect.top();
110 qreal left = rect.left();
111 qreal bottom = rect.bottom();
112 qreal right = rect.right();
113
114 vertexArray << QOpenGLPoint(left, top)
115 << QOpenGLPoint(right, top)
116 << QOpenGLPoint(right, bottom)
117 << QOpenGLPoint(right, bottom)
118 << QOpenGLPoint(left, bottom)
119 << QOpenGLPoint(left, top);
120 }
121
122 inline void addQuad(const QRectF &rect)
123 {
124 qreal top = rect.top();
125 qreal left = rect.left();
126 qreal bottom = rect.bottom();
127 qreal right = rect.right();
128
129 vertexArray << QOpenGLPoint(left, top)
130 << QOpenGLPoint(right, top)
131 << QOpenGLPoint(left, bottom)
132 << QOpenGLPoint(right, bottom);
133
134 }
135
136 inline void addVertex(const GLfloat x, const GLfloat y)
137 {
138 vertexArray.add(QOpenGLPoint(x, y));
139 }
140
141 void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline = true);
142 void clear();
143
144 QOpenGLPoint* data() {return vertexArray.data();}
145 int *stops() const { return vertexArrayStops.data(); }
146 int stopCount() const { return vertexArrayStops.size(); }
147 QOpenGLRect boundingRect() const;
148
149 int vertexCount() const { return vertexArray.size(); }
150
151 void lineToArray(const GLfloat x, const GLfloat y);
152
153private:
154 QDataBuffer<QOpenGLPoint> vertexArray;
155 QDataBuffer<int> vertexArrayStops;
156
157 GLfloat maxX;
158 GLfloat maxY;
159 GLfloat minX;
160 GLfloat minY;
161 bool boundingRectDirty;
162 void addClosingLine(int index);
163 void addCentroid(const QVectorPath &path, int subPathIndex);
164};
165
166QT_END_NAMESPACE
167
168#endif
169