Qt: Fix forcing 1.x when getting a 2/3 backwards-compatible context

This commit is contained in:
Vicki Pfau 2019-06-26 15:39:18 -07:00
parent 042a77a932
commit 48162e75e7
2 changed files with 10 additions and 4 deletions

View File

@ -50,14 +50,20 @@ DisplayGL::DisplayGL(const QSurfaceFormat& format, QWidget* parent)
auto version = m_gl->format().version();
QStringList extensions = QString(reinterpret_cast<const char*>(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<const char*>(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<mGLES2Context*>(malloc(sizeof(mGLES2Context)));
mGLES2ContextCreate(gl2Backend);
m_backend = &gl2Backend->d;

View File

@ -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<CoreController>);