diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-04-28 18:10:29 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-05-04 17:33:05 +0200 |
commit | 78073d6fdddf9b3675b28c2afb56a7a99bdd6dcf (patch) | |
tree | 948ceb2113260d0624307802e44ae624022def9f | |
parent | 72964f5bef1ed9210618ab3b02dc92c0d1cbf92c (diff) | |
download | qtlocation-mapboxgl-78073d6fdddf9b3675b28c2afb56a7a99bdd6dcf.tar.gz |
don't reallocate the Glyph atlas too often
- previously, we reallocated the glyph atlas on every upload. Instead, we're now using glTexSubImage2D to reuse the existing buffer
- we're no longer forcing a texture upload when we remove glyphs; they won't be rendered anyway
- we're now only doing a texture upload once per frame; previously, worker threads that added glyphs mid-render could trigger a texture upload while rendering is in progress
-rw-r--r-- | src/mbgl/geometry/glyph_atlas.cpp | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp index 378664f303..f2978de980 100644 --- a/src/mbgl/geometry/glyph_atlas.cpp +++ b/src/mbgl/geometry/glyph_atlas.cpp @@ -124,8 +124,6 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) { } } - dirty = true; - bin.release(rect); // Make sure to post-increment the iterator: This will return the @@ -142,7 +140,42 @@ void GlyphAtlas::removeGlyphs(uintptr_t tileUID) { void GlyphAtlas::upload() { if (dirty) { + const bool first = !texture; bind(); + + std::lock_guard<std::mutex> lock(mtx); + + if (first) { + MBGL_CHECK_ERROR(glTexImage2D( + GL_TEXTURE_2D, // GLenum target + 0, // GLint level + GL_ALPHA, // GLint internalformat + width, // GLsizei width + height, // GLsizei height + 0, // GLint border + GL_ALPHA, // GLenum format + GL_UNSIGNED_BYTE, // GLenum type + data.get() // const GLvoid* data + )); + } else { + MBGL_CHECK_ERROR(glTexSubImage2D( + GL_TEXTURE_2D, // GLenum target + 0, // GLint level + 0, // GLint xoffset + 0, // GLint yoffset + width, // GLsizei width + height, // GLsizei height + GL_ALPHA, // GLenum format + GL_UNSIGNED_BYTE, // GLenum type + data.get() // const GLvoid* data + )); + } + + dirty = false; + +#if defined(DEBUG) + // platform::showDebugImage("Glyph Atlas", data.get(), width, height); +#endif } } @@ -160,14 +193,4 @@ void GlyphAtlas::bind() { } else { MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); } - - if (dirty) { - std::lock_guard<std::mutex> lock(mtx); - MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data.get())); - dirty = false; - -#if defined(DEBUG) - // platform::showDebugImage("Glyph Atlas", data, width, height); -#endif - } }; |