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 | #ifndef QOPENGLCONTEXT_H |
5 | #define QOPENGLCONTEXT_H |
6 | |
7 | #include <QtGui/qtguiglobal.h> |
8 | |
9 | #ifndef QT_NO_OPENGL |
10 | |
11 | #include <QtCore/qnamespace.h> |
12 | #include <QtCore/qobject.h> |
13 | #include <QtCore/qscopedpointer.h> |
14 | #include <QtCore/qset.h> |
15 | #include <QtCore/qnativeinterface.h> |
16 | |
17 | #include <QtGui/QSurfaceFormat> |
18 | |
19 | #ifdef __GLEW_H__ |
20 | #if defined(Q_CC_GNU) |
21 | #warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined |
22 | #warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h |
23 | #endif |
24 | #endif |
25 | |
26 | #include <QtGui/qopengl.h> |
27 | |
28 | #include <QtCore/qvariant.h> |
29 | |
30 | QT_BEGIN_NAMESPACE |
31 | |
32 | class QDebug; |
33 | class QOpenGLContextPrivate; |
34 | class QOpenGLContextGroupPrivate; |
35 | class QOpenGLFunctions; |
36 | class QOpenGLExtraFunctions; |
37 | class QPlatformOpenGLContext; |
38 | |
39 | class QScreen; |
40 | class QSurface; |
41 | |
42 | class Q_GUI_EXPORT QOpenGLContextGroup : public QObject |
43 | { |
44 | Q_OBJECT |
45 | Q_DECLARE_PRIVATE(QOpenGLContextGroup) |
46 | public: |
47 | ~QOpenGLContextGroup(); |
48 | |
49 | QList<QOpenGLContext *> shares() const; |
50 | |
51 | static QOpenGLContextGroup *currentContextGroup(); |
52 | |
53 | private: |
54 | QOpenGLContextGroup(); |
55 | |
56 | friend class QOpenGLContext; |
57 | friend class QOpenGLContextPrivate; |
58 | friend class QOpenGLContextGroupResourceBase; |
59 | friend class QOpenGLSharedResource; |
60 | friend class QOpenGLMultiGroupSharedResource; |
61 | }; |
62 | |
63 | |
64 | class QOpenGLTextureHelper; |
65 | |
66 | class Q_GUI_EXPORT QOpenGLContext : public QObject |
67 | { |
68 | Q_OBJECT |
69 | Q_DECLARE_PRIVATE(QOpenGLContext) |
70 | public: |
71 | explicit QOpenGLContext(QObject *parent = nullptr); |
72 | ~QOpenGLContext(); |
73 | |
74 | void setFormat(const QSurfaceFormat &format); |
75 | void setShareContext(QOpenGLContext *shareContext); |
76 | void setScreen(QScreen *screen); |
77 | |
78 | bool create(); |
79 | bool isValid() const; |
80 | |
81 | QSurfaceFormat format() const; |
82 | QOpenGLContext *shareContext() const; |
83 | QOpenGLContextGroup *shareGroup() const; |
84 | QScreen *screen() const; |
85 | |
86 | GLuint defaultFramebufferObject() const; |
87 | |
88 | bool makeCurrent(QSurface *surface); |
89 | void doneCurrent(); |
90 | |
91 | void swapBuffers(QSurface *surface); |
92 | QFunctionPointer getProcAddress(const QByteArray &procName) const; |
93 | QFunctionPointer getProcAddress(const char *procName) const; |
94 | |
95 | QSurface *surface() const; |
96 | |
97 | static QOpenGLContext *currentContext(); |
98 | static bool areSharing(QOpenGLContext *first, QOpenGLContext *second); |
99 | |
100 | QPlatformOpenGLContext *handle() const; |
101 | QPlatformOpenGLContext *shareHandle() const; |
102 | |
103 | QOpenGLFunctions *functions() const; |
104 | QOpenGLExtraFunctions *extraFunctions() const; |
105 | |
106 | QSet<QByteArray> extensions() const; |
107 | bool hasExtension(const QByteArray &extension) const; |
108 | |
109 | enum OpenGLModuleType { |
110 | LibGL, |
111 | LibGLES |
112 | }; |
113 | |
114 | static OpenGLModuleType openGLModuleType(); |
115 | |
116 | bool isOpenGLES() const; |
117 | |
118 | static bool supportsThreadedOpenGL(); |
119 | static QOpenGLContext *globalShareContext(); |
120 | |
121 | QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QOpenGLContext) |
122 | |
123 | Q_SIGNALS: |
124 | void aboutToBeDestroyed(); |
125 | |
126 | private: |
127 | friend class QOpenGLContextResourceBase; |
128 | friend class QOpenGLPaintDevice; |
129 | friend class QOpenGLGlyphTexture; |
130 | friend class QOpenGLTextureGlyphCache; |
131 | friend class QOpenGLEngineShaderManager; |
132 | friend class QOpenGLFramebufferObject; |
133 | friend class QOpenGLFramebufferObjectPrivate; |
134 | friend class QOpenGL2PaintEngineEx; |
135 | friend class QOpenGL2PaintEngineExPrivate; |
136 | friend class QSGDistanceFieldGlyphCache; |
137 | friend class QWidgetPrivate; |
138 | friend class QAbstractOpenGLFunctionsPrivate; |
139 | friend class QOpenGLTexturePrivate; |
140 | |
141 | QOpenGLTextureHelper* textureFunctions() const; |
142 | void setTextureFunctions(QOpenGLTextureHelper* textureFuncs, std::function<void()> destroyCallback); |
143 | |
144 | void destroy(); |
145 | |
146 | Q_PRIVATE_SLOT(d_func(), void _q_screenDestroyed(QObject *object)) |
147 | }; |
148 | |
149 | #ifndef QT_NO_DEBUG_STREAM |
150 | Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContext *ctx); |
151 | Q_GUI_EXPORT QDebug operator<<(QDebug debug, const QOpenGLContextGroup *cg); |
152 | #endif // !QT_NO_DEBUG_STREAM |
153 | |
154 | QT_END_NAMESPACE |
155 | |
156 | #include <QtGui/qopenglcontext_platform.h> |
157 | |
158 | #endif // QT_NO_OPENGL |
159 | |
160 | #endif // QOPENGLCONTEXT_H |
161 |