Skip to content

Commit

Permalink
fix OpenGL version detection
Browse files Browse the repository at this point in the history
This allows OpenGL waveforms to be used with the Wayland Qt
Platform Abstraction on KDE and Weston. Though GL_MAJOR_VERSION and
GL_MINOR_VERSION reported much higher versions (4.6 when tested on
Intel UHD Graphics 770 (ADL-S GT1)), QSurfaceFormat reports 2.0 on
KDE Wayland and Weston (somehow it reports 2.1 on GNOME Wayland
though) and 2.1 with the Xcb QPA. QSurfaceFormat does not report
higher versions if they are requested in the OpenGLWindow
constructor.
  • Loading branch information
Be-ing committed Jun 22, 2023
1 parent b437a9f commit adced11
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <QGuiApplication>
#include <QOpenGLFunctions>
#include <QRegularExpression>
#include <QStringList>
#include <QTime>
#include <QWidget>
Expand Down Expand Up @@ -71,6 +72,8 @@ bool shouldRenderWaveform(WaveformWidgetAbstract* pWaveformWidget) {

return glw->shouldRender();
}

const QRegularExpression openGLVersionRegex(QStringLiteral("^(\\d+)\\.(\\d+).*$"));
} // anonymous namespace

///////////////////////////////////////////
Expand Down Expand Up @@ -142,13 +145,27 @@ WaveformWidgetFactory::WaveformWidgetFactory()
reinterpret_cast<const char*>(glFunctions->glGetString(GL_VENDOR))));
QString rendererString = QString(QLatin1String(
reinterpret_cast<const char*>(glFunctions->glGetString(GL_RENDERER))));
qDebug() << versionString << vendorString << rendererString;

// note: the requested version has been set in WGLWidget's OpenGLWindow constructor
const int majorVersion = context->surface()->format().majorVersion();
const int minorVersion = context->surface()->format().minorVersion();
qDebug().noquote() << QStringLiteral(
"OpenGL driver version string \"%1\", vendor \"%2\", "
"renderer \"%3\"")
.arg(versionString, vendorString, rendererString);

GLint majorVersion, minorVersion = GL_INVALID_ENUM;
glFunctions->glGetIntegerv(GL_MAJOR_VERSION, &majorVersion);
glFunctions->glGetIntegerv(GL_MINOR_VERSION, &minorVersion);
if (majorVersion == GL_INVALID_ENUM || minorVersion == GL_INVALID_ENUM) {
// GL_MAJOR/MINOR_VERSION are not supported below OpenGL 3.0, so
// parse GL_VERSION string as a fallback.
// https://www.khronos.org/opengl/wiki/OpenGL_Context#OpenGL_version_number
auto match = openGLVersionRegex.match(versionString);
DEBUG_ASSERT(match.hasMatch());
majorVersion = match.captured(1).toInt();
minorVersion = match.captured(2).toInt();
}

qDebug() << "QOpenGLContext surface format version:" << majorVersion << minorVersion;
qDebug().noquote()
<< QStringLiteral("Supported OpenGL version: %1.%2")
.arg(QString::number(majorVersion), QString::number(minorVersion));

m_openGLShaderAvailable = QOpenGLShaderProgram::hasOpenGLShaderPrograms(context);

Expand Down

0 comments on commit adced11

Please sign in to comment.