Hi there !
I'm having trouble using a QPainter (specifically drawing QPixmap) on a QGLWidget.
Here's my setup :
I have an application with two QGLWidget sharing the same GL context (this is important).
I then use a QPainter to draw QPixmaps over the GL rendering.
Everything is fine except memory usage increases indefinitely. This won't happen if i don't call the QPainter::drawPixmap() function.
I went through Qt's code and noticed that they use a cache system maintaining GL textures associated to QPixmap. The thing is that when Qt decides to remove a GL texture from the cache, if the context used to create that texture is shared (that's true in my case) Qt won't destory the underlying GL texture (glDeleteTextures) resulting in leaving unreachable GL textures in memory.
I modified Qt's code to skip the test and it runs just fine (memory usage won't increase).
As those GL textures are internally created by Qt and as I couldn't find any function to access them, I can't do much about it ...
So I wondered if any of you had ever encountered the issue, or if I missed something, or if i did something the wrong way ...
I forgot to mention that some of the QPixmap I draw are updated quite often and that's why the cache has to delete objects.
Thanks !
PS: a few references in the code if you're interested :
the Qt's wrapper class around GL texture objects. Instance of those are being held in the cache.
file qgl.cpp, line 1288 (Qt 4.2.0 open source edition):
class QGLTexture {
public:
QGLTexture
(const QGLContext *ctx, GLuint tx_id, qint64 _qt_id,
bool _clean
= false) : context(ctx), id(tx_id), qt_id(_qt_id), clean(_clean) {}
~QGLTexture() {
if (!context->isSharing()) // <--- THERE
glDeleteTextures(1, &id);
}
GLuint id;
qint64 qt_id;
bool clean;
};
class QGLTexture {
public:
QGLTexture(const QGLContext *ctx, GLuint tx_id, qint64 _qt_id, bool _clean = false)
: context(ctx), id(tx_id), qt_id(_qt_id), clean(_clean) {}
~QGLTexture() {
if (!context->isSharing()) // <--- THERE
glDeleteTextures(1, &id);
}
const QGLContext *context;
GLuint id;
qint64 qt_id;
bool clean;
};
To copy to clipboard, switch view to plain text mode
Deleting such an object won't release the underlying GL texture if context is shared ...
Bookmarks