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
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QOPENGL2PEXVERTEXARRAY_P_H
16#define QOPENGL2PEXVERTEXARRAY_P_H
17
18#include <QRectF>
19
20#include <private/qdatabuffer_p.h>
21#include <private/qvectorpath_p.h>
22#include <private/qopenglcontext_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QOpenGLPoint
27{
28public:
29 QOpenGLPoint(GLfloat new_x, GLfloat new_y) :
30 x(new_x), y(new_y) {}
31
32 QOpenGLPoint(const QPointF &p) :
33 x(p.x()), y(p.y()) {}
34
35 QOpenGLPoint(const QPointF* p) :
36 x(p->x()), y(p->y()) {}
37
38 GLfloat x;
39 GLfloat y;
40
41 operator QPointF() {return QPointF(x,y);}
42 operator QPointF() const {return QPointF(x,y);}
43};
44Q_DECLARE_TYPEINFO(QOpenGLPoint, Q_PRIMITIVE_TYPE);
45
46struct QOpenGLRect
47{
48 QOpenGLRect(const QRectF &r)
49 : left(r.left()), top(r.top()), right(r.right()), bottom(r.bottom()) {}
50
51 QOpenGLRect(GLfloat l, GLfloat t, GLfloat r, GLfloat b)
52 : left(l), top(t), right(r), bottom(b) {}
53
54 GLfloat left;
55 GLfloat top;
56 GLfloat right;
57 GLfloat bottom;
58
59 operator QRectF() const {return QRectF(left, top, right-left, bottom-top);}
60};
61Q_DECLARE_TYPEINFO(QOpenGLRect, Q_PRIMITIVE_TYPE);
62
63class QOpenGL2PEXVertexArray
64{
65public:
66 QOpenGL2PEXVertexArray() :
67 vertexArray(0), vertexArrayStops(0),
68 maxX(-2e10), maxY(-2e10), minX(2e10), minY(2e10),
69 boundingRectDirty(true)
70 { }
71
72 inline void addRect(const QRectF &rect)
73 {
74 qreal top = rect.top();
75 qreal left = rect.left();
76 qreal bottom = rect.bottom();
77 qreal right = rect.right();
78
79 vertexArray << QOpenGLPoint(left, top)
80 << QOpenGLPoint(right, top)
81 << QOpenGLPoint(right, bottom)
82 << QOpenGLPoint(right, bottom)
83 << QOpenGLPoint(left, bottom)
84 << QOpenGLPoint(left, top);
85 }
86
87 inline void addQuad(const QRectF &rect)
88 {
89 qreal top = rect.top();
90 qreal left = rect.left();
91 qreal bottom = rect.bottom();
92 qreal right = rect.right();
93
94 vertexArray << QOpenGLPoint(left, top)
95 << QOpenGLPoint(right, top)
96 << QOpenGLPoint(left, bottom)
97 << QOpenGLPoint(right, bottom);
98
99 }
100
101 inline void addVertex(const GLfloat x, const GLfloat y)
102 {
103 vertexArray.add(t: QOpenGLPoint(x, y));
104 }
105
106 void addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline = true);
107 void clear();
108
109 QOpenGLPoint* data() {return vertexArray.data();}
110 int *stops() const { return vertexArrayStops.data(); }
111 int stopCount() const { return vertexArrayStops.size(); }
112 QOpenGLRect boundingRect() const;
113
114 int vertexCount() const { return vertexArray.size(); }
115
116 void lineToArray(const GLfloat x, const GLfloat y);
117
118private:
119 QDataBuffer<QOpenGLPoint> vertexArray;
120 QDataBuffer<int> vertexArrayStops;
121
122 GLfloat maxX;
123 GLfloat maxY;
124 GLfloat minX;
125 GLfloat minY;
126 bool boundingRectDirty;
127 void addClosingLine(int index);
128 void addCentroid(const QVectorPath &path, int subPathIndex);
129};
130
131QT_END_NAMESPACE
132
133#endif
134

source code of qtbase/src/opengl/qopengl2pexvertexarray_p.h