From da2b3c4479e1d23ea6ead555cadc96a56967887a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 1 Sep 2014 10:43:42 +0200 Subject: Prevent current context from becoming inconsistent upon create() Platform plugins have a tendency to make the newly created native context current with a temporary surface. This is usually needed to query some information related to the new context. Afterwards most of them just reset to having nothing current. This has two issues: It unexpectedly changes the current context/surface. A call into QOpenGLContext::create() does not imply that the current context will get changed. This is the minor issue and we could probably live with it (at least if it had been documented). However, the real issue is that QOpenGLContext::currentContext() will become inconsistent: it will still report whatever was current before the create() even though on the EGL/WGL/GLX level that's not the case anymore. To prevent all this confusion the platform plugins can easily be changed to restore whatever context/surface was current before they altered it. Change-Id: I6a5b4597c86571327524ddb13e0d02538593cc7b Reviewed-by: Friedemann Kleint Reviewed-by: Gunnar Sletta --- src/plugins/platforms/windows/qwindowsglcontext.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/windows/qwindowsglcontext.cpp') diff --git a/src/plugins/platforms/windows/qwindowsglcontext.cpp b/src/plugins/platforms/windows/qwindowsglcontext.cpp index e09018ef69..1ed27f545d 100644 --- a/src/plugins/platforms/windows/qwindowsglcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsglcontext.cpp @@ -1207,6 +1207,9 @@ QWindowsGLContext::~QWindowsGLContext() bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) { + HGLRC prevContext = wglGetCurrentContext(); + HDC prevSurface = wglGetCurrentDC(); + if (!QOpenGLStaticContext::opengl32.wglMakeCurrent(hdc, m_renderingContext)) { qWarning("Failed to make context current."); return false; @@ -1217,7 +1220,7 @@ bool QWindowsGLContext::updateObtainedParams(HDC hdc, int *obtainedSwapInterval) if (m_staticContext->wglGetSwapInternalExt && obtainedSwapInterval) *obtainedSwapInterval = m_staticContext->wglGetSwapInternalExt(); - QOpenGLStaticContext::opengl32.wglMakeCurrent(0, 0); + QOpenGLStaticContext::opengl32.wglMakeCurrent(prevSurface, prevContext); return true; } -- cgit v1.2.3