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#ifndef QOPENGLCONTEXT_H
41#define QOPENGLCONTEXT_H
42
43#include <QtGui/qtguiglobal.h>
44
45#ifndef QT_NO_OPENGL
46
47#include <QtCore/qnamespace.h>
48#include <QtCore/QObject>
49#include <QtCore/QScopedPointer>
50
51#include <QtGui/QSurfaceFormat>
52
53#ifdef __GLEW_H__
54#if defined(Q_CC_GNU)
55#warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined
56#warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h
57#endif
58#endif
59
60#include <QtGui/qopengl.h>
61#include <QtGui/qopenglversionfunctions.h>
62
63#if QT_DEPRECATED_SINCE(5, 6)
64#include <QtCore/qhash.h>
65#endif
66#include <QtCore/qhashfunctions.h>
67#include <QtCore/qpair.h>
68#include <QtCore/qvariant.h>
69
70QT_BEGIN_NAMESPACE
71
72class QDebug;
73class QOpenGLContextPrivate;
74class QOpenGLContextGroupPrivate;
75class QOpenGLFunctions;
76class QOpenGLExtraFunctions;
77class QPlatformOpenGLContext;
78
79class QScreen;
80class QSurface;
81
82class QOpenGLVersionProfilePrivate;
83
84class Q_GUI_EXPORT QOpenGLVersionProfile
85{
86public:
87 QOpenGLVersionProfile();
88 explicit QOpenGLVersionProfile(const QSurfaceFormat &format);
89 QOpenGLVersionProfile(const QOpenGLVersionProfile &other);
90 ~QOpenGLVersionProfile();
91
92 QOpenGLVersionProfile &operator=(const QOpenGLVersionProfile &rhs);
93
94 QPair<int, int> version() const;
95 void setVersion(int majorVersion, int minorVersion);
96
97 QSurfaceFormat::OpenGLContextProfile profile() const;
98 void setProfile(QSurfaceFormat::OpenGLContextProfile profile);
99
100 bool hasProfiles() const;
101 bool isLegacyVersion() const;
102 bool isValid() const;
103
104private:
105 QOpenGLVersionProfilePrivate* d;
106};
107
108inline uint qHash(const QOpenGLVersionProfile &v, uint seed = 0)
109{
110 return qHash(key: static_cast<int>(v.profile() * 1000)
111 + v.version().first * 100 + v.version().second * 10, seed);
112}
113
114inline bool operator==(const QOpenGLVersionProfile &lhs, const QOpenGLVersionProfile &rhs)
115{
116 if (lhs.profile() != rhs.profile())
117 return false;
118 return lhs.version() == rhs.version();
119}
120
121inline bool operator!=(const QOpenGLVersionProfile &lhs, const QOpenGLVersionProfile &rhs)
122{
123 return !operator==(lhs, rhs);
124}
125
126class Q_GUI_EXPORT QOpenGLContextGroup : public QObject
127{
128 Q_OBJECT
129 Q_DECLARE_PRIVATE(QOpenGLContextGroup)
130public:
131 ~QOpenGLContextGroup();
132
133 QList<QOpenGLContext *> shares() const;
134
135 static QOpenGLContextGroup *currentContextGroup();
136
137private:
138 QOpenGLContextGroup();
139
140 friend class QOpenGLContext;
141 friend class QOpenGLContextGroupResourceBase;
142 friend class QOpenGLSharedResource;
143 friend class QOpenGLMultiGroupSharedResource;
144};
145
146
147class QOpenGLTextureHelper;
148
149class Q_GUI_EXPORT QOpenGLContext : public QObject
150{
151 Q_OBJECT
152 Q_DECLARE_PRIVATE(QOpenGLContext)
153public:
154 explicit QOpenGLContext(QObject *parent = nullptr);
155 ~QOpenGLContext();
156
157 void setFormat(const QSurfaceFormat &format);
158 void setShareContext(QOpenGLContext *shareContext);
159 void setScreen(QScreen *screen);
160 void setNativeHandle(const QVariant &handle);
161
162 bool create();
163 bool isValid() const;
164
165 QSurfaceFormat format() const;
166 QOpenGLContext *shareContext() const;
167 QOpenGLContextGroup *shareGroup() const;
168 QScreen *screen() const;
169 QVariant nativeHandle() const;
170
171 GLuint defaultFramebufferObject() const;
172
173 bool makeCurrent(QSurface *surface);
174 void doneCurrent();
175
176 void swapBuffers(QSurface *surface);
177 QFunctionPointer getProcAddress(const QByteArray &procName) const;
178 QFunctionPointer getProcAddress(const char *procName) const;
179
180 QSurface *surface() const;
181
182 static QOpenGLContext *currentContext();
183 static bool areSharing(QOpenGLContext *first, QOpenGLContext *second);
184
185 QPlatformOpenGLContext *handle() const;
186 QPlatformOpenGLContext *shareHandle() const;
187
188 QOpenGLFunctions *functions() const;
189 QOpenGLExtraFunctions *extraFunctions() const;
190
191 QAbstractOpenGLFunctions *versionFunctions(const QOpenGLVersionProfile &versionProfile = QOpenGLVersionProfile()) const;
192
193 template<class TYPE>
194 TYPE *versionFunctions() const
195 {
196 QOpenGLVersionProfile v = TYPE::versionProfile();
197 return static_cast<TYPE*>(versionFunctions(versionProfile: v));
198 }
199
200 QSet<QByteArray> extensions() const;
201 bool hasExtension(const QByteArray &extension) const;
202
203 static void *openGLModuleHandle();
204
205 enum OpenGLModuleType {
206 LibGL,
207 LibGLES
208 };
209
210 static OpenGLModuleType openGLModuleType();
211
212 bool isOpenGLES() const;
213
214 static bool supportsThreadedOpenGL();
215 static QOpenGLContext *globalShareContext();
216
217Q_SIGNALS:
218 void aboutToBeDestroyed();
219
220private:
221 friend class QGLContext;
222 friend class QGLPixelBuffer;
223 friend class QOpenGLContextResourceBase;
224 friend class QOpenGLPaintDevice;
225 friend class QOpenGLGlyphTexture;
226 friend class QOpenGLTextureGlyphCache;
227 friend class QOpenGLEngineShaderManager;
228 friend class QOpenGLFramebufferObject;
229 friend class QOpenGLFramebufferObjectPrivate;
230 friend class QOpenGL2PaintEngineEx;
231 friend class QOpenGL2PaintEngineExPrivate;
232 friend class QSGDistanceFieldGlyphCache;
233 friend class QWidgetPrivate;
234 friend class QAbstractOpenGLFunctionsPrivate;
235 friend class QOpenGLTexturePrivate;
236
237 void *qGLContextHandle() const;
238 void setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *));
239 void deleteQGLContext();
240
241 QOpenGLVersionFunctionsStorage* functionsBackendStorage() const;
242 void insertExternalFunctions(QAbstractOpenGLFunctions *f);
243 void removeExternalFunctions(QAbstractOpenGLFunctions *f);
244
245 QOpenGLTextureHelper* textureFunctions() const;
246 void setTextureFunctions(QOpenGLTextureHelper* textureFuncs);
247
248 void destroy();
249
250 Q_PRIVATE_SLOT(d_func(), void _q_screenDestroyed(QObject *object))
251};
252
253#ifndef QT_NO_DEBUG_STREAM
254Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLVersionProfile &vp);
255Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContext *ctx);
256Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContextGroup *cg);
257#endif // !QT_NO_DEBUG_STREAM
258
259QT_END_NAMESPACE
260
261#endif // QT_NO_OPENGL
262
263#endif // QOPENGLCONTEXT_H
264

source code of qtbase/src/gui/kernel/qopenglcontext.h