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 | #pragma once |
5 | |
6 | #include "qxcbwindow.h" |
7 | #include "qxcbscreen.h" |
8 | |
9 | #include <qpa/qplatformopenglcontext.h> |
10 | #include <qpa/qplatformoffscreensurface.h> |
11 | #include <QtGui/QSurfaceFormat> |
12 | |
13 | #include <QtCore/QMutex> |
14 | |
15 | #include <GL/glx.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QGLXContext : public QPlatformOpenGLContext, |
20 | public QNativeInterface::QGLXContext |
21 | { |
22 | public: |
23 | QGLXContext(Display *display, QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share); |
24 | QGLXContext(Display *display, GLXContext context, void *visualInfo, QPlatformOpenGLContext *share); |
25 | ~QGLXContext(); |
26 | |
27 | bool makeCurrent(QPlatformSurface *surface) override; |
28 | void doneCurrent() override; |
29 | void swapBuffers(QPlatformSurface *surface) override; |
30 | QFunctionPointer getProcAddress(const char *procName) override; |
31 | |
32 | QSurfaceFormat format() const override; |
33 | bool isSharing() const override; |
34 | bool isValid() const override; |
35 | |
36 | GLXContext nativeContext() const override { return glxContext(); } |
37 | |
38 | GLXContext glxContext() const { return m_context; } |
39 | GLXFBConfig glxConfig() const { return m_config; } |
40 | |
41 | static bool supportsThreading(); |
42 | static void queryDummyContext(); |
43 | |
44 | private: |
45 | Display *m_display = nullptr; |
46 | GLXFBConfig m_config = nullptr; |
47 | GLXContext m_context = nullptr; |
48 | GLXContext m_shareContext = nullptr; |
49 | QSurfaceFormat m_format; |
50 | bool m_isPBufferCurrent = false; |
51 | bool m_ownsContext = false; |
52 | GLenum (APIENTRY * m_getGraphicsResetStatus)() = nullptr; |
53 | bool m_lost = false; |
54 | static bool m_queriedDummyContext; |
55 | static bool m_supportsThreading; |
56 | }; |
57 | |
58 | |
59 | class QGLXPbuffer : public QPlatformOffscreenSurface |
60 | { |
61 | public: |
62 | explicit QGLXPbuffer(QOffscreenSurface *offscreenSurface); |
63 | ~QGLXPbuffer(); |
64 | |
65 | QSurfaceFormat format() const override { return m_format; } |
66 | bool isValid() const override { return m_pbuffer != 0; } |
67 | |
68 | GLXPbuffer pbuffer() const { return m_pbuffer; } |
69 | |
70 | private: |
71 | QXcbScreen *m_screen; |
72 | QSurfaceFormat m_format; |
73 | Display *m_display; |
74 | GLXPbuffer m_pbuffer; |
75 | }; |
76 | |
77 | QT_END_NAMESPACE |
78 | |