aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@nokia.com>2012-03-14 16:11:10 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-15 10:14:37 +0100
commitb634c19680cd1d4dd925a18e616844ed420d18ae (patch)
tree12048355231ce24997f2967c97301f4003ca2176 /src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
parent1c8e65a0999c81d2252757f8872c663417270d37 (diff)
Support for multiple textures in the default distance field glyph cache.
The default implementation of the distance field glyph cache can now store the glyphs of one font in several textures, allowing to cache more glyphs at once. The default maximum number of textures per cache is 3. Glyphs are recycled when all textures are full. Change-Id: I28d2d6cf5aa409141e2700b505023f15d3c2cd26 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h')
-rw-r--r--src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h59
1 files changed, 44 insertions, 15 deletions
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
index 76e4a64e60..12bbcce060 100644
--- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
+++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h
@@ -59,37 +59,55 @@ public:
void referenceGlyphs(const QSet<glyph_t> &glyphs);
void releaseGlyphs(const QSet<glyph_t> &glyphs);
- bool cacheIsFull() const { return m_textureData->currY >= maxTextureSize(); }
+ bool cacheIsFull() const {
+ return m_textureData->textures.count() == m_maxTextureCount
+ && textureIsFull(m_textureData->currentTexture);
+ }
bool useWorkaroundBrokenFBOReadback() const;
int maxTextureSize() const;
-private:
- void createTexture(int width, int height);
- void resizeTexture(int width, int height);
+ void setMaxTextureCount(int max) { m_maxTextureCount = max; }
+ int maxTextureCount() const { return m_maxTextureCount; }
+private:
mutable int m_maxTextureSize;
+ int m_maxTextureCount;
struct DistanceFieldTextureData : public QOpenGLSharedResource {
- GLuint texture;
+ struct TextureInfo {
+ GLuint texture;
+ QSize size;
+ int currX;
+ int currY;
+ QImage image;
+
+ TextureInfo() : texture(0), currX(0), currY(0)
+ { }
+ };
+
+ TextureInfo *currentTexture;
+ QList<TextureInfo> textures;
+ QHash<glyph_t, TextureInfo *> glyphsTexture;
GLuint fbo;
- QSize size;
QSet<glyph_t> unusedGlyphs;
- int currX;
- int currY;
- QImage image;
QOpenGLShaderProgram *blitProgram;
GLfloat blitVertexCoordinateArray[8];
GLfloat blitTextureCoordinateArray[8];
+ TextureInfo *addTexture()
+ {
+ textures.append(TextureInfo());
+ return &textures.last();
+ }
+
DistanceFieldTextureData(QOpenGLContext *ctx)
: QOpenGLSharedResource(ctx->shareGroup())
- , texture(0)
, fbo(0)
- , currX(0)
- , currY(0)
, blitProgram(0)
{
+ currentTexture = addTexture();
+
blitVertexCoordinateArray[0] = -1.0f;
blitVertexCoordinateArray[1] = -1.0f;
blitVertexCoordinateArray[2] = 1.0f;
@@ -111,19 +129,26 @@ private:
void invalidateResource()
{
- texture = 0;
+ glyphsTexture.clear();
+ textures.clear();
fbo = 0;
- size = QSize();
delete blitProgram;
blitProgram = 0;
+
+ currentTexture = addTexture();
}
void freeResource(QOpenGLContext *ctx)
{
- glDeleteTextures(1, &texture);
+ glyphsTexture.clear();
+ for (int i = 0; i < textures.count(); ++i)
+ glDeleteTextures(1, &textures[i].texture);
+ textures.clear();
ctx->functions()->glDeleteFramebuffers(1, &fbo);
delete blitProgram;
blitProgram = 0;
+
+ currentTexture = addTexture();
}
void createBlitProgram()
@@ -155,6 +180,10 @@ private:
}
};
+ void createTexture(DistanceFieldTextureData::TextureInfo * texInfo, int width, int height);
+ void resizeTexture(DistanceFieldTextureData::TextureInfo * texInfo, int width, int height);
+ bool textureIsFull (const DistanceFieldTextureData::TextureInfo *tex) const { return tex->currY >= maxTextureSize(); }
+
DistanceFieldTextureData *textureData(QOpenGLContext *c);
DistanceFieldTextureData *m_textureData;
static QHash<QString, QOpenGLMultiGroupSharedResource> m_textures_data;