Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix OpenGL version detection #11673

Merged
merged 1 commit into from
Jun 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Be-ing marked this conversation as resolved.
Show resolved Hide resolved

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