Qt: Improve OpenGLES support and cleanup ifdef maze

This commit is contained in:
Vicki Pfau 2024-02-07 03:38:07 -08:00
parent 55c7c2f48e
commit c917a71ef8
3 changed files with 64 additions and 32 deletions

View File

@ -33,49 +33,33 @@ QGBA::Display* QGBA::Display::create(QWidget* parent) {
switch (s_driver) { switch (s_driver) {
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) #if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
case Driver::OPENGL: case Driver::OPENGL:
#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY) default:
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) { if (DisplayGL::highestCompatible(format)) {
format.setVersion(2, 0); return new DisplayGL(format, parent);
} else {
format.setVersion(3, 3);
} }
format.setProfile(QSurfaceFormat::CoreProfile); break;
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
#endif #endif
#ifdef BUILD_GL #ifdef BUILD_GL
case Driver::OPENGL1: case Driver::OPENGL1:
format.setVersion(1, 4); if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
if (!DisplayGL::supportsFormat(format)) { format.setVersion(1, 4);
return nullptr; } else {
format.setVersion(1, 1);
} }
return new DisplayGL(format, parent); if (DisplayGL::supportsFormat(format)) {
return new DisplayGL(format, parent);
}
break;
#endif #endif
case Driver::QT: case Driver::QT:
#if !defined(BUILD_GL) && !defined(BUILD_GLES2) && !defined(BUILD_GLES3) && !defined(USE_EPOXY)
default:
#endif
return new DisplayQt(parent); 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) QGBA::Display::Display(QWidget* parent)

View File

@ -53,6 +53,12 @@ typedef struct _XDisplay Display;
#define OVERHEAD_NSEC 300000 #define OVERHEAD_NSEC 300000
#endif #endif
// Legacy define from X11/X.h
#ifdef Unsorted
#undef Unsorted
#endif
#include "LogController.h"
#include "OpenGLBug.h" #include "OpenGLBug.h"
#include "utils.h" #include "utils.h"
@ -277,6 +283,47 @@ void DisplayGL::startDrawing(std::shared_ptr<CoreController> controller) {
QTimer::singleShot(8, this, &DisplayGL::updateContentSize); 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) { bool DisplayGL::supportsFormat(const QSurfaceFormat& format) {
if (!s_supports.contains(format)) { if (!s_supports.contains(format)) {
QOpenGLContext context; QOpenGLContext context;

View File

@ -96,6 +96,7 @@ public:
int framebufferHandle() override; int framebufferHandle() override;
QSize contentSize() const override { return m_cachedContentSize; } QSize contentSize() const override { return m_cachedContentSize; }
static bool highestCompatible(QSurfaceFormat&);
static bool supportsFormat(const QSurfaceFormat&); static bool supportsFormat(const QSurfaceFormat&);
public slots: public slots: