diff options
Diffstat (limited to 'platform/qt/src/headless_backend_qt.cpp')
-rw-r--r-- | platform/qt/src/headless_backend_qt.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/platform/qt/src/headless_backend_qt.cpp b/platform/qt/src/headless_backend_qt.cpp new file mode 100644 index 0000000000..5f95b2f96a --- /dev/null +++ b/platform/qt/src/headless_backend_qt.cpp @@ -0,0 +1,46 @@ +#include <mbgl/gl/headless_backend.hpp> + +#include <QGLWidget> + +#if QT_VERSION >= 0x050000 +#include <QOpenGLContext> +#else +#include <QGLContext> +#endif + +#include <cassert> + +namespace mbgl { + +struct QtImpl : public HeadlessBackend::Impl { + void activateContext() final { + widget.makeCurrent(); + } + + void deactivateContext() final { + widget.doneCurrent(); + } + + QGLWidget widget; +}; + +gl::ProcAddress HeadlessBackend::initializeExtension(const char* name) { +#if QT_VERSION >= 0x050000 + QOpenGLContext* thisContext = QOpenGLContext::currentContext(); + return thisContext->getProcAddress(name); +#else + const QGLContext* thisContext = QGLContext::currentContext(); + return reinterpret_cast<gl::ProcAddress>(thisContext->getProcAddress(name)); +#endif +} + +bool HeadlessBackend::hasDisplay() { + return true; +}; + +void HeadlessBackend::createContext() { + assert(!hasContext()); + impl.reset(new QtImpl); +} + +} // namespace mbgl |