Commit a4e10426 authored by Volker Krause's avatar Volker Krause
Browse files

Properly extract GLSL version, in particular with OpenGL ES

parent 5997a4d6
......@@ -80,7 +80,7 @@ private slots:
QVariantMap m;
OpenGLInfoSourcePrivate::parseGLVersion(glVersion.toUtf8(), m);
QCOMPARE(m.value(QLatin1String("vendorVersion")).toString(), vendorVersion);
}
}
void testParseGLESVersion_data()
{
......@@ -105,6 +105,48 @@ private slots:
QCOMPARE(m.value(QLatin1String("version")).toString(), version);
QCOMPARE(m.value(QLatin1String("vendorVersion")).toString(), vendorVersion);
}
void testParseGLSLVersion_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("glslVersion");
QTest::newRow("empty") << QString() << QString();
QTest::newRow("default") << QStringLiteral("1.30") << QStringLiteral("1.30");
QTest::newRow("nvidia") << QStringLiteral("4.50 NVIDIA") << QStringLiteral("4.50");
}
void testParseGLSLVersion()
{
QFETCH(QString, input);
QFETCH(QString, glslVersion);
QVariantMap m;
OpenGLInfoSourcePrivate::parseGLSLVersion(input.toUtf8(), m);
QCOMPARE(m.value(QLatin1String("glslVersion")).toString(), glslVersion);
}
void testParseESGLSLVersion_data()
{
QTest::addColumn<QString>("input");
QTest::addColumn<QString>("glslVersion");
QTest::newRow("empty") << QString() << QString();
QTest::newRow("invalid") << QStringLiteral("GLSL 1.00") << QStringLiteral("GLSL 1.00");
QTest::newRow("default") << QStringLiteral("OpenGL ES GLSL ES 1.00") << QStringLiteral("1.00");
QTest::newRow("angle") << QStringLiteral("OpenGL ES GLSL ES 1.00 (ANGLE 2.1.0.8613f4946861)") << QStringLiteral("1.00");
}
void testParseESGLSLVersion()
{
QFETCH(QString, input);
QFETCH(QString, glslVersion);
QVariantMap m;
OpenGLInfoSourcePrivate::parseESGLSLVersion(input.toUtf8(), m);
QCOMPARE(m.value(QLatin1String("glslVersion")).toString(), glslVersion);
}
};
QTEST_MAIN(OpenGLInfoSourceTest)
......
......@@ -64,18 +64,18 @@ QVariant OpenGLInfoSource::data()
m.insert(QStringLiteral("version"), QString(QString::number(major) + QLatin1Char('.') + QString::number(minor)));
OpenGLInfoSourcePrivate::parseGLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_VERSION)), m);
OpenGLInfoSourcePrivate::parseGLSLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)), m);
break;
}
case QOpenGLContext::LibGLES:
{
m.insert(QStringLiteral("type"), QStringLiteral("GLES"));
OpenGLInfoSourcePrivate::parseGLESVersion(reinterpret_cast<const char*>(functions.glGetString(GL_VERSION)), m);
OpenGLInfoSourcePrivate::parseESGLSLVersion(reinterpret_cast<const char*>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION)), m);
break;
}
}
m.insert(QStringLiteral("glslVersion"), QString::fromLocal8Bit(reinterpret_cast<const char*>(functions.glGetString(GL_SHADING_LANGUAGE_VERSION))));
switch (context.format().profile()) {
case QSurfaceFormat::NoProfile:
break;
......
......@@ -57,6 +57,41 @@ public:
}
}
static inline void parseGLSLVersion(const char *version, QVariantMap &m)
{
auto v = QString::fromLocal8Bit(version);
const auto idx = v.indexOf(QLatin1Char(' '));
if (idx > 0) {
const auto glslVersion = v.left(idx);
if (!glslVersion.isEmpty())
m.insert(QStringLiteral("glslVersion"), glslVersion);
else
m.insert(QStringLiteral("glslVersion"), v);
} else {
m.insert(QStringLiteral("glslVersion"), v);
}
}
static inline void parseESGLSLVersion(const char *version, QVariantMap &m)
{
auto v = QString::fromLocal8Bit(version);
if (!v.startsWith(QLatin1String("OpenGL ES GLSL ES "))) {
m.insert(QStringLiteral("glslVersion"), v);
} else {
v = v.mid(18);
const auto idx = v.indexOf(QLatin1Char(' '));
if (idx > 0) {
const auto glslVersion = v.left(idx);
if (!glslVersion.isEmpty())
m.insert(QStringLiteral("glslVersion"), glslVersion);
else
m.insert(QStringLiteral("glslVersion"), v);
} else {
m.insert(QStringLiteral("glslVersion"), v);
}
}
}
private:
static inline QString normalizeVendorString(const QString &s)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment