diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index 8bec92f28..2cc7df66e 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -33,49 +33,33 @@ QGBA::Display* QGBA::Display::create(QWidget* parent) { switch (s_driver) { #if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) case Driver::OPENGL: -#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) - if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { - format.setVersion(2, 0); - } else { - format.setVersion(3, 3); + default: + if (DisplayGL::highestCompatible(format)) { + return new DisplayGL(format, parent); } - format.setProfile(QSurfaceFormat::CoreProfile); - if (DisplayGL::supportsFormat(format)) { - QSurfaceFormat::setDefaultFormat(format); - } else { -#ifdef BUILD_GL - LOG(QT, WARN) << ("Failed to create an OpenGL Core context, trying old-style..."); - format.setVersion(1, 4); - format.setOption(QSurfaceFormat::DeprecatedFunctions); - if (!DisplayGL::supportsFormat(format)) { - return nullptr; - } -#else - return nullptr; -#endif - } - return new DisplayGL(format, parent); -#endif + break; #endif #ifdef BUILD_GL case Driver::OPENGL1: - format.setVersion(1, 4); - if (!DisplayGL::supportsFormat(format)) { - return nullptr; + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(1, 4); + } else { + format.setVersion(1, 1); } - return new DisplayGL(format, parent); + if (DisplayGL::supportsFormat(format)) { + return new DisplayGL(format, parent); + } + break; #endif case Driver::QT: +#if !defined(BUILD_GL) && !defined(BUILD_GLES2) && !defined(BUILD_GLES3) && !defined(USE_EPOXY) + default: +#endif return new DisplayQt(parent); - default: -#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) - return new DisplayGL(format, parent); -#else - return new DisplayQt(parent); -#endif } + return nullptr; } QGBA::Display::Display(QWidget* parent) diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index e31437cad..3a4c3ffdd 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -53,6 +53,12 @@ typedef struct _XDisplay Display; #define OVERHEAD_NSEC 300000 #endif +// Legacy define from X11/X.h +#ifdef Unsorted +#undef Unsorted +#endif + +#include "LogController.h" #include "OpenGLBug.h" #include "utils.h" @@ -277,6 +283,47 @@ void DisplayGL::startDrawing(std::shared_ptr controller) { QTimer::singleShot(8, this, &DisplayGL::updateContentSize); } +bool DisplayGL::highestCompatible(QSurfaceFormat& format) { +#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(3, 3); + format.setProfile(QSurfaceFormat::CoreProfile); + if (DisplayGL::supportsFormat(format)) { + return true; + } + } else { +#if defined(BUILD_GLES3) || defined(USE_EPOXY) + format.setVersion(3, 1); + if (DisplayGL::supportsFormat(format)) { + return true; + } +#endif +#if defined(BUILD_GLES2) || defined(USE_EPOXY) + format.setVersion(2, 0); + if (DisplayGL::supportsFormat(format)) { + return true; + } +#endif + } +#endif + +#ifdef BUILD_GL +#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) + LOG(QT, WARN) << tr("Failed to create an OpenGL 3 context, trying old-style..."); +#endif + if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { + format.setVersion(1, 4); + } else { + format.setVersion(1, 1); + } + format.setOption(QSurfaceFormat::DeprecatedFunctions); + if (DisplayGL::supportsFormat(format)) { + return true; + } +#endif + return false; +} + bool DisplayGL::supportsFormat(const QSurfaceFormat& format) { if (!s_supports.contains(format)) { QOpenGLContext context; diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index d94a68621..71e2de597 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -96,6 +96,7 @@ public: int framebufferHandle() override; QSize contentSize() const override { return m_cachedContentSize; } + static bool highestCompatible(QSurfaceFormat&); static bool supportsFormat(const QSurfaceFormat&); public slots: