From 48162e75e741743428fcbe6feca0f2f383da9806 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 26 Jun 2019 15:39:18 -0700 Subject: [PATCH] Qt: Fix forcing 1.x when getting a 2/3 backwards-compatible context --- src/platform/qt/DisplayGL.cpp | 12 +++++++++--- src/platform/qt/DisplayGL.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index ad8f7ba4f..94069c96d 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -50,14 +50,20 @@ DisplayGL::DisplayGL(const QSurfaceFormat& format, QWidget* parent) auto version = m_gl->format().version(); QStringList extensions = QString(reinterpret_cast(glGetString(GL_EXTENSIONS))).split(' '); + int forceVersion = 0; + if (format.majorVersion() < 2) { + forceVersion = 1; + } + if ((version == qMakePair(2, 1) && !extensions.contains("GL_ARB_framebuffer_object")) || version == qMakePair(2, 0)) { QSurfaceFormat newFormat(format); newFormat.setVersion(1, 4); + forceVersion = 1; m_gl->setFormat(newFormat); m_gl->create(); } - m_painter = new PainterGL(windowHandle(), m_gl); + m_painter = new PainterGL(windowHandle(), m_gl, forceVersion); setUpdatesEnabled(false); // Prevent paint events, which can cause race conditions } @@ -230,7 +236,7 @@ int DisplayGL::framebufferHandle() { return m_painter->glTex(); } -PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent) +PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion) : m_gl(parent) , m_surface(surface) { @@ -250,7 +256,7 @@ PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent) #ifdef BUILD_GLES2 auto version = m_gl->format().version(); QStringList extensions = QString(reinterpret_cast(glGetString(GL_EXTENSIONS))).split(' '); - if ((version == qMakePair(2, 1) && extensions.contains("GL_ARB_framebuffer_object")) || version.first > 2) { + if (forceVersion != 1 && ((version == qMakePair(2, 1) && extensions.contains("GL_ARB_framebuffer_object")) || version.first > 2)) { gl2Backend = static_cast(malloc(sizeof(mGLES2Context))); mGLES2ContextCreate(gl2Backend); m_backend = &gl2Backend->d; diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index 0256b32cc..40cc05b77 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -77,7 +77,7 @@ class PainterGL : public QObject { Q_OBJECT public: - PainterGL(QWindow* surface, QOpenGLContext* parent); + PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion = 0); ~PainterGL(); void setContext(std::shared_ptr);