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) {
#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);
}
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
}
default:
if (DisplayGL::highestCompatible(format)) {
return new DisplayGL(format, parent);
#endif
}
break;
#endif
#ifdef BUILD_GL
case Driver::OPENGL1:
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) {
format.setVersion(1, 4);
if (!DisplayGL::supportsFormat(format)) {
return nullptr;
} else {
format.setVersion(1, 1);
}
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)

View File

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

View File

@ -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: