diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2012-09-27 15:24:34 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-03 17:22:03 +0200 |
commit | 394249616cbb4c0861a032d33f846f85e2801677 (patch) | |
tree | d1b7b2b44041be92bbc47f3419866a823ed381c6 /src/plugins/platforms/windows/qwindowsglcontext.cpp | |
parent | 84100c9085ddc30368582d02a4229d44622f85e2 (diff) |
OpenGL: Don't request a context version higher than is supported
The function wglCreateContextAttribsARB will fail if we request a
context version higher than is supported. We therefore upper-bound the
requested version by the version of the static context. This results
in context creation succeeding and having the closest possible match
to the requested format.
The xcb qpa plugin is modified to operate similarly to the windows
plugin in that it now creates a "static" context which is used to
limit the versions of contexts requested by the user.
Change-Id: I277ad7cc82edfdf7b9d8502ad921c8175feb1a4a
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsglcontext.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowsglcontext.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index 45e344416d..1c9a7d36f5 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -562,12 +562,21 @@ static HGLRC createContext(const QOpenGLStaticContext &staticContext, int attributes[attribSize]; int attribIndex = 0; qFill(attributes, attributes + attribSize, int(0)); - const int requestedVersion = (format.majorVersion() << 8) + format.minorVersion(); + + // We limit the requested version by the version of the static context as + // wglCreateContextAttribsARB fails and returns NULL if the requested context + // version is not supported. This means that we will get the closest supported + // context format that that which was requested and is supported by the driver + const int requestedVersion = qMin((format.majorVersion() << 8) + format.minorVersion(), + staticContext.defaultFormat.version); + const int majorVersion = requestedVersion >> 8; + const int minorVersion = requestedVersion & 0xFF; + if (requestedVersion > 0x0101) { attributes[attribIndex++] = WGL_CONTEXT_MAJOR_VERSION_ARB; - attributes[attribIndex++] = format.majorVersion(); + attributes[attribIndex++] = majorVersion; attributes[attribIndex++] = WGL_CONTEXT_MINOR_VERSION_ARB; - attributes[attribIndex++] = format.minorVersion(); + attributes[attribIndex++] = minorVersion; } if (requestedVersion >= 0x0300) { attributes[attribIndex++] = WGL_CONTEXT_FLAGS_ARB; @@ -594,7 +603,7 @@ static HGLRC createContext(const QOpenGLStaticContext &staticContext, } if (QWindowsContext::verboseGL) qDebug("%s: Creating context version %d.%d with %d attributes", - __FUNCTION__, format.majorVersion(), format.minorVersion(), attribIndex / 2); + __FUNCTION__, majorVersion, minorVersion, attribIndex / 2); const HGLRC result = staticContext.wglCreateContextAttribsARB(hdc, shared, attributes); |