Qt: Simplify OpenGL context creation
Jeffrey Pfau jeffrey@endrift.com
Sat, 16 Jul 2016 23:53:40 -0700
4 files changed,
13 insertions(+),
17 deletions(-)
M
src/platform/qt/Display.cpp
→
src/platform/qt/Display.cpp
@@ -29,11 +29,13 @@
switch (s_driver) { #if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY) case Driver::OPENGL: - return new DisplayGL(format, false, parent); + format.setVersion(3, 0); + return new DisplayGL(format, parent); #endif #ifdef BUILD_GL case Driver::OPENGL1: - return new DisplayGL(format, true, parent); + format.setVersion(1, 4); + return new DisplayGL(format, parent); #endif case Driver::QT:@@ -41,7 +43,8 @@ return new DisplayQt(parent);
default: #if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY) - return new DisplayGL(format, false, parent); + format.setVersion(3, 0); + return new DisplayGL(format, parent); #else return new DisplayQt(parent); #endif
M
src/platform/qt/DisplayGL.cpp
→
src/platform/qt/DisplayGL.cpp
@@ -24,22 +24,14 @@ }
using namespace QGBA; -DisplayGL::DisplayGL(const QGLFormat& format, bool force1, QWidget* parent) +DisplayGL::DisplayGL(const QGLFormat& format, QWidget* parent) : Display(parent) , m_isDrawing(false) , m_gl(new EmptyGLWidget(format, this)) , m_drawThread(nullptr) , m_context(nullptr) { - QGLFormat::OpenGLVersionFlags versions = QGLFormat::openGLVersionFlags(); - if (force1) { - versions &= QGLFormat::OpenGL_Version_1_1 | - QGLFormat::OpenGL_Version_1_2 | - QGLFormat::OpenGL_Version_1_3 | - QGLFormat::OpenGL_Version_1_4 | - QGLFormat::OpenGL_Version_1_5; - } - m_painter = new PainterGL(m_gl, versions); + m_painter = new PainterGL(format.majorVersion(), m_gl); m_gl->setMouseTracking(true); m_gl->setAttribute(Qt::WA_TransparentForMouseEvents); // This doesn't seem to work? }@@ -179,7 +171,7 @@ QMetaObject::invokeMethod(m_painter, "resize", Qt::BlockingQueuedConnection, Q_ARG(QSize, size()));
} } -PainterGL::PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags glVersion) +PainterGL::PainterGL(int majorVersion, QGLWidget* parent) : m_gl(parent) , m_active(false) , m_started(false)@@ -196,7 +188,7 @@ mGLES2Context* gl2Backend;
#endif #if !defined(_WIN32) || defined(USE_EPOXY) - if (glVersion & (QGLFormat::OpenGL_Version_3_0 | QGLFormat::OpenGL_ES_Version_2_0)) { + if (majorVersion >= 2) { gl2Backend = new mGLES2Context; mGLES2ContextCreate(gl2Backend); m_backend = &gl2Backend->d;
M
src/platform/qt/DisplayGL.h
→
src/platform/qt/DisplayGL.h
@@ -43,7 +43,7 @@ class DisplayGL : public Display {
Q_OBJECT public: - DisplayGL(const QGLFormat& format, bool force1 = false, QWidget* parent = nullptr); + DisplayGL(const QGLFormat& format, QWidget* parent = nullptr); ~DisplayGL(); bool isDrawing() const override { return m_isDrawing; }@@ -80,7 +80,7 @@ class PainterGL : public QObject {
Q_OBJECT public: - PainterGL(QGLWidget* parent, QGLFormat::OpenGLVersionFlags = QGLFormat::OpenGL_Version_1_1); + PainterGL(int majorVersion, QGLWidget* parent); ~PainterGL(); void setContext(mCoreThread*);