Skip to content

Commit

Permalink
Merge pull request #11673 from Be-ing/opengl_version
Browse files Browse the repository at this point in the history
fix OpenGL version detection
  • Loading branch information
JoergAtGithub authored Jun 24, 2023
2 parents b437a9f + adced11 commit 4b77981
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 4b77981

Please sign in to comment.