summaryrefslogtreecommitdiffstats
path: root/src/opengl/qopengltexturecache.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <[email protected]>2023-03-01 13:51:58 +0100
committerQt Cherry-pick Bot <[email protected]>2023-03-03 10:54:14 +0000
commit7aea4ff331e8f32c2ea99ff194ba670d0277af88 (patch)
treee198c9aed912519f0865d61040d7ed19601d7cac /src/opengl/qopengltexturecache.cpp
parent0a0d18303f8f20ff948f34126a027a04accca548 (diff)
Avoid incomplete textures in GL paint engine
...which can happen if the OpenGL implementation reuses IDs so that a glGenTextures results in the same ID that was used by a texture destroyed by glDeleteTextures just before. In this case the lastTextureUsed tracking needs to be aware and invalidate, otherwise the newly created texture is assumed to be already existing (the ID is the same as before after all), and so operations such as setting the minification filter is skipped (which is fatal with OpenGL given that we do not use mipmaps). This is exercised in practice by the drawPixmapFragments test introduced in the previous patch. On Intel graphics it would work, but it does not render correctly with NVIDIA due to how the driver's internal ID handling works. Change-Id: Ic2771fe9a2dec7da4aa3804d8498dd89e3c18415 Reviewed-by: Eirik Aavitsland <[email protected]> (cherry picked from commit 7cf6c57648c67bea42a54c561dc3c1616a305756) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
Diffstat (limited to 'src/opengl/qopengltexturecache.cpp')
-rw-r--r--src/opengl/qopengltexturecache.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/opengl/qopengltexturecache.cpp b/src/opengl/qopengltexturecache.cpp
index 88bd280f7a3..64583c03a97 100644
--- a/src/opengl/qopengltexturecache.cpp
+++ b/src/opengl/qopengltexturecache.cpp
@@ -81,10 +81,12 @@ QOpenGLTextureCache::~QOpenGLTextureCache()
{
}
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &pixmap, QOpenGLTextureUploader::BindOptions options)
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ const QPixmap &pixmap,
+ QOpenGLTextureUploader::BindOptions options)
{
if (pixmap.isNull())
- return 0;
+ return { 0, {} };
QMutexLocker locker(&m_mutex);
qint64 key = pixmap.cacheKey();
@@ -93,21 +95,23 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &
QOpenGLCachedTexture *entry = m_cache.object(key);
if (entry && entry->options() == options) {
context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
- return entry->id();
+ return { entry->id(), {} };
}
}
- GLuint id = bindTexture(context, key, pixmap.toImage(), options);
- if (id > 0)
+ BindResult result = bindTexture(context, key, pixmap.toImage(), options);
+ if (result.id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
- return id;
+ return result;
}
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image, QOpenGLTextureUploader::BindOptions options)
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ const QImage &image,
+ QOpenGLTextureUploader::BindOptions options)
{
if (image.isNull())
- return 0;
+ return { 0, {} };
QMutexLocker locker(&m_mutex);
qint64 key = image.cacheKey();
@@ -116,7 +120,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i
QOpenGLCachedTexture *entry = m_cache.object(key);
if (entry && entry->options() == options) {
context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
- return entry->id();
+ return { entry->id(), {} };
}
}
@@ -124,17 +128,20 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i
if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures))
options |= QOpenGLTextureUploader::PowerOfTwoBindOption;
- GLuint id = bindTexture(context, key, img, options);
- if (id > 0)
+ BindResult result = bindTexture(context, key, img, options);
+ if (result.id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(image);
- return id;
+ return result;
}
Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_entry, QOpenGLContext *context, qint64 key, const unsigned char *image, int options);
Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_exit);
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options)
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ qint64 key,
+ const QImage &image,
+ QOpenGLTextureUploader::BindOptions options)
{
Q_TRACE_SCOPE(QOpenGLTextureCache_bindTexture, context, key, image.bits(), options);
@@ -147,7 +154,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con
m_cache.insert(key, new QOpenGLCachedTexture(id, options, context), cost / 1024);
- return id;
+ return { id, BindResultFlag::NewTexture };
}
void QOpenGLTextureCache::invalidate(qint64 key)