From b81255e5da6d8835c9732a8a3d5e962c1a4b1656 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Thu, 24 Nov 2016 17:34:43 +0200 Subject: [PATCH] [qt, macos] Consume GL_INVALID_OPERATION from Qt --- platform/qt/app/mapwindow.cpp | 9 -------- platform/qt/src/qmapboxgl.cpp | 40 ++++++++++++++++----------------- platform/qt/src/qmapboxgl_p.hpp | 4 ---- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/platform/qt/app/mapwindow.cpp b/platform/qt/app/mapwindow.cpp index e8e3a1348..8b7682147 100644 --- a/platform/qt/app/mapwindow.cpp +++ b/platform/qt/app/mapwindow.cpp @@ -310,14 +310,5 @@ void MapWindow::paintGL() m_map.resize(size(), size() * pixelRatio()); -#if QT_VERSION < 0x050400 && defined(__APPLE__) - // XXX GL framebuffer is valid only after first attempt of painting on - // older versions of Qt on macOS. - // See https://bugreports.qt.io/browse/QTBUG-36802 for details. - static bool first = true; - if (!first) m_map.render(); - first = false; -#else m_map.render(); -#endif } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 67743d180..e1a8a463e 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -5,6 +5,7 @@ #include "qt_geojson.hpp" #include +#include #include #include #include @@ -798,13 +799,30 @@ void QMapboxGL::setFilter(const QString& layer_, const QVariant& filter_) #if QT_VERSION >= 0x050000 void QMapboxGL::render(QOpenGLFramebufferObject *fbo) { +#if defined(__APPLE__) + // FIXME Consume one GL_INVALID_OPERATION from Qt. + // See https://bugreports.qt.io/browse/QTBUG-36802 for details. + GLenum error = glGetError(); + if (!(error == GL_NO_ERROR || error == GL_INVALID_OPERATION)) { + throw std::runtime_error(std::string("glGetError() returned ") + std::to_string(error)); + } +#endif + d_ptr->dirty = false; - d_ptr->updateFramebufferBinding(fbo); + d_ptr->fbo = fbo; d_ptr->mapObj->render(*d_ptr); } #else void QMapboxGL::render() { +#if defined(__APPLE__) + // FIXME Qt 4.x provides an incomplete FBO at start. + // See https://bugreports.qt.io/browse/QTBUG-36802 for details. + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + return; + } +#endif + d_ptr->dirty = false; d_ptr->mapObj->render(*d_ptr); } @@ -844,21 +862,6 @@ QMapboxGLPrivate::~QMapboxGLPrivate() } #if QT_VERSION >= 0x050000 -void QMapboxGLPrivate::updateFramebufferBinding(QOpenGLFramebufferObject *fbo_) -{ - fbo = fbo_; - if (fbo) { - getContext().bindFramebuffer.setDirty(); - getContext().viewport = { - 0, 0, { static_cast(fbo->width()), static_cast(fbo->height()) } }; - } else { - getContext().bindFramebuffer.setCurrentValue(0); - assert(mbgl::gl::value::BindFramebuffer::Get() == getContext().bindFramebuffer.getCurrentValue()); - getContext().viewport = { - 0, 0, { static_cast(fbSize.width()), static_cast(fbSize.height()) } }; - } -} - void QMapboxGLPrivate::bind() { if (fbo) { fbo->bind(); @@ -866,11 +869,6 @@ void QMapboxGLPrivate::bind() { getContext().viewport = { 0, 0, { static_cast(fbo->width()), static_cast(fbo->height()) } }; - } else { - getContext().bindFramebuffer = 0; - getContext().viewport = { - 0, 0, { static_cast(fbSize.width()), static_cast(fbSize.height()) } - }; } } #else diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp index edff728dd..74ee207d0 100644 --- a/platform/qt/src/qmapboxgl_p.hpp +++ b/platform/qt/src/qmapboxgl_p.hpp @@ -31,10 +31,6 @@ public: void invalidate() final; void notifyMapChange(mbgl::MapChange) final; -#if QT_VERSION >= 0x050000 - void updateFramebufferBinding(QOpenGLFramebufferObject *); -#endif - mbgl::EdgeInsets margins; QSize size { 0, 0 }; QSize fbSize { 0, 0 };