diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-04-09 16:49:34 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-04-16 16:47:43 +0000 |
commit | f3fad26bc9e0fde3bcf1625da731aeb02b04a7a5 (patch) | |
tree | be126a58542a181646178a4bdb4c265bb6f7421d /src | |
parent | 71e3ce7f0b671ac8bb6607d18d4fa16c6c81f737 (diff) |
Add matching by GL_VENDOR to QOpenGLConfig
This will be essential on Linux, especially Embedded where PCI IDs are
not that useful.
Change-Id: I2fa8ca07236e8aae203e21fe629d12aab092c7fd
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/opengl/qopengl.cpp | 42 | ||||
-rw-r--r-- | src/gui/opengl/qopengl_p.h | 24 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsopengltester.cpp | 5 |
3 files changed, 56 insertions, 15 deletions
diff --git a/src/gui/opengl/qopengl.cpp b/src/gui/opengl/qopengl.cpp index 61d0614724..c8d33df4ba 100644 --- a/src/gui/opengl/qopengl.cpp +++ b/src/gui/opengl/qopengl.cpp @@ -36,6 +36,7 @@ #include "qopenglcontext.h" #include "qopenglfunctions.h" +#include "qoffscreensurface.h" #include <QtCore/QDebug> #include <QtCore/QJsonDocument> @@ -89,8 +90,8 @@ QOpenGLExtensionMatcher::QOpenGLExtensionMatcher() } /* Helpers to read out the list of features matching a device from - * a Chromium driver bug list of the format using a subset of keys - * (namely, matching by gl_vendor RegExp is not implemented): + * a Chromium driver bug list. Note that not all keys are supported and + * some may behave differently: gl_vendor is a substring match instead of regex. { "entries": [ { @@ -291,14 +292,14 @@ static bool matches(const QJsonObject &object, const QJsonValue vendorV = object.value(vendorIdKey()); if (vendorV.isString()) { - if (gpu.vendorId != vendorV.toString().toUInt(Q_NULLPTR, /* base */ 0)) - return false; + if (gpu.vendorId != vendorV.toString().toUInt(Q_NULLPTR, /* base */ 0)) + return false; } else { if (object.contains(glVendorKey())) { - qWarning().nospace() << "Id " << object.value(idKey()).toInt() - << ": Matching by " << glVendorKey() << " is not implemented."; - return false; - } + const QByteArray glVendorV = object.value(glVendorKey()).toString().toUtf8(); + if (!gpu.glVendor.contains(glVendorV)) + return false; + } } if (gpu.deviceId) { @@ -447,5 +448,30 @@ QSet<QString> QOpenGLConfig::gpuFeatures(const Gpu &gpu, const QString &fileName return gpuFeatures(gpu, OsTypeTerm::hostOs(), OsTypeTerm::hostKernelVersion(), fileName); } +QOpenGLConfig::Gpu QOpenGLConfig::Gpu::fromContext() +{ + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + QScopedPointer<QOpenGLContext> tmpContext; + QScopedPointer<QOffscreenSurface> tmpSurface; + if (!ctx) { + tmpContext.reset(new QOpenGLContext); + if (!tmpContext->create()) { + qWarning("QOpenGLConfig::Gpu::fromContext: Failed to create temporary context"); + return QOpenGLConfig::Gpu(); + } + tmpSurface.reset(new QOffscreenSurface); + tmpSurface->setFormat(tmpContext->format()); + tmpSurface->create(); + tmpContext->makeCurrent(tmpSurface.data()); + } + + QOpenGLConfig::Gpu gpu; + ctx = QOpenGLContext::currentContext(); + const GLubyte *p = ctx->functions()->glGetString(GL_VENDOR); + if (p) + gpu.glVendor = QByteArray(reinterpret_cast<const char *>(p)); + + return gpu; +} QT_END_NAMESPACE diff --git a/src/gui/opengl/qopengl_p.h b/src/gui/opengl/qopengl_p.h index e04ae05120..980e02aea6 100644 --- a/src/gui/opengl/qopengl_p.h +++ b/src/gui/opengl/qopengl_p.h @@ -74,16 +74,34 @@ private: class Q_GUI_EXPORT QOpenGLConfig { public: - struct Gpu { + struct Q_GUI_EXPORT Gpu { Gpu() : vendorId(0), deviceId(0) {} - bool isValid() const { return deviceId; } + bool isValid() const { return deviceId || !glVendor.isEmpty(); } bool equals(const Gpu &other) const { - return vendorId == other.vendorId && deviceId == other.deviceId && driverVersion == other.driverVersion; + return vendorId == other.vendorId && deviceId == other.deviceId && driverVersion == other.driverVersion + && glVendor == other.glVendor; } uint vendorId; uint deviceId; QVersionNumber driverVersion; + QByteArray glVendor; + + static Gpu fromDevice(uint vendorId, uint deviceId, QVersionNumber driverVersion) { + Gpu gpu; + gpu.vendorId = vendorId; + gpu.deviceId = deviceId; + gpu.driverVersion = driverVersion; + return gpu; + } + + static Gpu fromGLVendor(const QByteArray &glVendor) { + Gpu gpu; + gpu.glVendor = glVendor; + return gpu; + } + + static Gpu fromContext(); }; static QSet<QString> gpuFeatures(const Gpu &gpu, diff --git a/src/plugins/platforms/windows/qwindowsopengltester.cpp b/src/plugins/platforms/windows/qwindowsopengltester.cpp index f5065a22b8..2e6a43f596 100644 --- a/src/plugins/platforms/windows/qwindowsopengltester.cpp +++ b/src/plugins/platforms/windows/qwindowsopengltester.cpp @@ -224,10 +224,7 @@ QWindowsOpenGLTester::Renderers QWindowsOpenGLTester::detectSupportedRenderers(c #elif defined(Q_OS_WINCE) return QWindowsOpenGLTester::Gles; #else - QOpenGLConfig::Gpu qgpu; - qgpu.deviceId = gpu.deviceId; - qgpu.vendorId = gpu.vendorId; - qgpu.driverVersion = gpu.driverVersion; + QOpenGLConfig::Gpu qgpu = QOpenGLConfig::Gpu::fromDevice(gpu.deviceId, gpu.vendorId, gpu.driverVersion); SupportedRenderersCache *srCache = supportedRenderersCache(); SupportedRenderersCache::const_iterator it = srCache->find(qgpu); if (it != srCache->cend()) |