| 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 QPLATFORMOPENGLCONTEXT_H |
| 5 | #define QPLATFORMOPENGLCONTEXT_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is part of the QPA API and is not meant to be used |
| 12 | // in applications. Usage of this API may make your code |
| 13 | // source and binary incompatible with future versions of Qt. |
| 14 | // |
| 15 | |
| 16 | #include <QtGui/qtguiglobal.h> |
| 17 | #include <QtCore/qnamespace.h> |
| 18 | |
| 19 | #ifndef QT_NO_OPENGL |
| 20 | |
| 21 | #include <QtGui/qsurfaceformat.h> |
| 22 | #include <QtGui/qwindow.h> |
| 23 | #include <QtGui/qopengl.h> |
| 24 | #include <QtGui/qopenglcontext.h> |
| 25 | |
| 26 | #include <QtCore/qnativeinterface.h> |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | |
| 31 | class QPlatformOpenGLContextPrivate; |
| 32 | |
| 33 | class Q_GUI_EXPORT QPlatformOpenGLContext |
| 34 | { |
| 35 | Q_DECLARE_PRIVATE(QPlatformOpenGLContext) |
| 36 | public: |
| 37 | QPlatformOpenGLContext(); |
| 38 | virtual ~QPlatformOpenGLContext(); |
| 39 | |
| 40 | virtual void initialize(); |
| 41 | |
| 42 | virtual QSurfaceFormat format() const = 0; |
| 43 | |
| 44 | virtual void swapBuffers(QPlatformSurface *surface) = 0; |
| 45 | |
| 46 | virtual GLuint defaultFramebufferObject(QPlatformSurface *surface) const; |
| 47 | |
| 48 | virtual bool makeCurrent(QPlatformSurface *surface) = 0; |
| 49 | virtual void doneCurrent() = 0; |
| 50 | |
| 51 | virtual void beginFrame(); |
| 52 | virtual void endFrame(); |
| 53 | |
| 54 | virtual bool isSharing() const { return false; } |
| 55 | virtual bool isValid() const { return true; } |
| 56 | |
| 57 | virtual QFunctionPointer getProcAddress(const char *procName) = 0; |
| 58 | |
| 59 | QOpenGLContext *context() const; |
| 60 | |
| 61 | static bool parseOpenGLVersion(const QByteArray &versionString, int &major, int &minor); |
| 62 | |
| 63 | private: |
| 64 | friend class QOpenGLContext; |
| 65 | friend class QOpenGLContextPrivate; |
| 66 | |
| 67 | QScopedPointer<QPlatformOpenGLContextPrivate> d_ptr; |
| 68 | |
| 69 | void setContext(QOpenGLContext *context); |
| 70 | |
| 71 | Q_DISABLE_COPY(QPlatformOpenGLContext) |
| 72 | }; |
| 73 | |
| 74 | namespace QNativeInterface::Private { |
| 75 | |
| 76 | #if defined(Q_OS_MACOS) |
| 77 | struct Q_GUI_EXPORT QCocoaGLIntegration |
| 78 | { |
| 79 | QT_DECLARE_NATIVE_INTERFACE(QCocoaGLIntegration) |
| 80 | virtual QOpenGLContext *createOpenGLContext(NSOpenGLContext *, QOpenGLContext *shareContext) const = 0; |
| 81 | }; |
| 82 | #endif |
| 83 | |
| 84 | #if defined(Q_OS_WIN) |
| 85 | struct Q_GUI_EXPORT QWindowsGLIntegration |
| 86 | { |
| 87 | QT_DECLARE_NATIVE_INTERFACE(QWindowsGLIntegration) |
| 88 | virtual HMODULE openGLModuleHandle() const = 0; |
| 89 | virtual QOpenGLContext *createOpenGLContext(HGLRC context, HWND window, QOpenGLContext *shareContext) const = 0; |
| 90 | }; |
| 91 | #endif |
| 92 | |
| 93 | #if QT_CONFIG(xcb_glx_plugin) |
| 94 | struct Q_GUI_EXPORT QGLXIntegration |
| 95 | { |
| 96 | QT_DECLARE_NATIVE_INTERFACE(QGLXIntegration) |
| 97 | virtual QOpenGLContext *createOpenGLContext(GLXContext context, void *visualInfo, QOpenGLContext *shareContext) const = 0; |
| 98 | }; |
| 99 | #endif |
| 100 | |
| 101 | #if QT_CONFIG(egl) |
| 102 | struct Q_GUI_EXPORT QEGLIntegration |
| 103 | { |
| 104 | QT_DECLARE_NATIVE_INTERFACE(QEGLIntegration) |
| 105 | virtual QOpenGLContext *createOpenGLContext(EGLContext context, EGLDisplay display, QOpenGLContext *shareContext) const = 0; |
| 106 | }; |
| 107 | #endif |
| 108 | |
| 109 | } // QNativeInterface::Private |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 | |
| 113 | #endif // QT_NO_OPENGL |
| 114 | |
| 115 | #endif // QPLATFORMOPENGLCONTEXT_H |
| 116 | |