diff options
author | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-06-23 14:04:28 (GMT) |
---|---|---|
committer | Trond Kjernåsen <trond.kjernasen@nokia.com> | 2010-07-02 10:26:22 (GMT) |
commit | e11af338a0d0e96a8100d0e78cc42e67e1447864 (patch) | |
tree | 6fddd30e0603e0b10c2d764980870c673d5d5cc5 /src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h | |
parent | 10ac24c98ea7f2738662be91fda7feec7f322dff (diff) | |
download | Qt-e11af338a0d0e96a8100d0e78cc42e67e1447864.zip Qt-e11af338a0d0e96a8100d0e78cc42e67e1447864.tar.gz Qt-e11af338a0d0e96a8100d0e78cc42e67e1447864.tar.bz2 |
Rework how QGLTextureGlyphCache makes use of the resource system.
Separate out the GL objects (the texture and the fbo) that needs to
be tracked into a QGLGlyphTexture structure and make that accessible
via a QGLContextGroupResource object.
Diffstat (limited to 'src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h')
-rw-r--r-- | src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h index 04d1354..66aed91 100644 --- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h +++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h @@ -63,7 +63,42 @@ QT_BEGIN_NAMESPACE class QGL2PaintEngineExPrivate; -class Q_OPENGL_EXPORT QGLTextureGlyphCache : public QGLContextGroupResourceBase, public QImageTextureGlyphCache +struct QGLGlyphTexture +{ + QGLGlyphTexture(const QGLContext *ctx) + : m_width(0) + , m_height(0) + { + if (ctx && !ctx->d_ptr->workaround_brokenFBOReadBack) + glGenFramebuffers(1, &m_fbo); + +#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG + qDebug(" -> QGLGlyphTexture() %p for context %p.", this, ctx); +#endif + } + + ~QGLGlyphTexture() { + const QGLContext *ctx = QGLContext::currentContext(); +#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG + qDebug("~QGLGlyphTexture() %p for context %p.", this, ctx); +#endif + // At this point, the context group is made current, so it's safe to + // release resources without a makeCurrent() call + if (ctx) { + if (!ctx->d_ptr->workaround_brokenFBOReadBack) + glDeleteFramebuffers(1, &m_fbo); + if (m_width || m_height) + glDeleteTextures(1, &m_texture); + } + } + + GLuint m_texture; + GLuint m_fbo; + int m_width; + int m_height; +}; + +class Q_OPENGL_EXPORT QGLTextureGlyphCache : public QImageTextureGlyphCache { public: QGLTextureGlyphCache(const QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix); @@ -75,46 +110,33 @@ public: virtual int glyphMargin() const; virtual int glyphPadding() const; - inline GLuint texture() const { return m_texture; } - - inline int width() const { return m_width; } - inline int height() const { return m_height; } - - inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; } - - inline const QGLContext *context() const - { - return ctx; + inline GLuint texture() const { + QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this); + QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx); + return glyphTexture ? glyphTexture->m_texture : 0; } - void freeResource(void *) { -#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG - qDebug("Freeing glyph cache resource %p for context %p.", this, ctx); -#endif + inline int width() const { + QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this); + QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx); + return glyphTexture ? glyphTexture->m_width : 0; + } + inline int height() const { + QGLTextureGlyphCache *that = const_cast<QGLTextureGlyphCache *>(this); + QGLGlyphTexture *glyphTexture = that->m_textureResource.value(ctx); + return glyphTexture ? glyphTexture->m_height : 0; + } - // At this point, the context group is made current, so it's safe to - // release resources without a makeCurrent() call - if (!ctx->d_ptr->workaround_brokenFBOReadBack) - glDeleteFramebuffers(1, &m_fbo); + inline void setPaintEnginePrivate(QGL2PaintEngineExPrivate *p) { pex = p; } - if (m_width || m_height) - glDeleteTextures(1, &m_texture); - } + void setContext(const QGLContext *context); + inline const QGLContext *context() const { return ctx; } private: - void cleanUpContext(); + QGLContextGroupResource<QGLGlyphTexture> m_textureResource; const QGLContext *ctx; - QGL2PaintEngineExPrivate *pex; - - GLuint m_texture; - GLuint m_fbo; - - int m_width; - int m_height; - - QGLShaderProgram *m_program; }; QT_END_NAMESPACE |