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
62#include <QtCore/qvariant.h>
63
64QT_BEGIN_NAMESPACE
65
66class QDebug;
67class QOpenGLContextPrivate;
68class QOpenGLContextGroupPrivate;
69class QOpenGLFunctions;
70class QOpenGLExtraFunctions;
71class QPlatformOpenGLContext;
72
73class QScreen;
74class QSurface;
75
76class Q_GUI_EXPORT QOpenGLContextGroup : public QObject
77{
78 Q_OBJECT
79 Q_DECLARE_PRIVATE(QOpenGLContextGroup)
80public:
81 ~QOpenGLContextGroup();
82
83 QList<QOpenGLContext *> shares() const;
84
85 static QOpenGLContextGroup *currentContextGroup();
86
87private:
88 QOpenGLContextGroup();
89
90 friend class QOpenGLContext;
91 friend class QOpenGLContextPrivate;
92 friend class QOpenGLContextGroupResourceBase;
93 friend class QOpenGLSharedResource;
94 friend class QOpenGLMultiGroupSharedResource;
95};
96
97
98class QOpenGLTextureHelper;
99
100class Q_GUI_EXPORT QOpenGLContext : public QObject
101{
102 Q_OBJECT
103 Q_DECLARE_PRIVATE(QOpenGLContext)
104public:
105 explicit QOpenGLContext(QObject *parent = nullptr);
106 ~QOpenGLContext();
107
108 void setFormat(const QSurfaceFormat &format);
109 void setShareContext(QOpenGLContext *shareContext);
110 void setScreen(QScreen *screen);
111
112 bool create();
113 bool isValid() const;
114
115 QSurfaceFormat format() const;
116 QOpenGLContext *shareContext() const;
117 QOpenGLContextGroup *shareGroup() const;
118 QScreen *screen() const;
119
120 GLuint defaultFramebufferObject() const;
121
122 bool makeCurrent(QSurface *surface);
123 void doneCurrent();
124
125 void swapBuffers(QSurface *surface);
126 QFunctionPointer getProcAddress(const QByteArray &procName) const;
127 QFunctionPointer getProcAddress(const char *procName) const;
128
129 QSurface *surface() const;
130
131 static QOpenGLContext *currentContext();
132 static bool areSharing(QOpenGLContext *first, QOpenGLContext *second);
133
134 QPlatformOpenGLContext *handle() const;
135 QPlatformOpenGLContext *shareHandle() const;
136
137 QOpenGLFunctions *functions() const;
138 QOpenGLExtraFunctions *extraFunctions() const;
139
140 QSet<QByteArray> extensions() const;
141 bool hasExtension(const QByteArray &extension) const;
142
143 enum OpenGLModuleType {
144 LibGL,
145 LibGLES
146 };
147
148 static OpenGLModuleType openGLModuleType();
149
150 bool isOpenGLES() const;
151
152 static bool supportsThreadedOpenGL();
153 static QOpenGLContext *globalShareContext();
154
155 QT_DECLARE_NATIVE_INTERFACE_ACCESSOR
156
157Q_SIGNALS:
158 void aboutToBeDestroyed();
159
160private:
161 friend class QOpenGLContextResourceBase;
162 friend class QOpenGLPaintDevice;
163 friend class QOpenGLGlyphTexture;
164 friend class QOpenGLTextureGlyphCache;
165 friend class QOpenGLEngineShaderManager;
166 friend class QOpenGLFramebufferObject;
167 friend class QOpenGLFramebufferObjectPrivate;
168 friend class QOpenGL2PaintEngineEx;
169 friend class QOpenGL2PaintEngineExPrivate;
170 friend class QSGDistanceFieldGlyphCache;
171 friend class QWidgetPrivate;
172 friend class QAbstractOpenGLFunctionsPrivate;
173 friend class QOpenGLTexturePrivate;
174
175 QOpenGLTextureHelper* textureFunctions() const;
176 void setTextureFunctions(QOpenGLTextureHelper* textureFuncs, std::function<void()> destroyCallback);
177
178 void destroy();
179
180 Q_PRIVATE_SLOT(d_func(), void _q_screenDestroyed(QObject *object))
181};
182
183#ifndef QT_NO_DEBUG_STREAM
184Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContext *ctx);
185Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContextGroup *cg);
186#endif // !QT_NO_DEBUG_STREAM
187
188QT_END_NAMESPACE
189
190#include <QtGui/qopenglcontext_platform.h>
191
192#endif // QT_NO_OPENGL
193
194#endif // QOPENGLCONTEXT_H
195