From 88b1aa6b3c0e03107db111921ef69de814f1dc06 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 5 Feb 2010 13:38:18 +0100 Subject: Clean up VBOs cached in QStaticText when context is deleted Follow pattern from qpaintengine_opengl.cpp and listen for the destroyed signal of the GL context. If the context that owns the VBOs is deleted, then we delete the VBOs as well. --- .../gl2paintengineex/qpaintengineex_opengl2.cpp | 54 ++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 917a1a2..c66472c 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1281,32 +1281,48 @@ void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem #define QSTATICTEXT_USE_INDEXARRAY -namespace { +class QOpenGLStaticTextUserData: public QObject, public QStaticTextUserData +{ + Q_OBJECT +public: + QOpenGLStaticTextUserData(QGLContext *glContext) + : QStaticTextUserData(OpenGLUserData), + vertexCoordVBOId(0), textureCoordVBOId(0), ctx(glContext) + { + connect(QGLSignalProxy::instance(), + SIGNAL(aboutToDestroyContext(const QGLContext*)), + SLOT(cleanupGLContextRefs(const QGLContext*))); + } - class QOpenGLStaticTextUserData: public QStaticTextUserData + ~QOpenGLStaticTextUserData() { - public: - QOpenGLStaticTextUserData(QGLContext *glContext) - : QStaticTextUserData(OpenGLUserData), - vertexCoordVBOId(0), textureCoordVBOId(0), ctx(glContext) {} - ~QOpenGLStaticTextUserData() - { + if (ctx != 0) + cleanupGLContextRefs(ctx); + } + + QGLContext *ctx; + GLuint vertexCoordVBOId; + GLuint textureCoordVBOId; + +#if defined(QSTATICTEXT_USE_INDEXARRAY) + QVector indices; +#endif + +public Q_SLOTS: + void cleanupGLContextRefs(const QGLContext *context) + { + if (context == ctx) { if (vertexCoordVBOId != 0) glDeleteBuffers(1, &vertexCoordVBOId); if (textureCoordVBOId != 0) glDeleteBuffers(1, &textureCoordVBOId); - } - - QGLContext *ctx; - GLuint vertexCoordVBOId; - GLuint textureCoordVBOId; -#if defined(QSTATICTEXT_USE_INDEXARRAY) - QVector indices; -#endif - }; -} + vertexCoordVBOId = 0; + textureCoordVBOId = 0; + } + } +}; void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem, @@ -2175,3 +2191,5 @@ QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState() } QT_END_NAMESPACE + +#include "qpaintengineex_opengl2.moc" -- cgit v0.12