diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 12:38:18 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 12:38:18 (GMT) |
commit | 88b1aa6b3c0e03107db111921ef69de814f1dc06 (patch) | |
tree | 9ec8e43617806429157407ceb21bd9f3026393c3 /src/opengl/gl2paintengineex | |
parent | f1815f8d19b32655597b17efad4b594466abb93b (diff) | |
download | Qt-88b1aa6b3c0e03107db111921ef69de814f1dc06.zip Qt-88b1aa6b3c0e03107db111921ef69de814f1dc06.tar.gz Qt-88b1aa6b3c0e03107db111921ef69de814f1dc06.tar.bz2 |
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.
Diffstat (limited to 'src/opengl/gl2paintengineex')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 54 |
1 files 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<GLuint> 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<GLuint> 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" |