diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-02-17 15:36:59 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-02-17 15:36:59 (GMT) |
commit | 54b20c491f7e182f6b98f65b7e9e8e68286d6109 (patch) | |
tree | 7f17d6b2540ea226eb7d8d1b830f31f1a032316a /src/opengl/qgl.cpp | |
parent | dcb2678f39345b66c5303e74c156654a8d13fe83 (diff) | |
parent | 17a0a50a101fc9863d0dffd0dcb887ba68a99622 (diff) | |
download | Qt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.zip Qt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.tar.gz Qt-54b20c491f7e182f6b98f65b7e9e8e68286d6109.tar.bz2 |
Merge branch '4.6' into qt-master-from-4.6
Conflicts:
mkspecs/common/symbian/symbian.conf
src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
tools/assistant/tools/assistant/helpviewer.cpp
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r-- | src/opengl/qgl.cpp | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index cfcbbf8..5f5941b 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1692,18 +1692,18 @@ QGLTextureCache::QGLTextureCache() Q_ASSERT(qt_gl_texture_cache == 0); qt_gl_texture_cache = this; - QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTextures); + QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTexturesForPixampData); QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction); - QImagePixmapCleanupHooks::instance()->addImageHook(imageCleanupHook); + QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey); } QGLTextureCache::~QGLTextureCache() { qt_gl_texture_cache = 0; - QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTextures); + QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTexturesForPixampData); QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction); - QImagePixmapCleanupHooks::instance()->removeImageHook(imageCleanupHook); + QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey); } void QGLTextureCache::insert(QGLContext* ctx, qint64 key, QGLTexture* texture, int cost) @@ -1759,32 +1759,25 @@ QGLTextureCache* QGLTextureCache::instance() a hook that removes textures from the cache when a pixmap/image is deref'ed */ -void QGLTextureCache::imageCleanupHook(qint64 cacheKey) +void QGLTextureCache::cleanupTexturesForCacheKey(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) + if (qApp->thread() == QThread::currentThread()) { instance()->remove(cacheKey); + Q_ASSERT(instance()->getTexture(cacheKey) == 0); + } } -void QGLTextureCache::cleanupTextures(QPixmapData* pmd) +void QGLTextureCache::cleanupTexturesForPixampData(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); - } + cleanupTexturesForCacheKey(pmd->cacheKey()); } void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd) { // Remove any bound textures first: - cleanupTextures(pmd); + cleanupTexturesForPixampData(pmd); #if defined(Q_WS_X11) if (pmd->classId() == QPixmapData::X11Class) { @@ -2185,8 +2178,9 @@ QGLTexture *QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G // NOTE: bindTexture(const QImage&, GLenum, GLint, const qint64, bool) should never return null Q_ASSERT(texture); - if (texture->id > 0) - QImagePixmapCleanupHooks::enableCleanupHooks(image); + // Enable the cleanup hooks for this image so that the texture cache entry is removed when the + // image gets deleted: + QImagePixmapCleanupHooks::enableCleanupHooks(image); return texture; } @@ -2240,6 +2234,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G int tx_h = qt_next_power_of_two(image.height()); QImage img = image; + if (!(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0) && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height()))) @@ -2408,6 +2403,7 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G int cost = img.width()*img.height()*4/1024; QGLTexture *texture = new QGLTexture(q, tx_id, target, options); QGLTextureCache::instance()->insert(q, key, texture, cost); + return texture; } @@ -2524,7 +2520,7 @@ GLuint QGLContext::bindTexture(const QImage &image, GLenum target, GLint format) return 0; Q_D(QGLContext); - QGLTexture *texture = d->bindTexture(image, target, format, false, DefaultBindOption); + QGLTexture *texture = d->bindTexture(image, target, format, DefaultBindOption); return texture->id; } @@ -2664,11 +2660,13 @@ void QGLContext::deleteTexture(GLuint id) for (int i = 0; i < ddsKeys.size(); ++i) { GLuint texture = dds_cache->value(ddsKeys.at(i)); if (id == texture) { - glDeleteTextures(1, &texture); dds_cache->remove(ddsKeys.at(i)); - return; + break; } } + + // Finally, actually delete the texture ID + glDeleteTextures(1, &id); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS |