From e02d97c50cee8bdc662bb1183ed01aa0dac53f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Thu, 8 Jul 2010 17:31:16 +0200 Subject: Track the GL DCs we use across different threads under Windows. A DC returned by GetDC() is only valid within the context of the calling thread, so we need to track which tread a DC belongs to. Reviewed-by: Kim --- src/opengl/qgl.cpp | 1 + src/opengl/qgl_p.h | 1 + src/opengl/qgl_win.cpp | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 3f2af9d..05dae60 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1655,6 +1655,7 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) #if defined(Q_WS_WIN) dc = 0; win = 0; + threadId = 0; pixelFormatId = 0; cmap = 0; hbitmap = 0; diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index eca4a29..dfbc926 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -347,6 +347,7 @@ public: QGLCmap* cmap; HBITMAP hbitmap; HDC hbitmap_hdc; + Qt::HANDLE threadId; #endif #ifndef QT_NO_EGL uint ownsEglContext : 1; diff --git a/src/opengl/qgl_win.cpp b/src/opengl/qgl_win.cpp index 52988b6..3f13ac4 100644 --- a/src/opengl/qgl_win.cpp +++ b/src/opengl/qgl_win.cpp @@ -1261,6 +1261,7 @@ void QGLContext::reset() } d->dc = 0; d->win = 0; + d->threadId = 0; d->pixelFormatId = 0; d->sharing = false; d->valid = false; @@ -1283,8 +1284,9 @@ void QGLContext::makeCurrent() if (d->rc == wglGetCurrentContext() || !d->valid) // already current return; - if (d->win && !d->dc) { + if (d->win && (!d->dc || d->threadId != QThread::currentThreadId())) { d->dc = GetDC(d->win); + d->threadId = QThread::currentThreadId(); if (!d->dc) { qwglError("QGLContext::makeCurrent()", "GetDC()"); return; @@ -1322,6 +1324,7 @@ void QGLContext::doneCurrent() if (d->win && d->dc) { ReleaseDC(d->win, d->dc); d->dc = 0; + d->threadId = 0; } } -- cgit v0.12