summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2010-02-17 11:41:32 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2010-02-17 11:44:27 (GMT)
commit46e254fcde0aa70851c7c82ebef474c12cf042ef (patch)
treed7ec36ca852216060aeaded42dd1800d6d4b3c04 /src/opengl/qgl.cpp
parent364929585a1fa0243acf3a3926626bdd19143447 (diff)
downloadQt-46e254fcde0aa70851c7c82ebef474c12cf042ef.zip
Qt-46e254fcde0aa70851c7c82ebef474c12cf042ef.tar.gz
Qt-46e254fcde0aa70851c7c82ebef474c12cf042ef.tar.bz2
Some threading improvements to the GL module
- Make bindTexture threadsafe - Document which areas of QGLWidget needs locking in order to do out-of-gui thread rendering - Testcases to prove that these cases work Reviewed-by: Trond
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index cfcbbf8..f3c66f2 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -1708,6 +1708,7 @@ QGLTextureCache::~QGLTextureCache()
void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost)
{
+ QWriteLocker locker(&m_lock);
if (m_cache.totalCost() + cost > m_cache.maxCost()) {
// the cache is full - make an attempt to remove something
const QList<qint64> keys = m_cache.keys();
@@ -1725,6 +1726,7 @@ void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, i
bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId)
{
+ QWriteLocker locker(&m_lock);
QList<qint64> keys = m_cache.keys();
for (int i = 0; i < keys.size(); ++i) {
QGLTexture *tex = m_cache.object(keys.at(i));
@@ -1739,6 +1741,7 @@ bool QGLTextureCache::remove(QGLContext* ctx, GLuint textureId)
void QGLTextureCache::removeContextTextures(QGLContext* ctx)
{
+ QWriteLocker locker(&m_lock);
QList<qint64> keys = m_cache.keys();
for (int i = 0; i < keys.size(); ++i) {
const qint64 &key = keys.at(i);
@@ -1761,9 +1764,6 @@ QGLTextureCache* QGLTextureCache::instance()
*/
void QGLTextureCache::imageCleanupHook(qint64 cacheKey)
{
- // ### remove when the GL texture cache becomes thread-safe
- if (qApp->thread() != QThread::currentThread())
- return;
QGLTexture *texture = instance()->getTexture(cacheKey);
if (texture && texture->options & QGLContext::MemoryManagedBindOption)
instance()->remove(cacheKey);
@@ -1772,13 +1772,10 @@ void QGLTextureCache::imageCleanupHook(qint64 cacheKey)
void QGLTextureCache::cleanupTextures(QPixmapData* pmd)
{
- // ### remove when the GL texture cache becomes thread-safe
- if (qApp->thread() == QThread::currentThread()) {
- const qint64 cacheKey = pmd->cacheKey();
- QGLTexture *texture = instance()->getTexture(cacheKey);
- if (texture && texture->options & QGLContext::MemoryManagedBindOption)
- instance()->remove(cacheKey);
- }
+ const qint64 cacheKey = pmd->cacheKey();
+ QGLTexture *texture = instance()->getTexture(cacheKey);
+ if (texture && texture->options & QGLContext::MemoryManagedBindOption)
+ instance()->remove(cacheKey);
}
void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd)
@@ -2393,7 +2390,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G
#ifndef QT_NO_DEBUG
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
- qWarning(" - texture upload failed, error code 0x%x\n", error);
+ qWarning(" - texture upload failed, error code 0x%x, enum: %d (%x)\n", error, target, target);
}
#endif
@@ -3292,6 +3289,7 @@ void QGLContextPrivate::setCurrentContext(QGLContext *context)
*/
+
/*****************************************************************************
QGLWidget implementation
*****************************************************************************/
@@ -3412,6 +3410,15 @@ void QGLContextPrivate::setCurrentContext(QGLContext *context)
One approach to doing this is shown in the
\l{Overpainting Example}{Overpainting} example.
+ \section1 Threading
+
+ It is possible to render into a QGLWidget from another thread, but it
+ requires that all access to the GL context is safe guarded. The Qt GUI
+ thread will try to use the context in resizeEvent and paintEvent, so in
+ order for threaded rendering using a GL widget to work, these functions
+ need to be intercepted in the GUI thread and handled accordingly in the
+ application.
+
\e{OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other
countries.}