From 78073d6fdddf9b3675b28c2afb56a7a99bdd6dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 28 Apr 2015 18:10:29 +0200 Subject: [PATCH] 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 --- src/mbgl/geometry/glyph_atlas.cpp | 47 +++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/mbgl/geometry/glyph_atlas.cpp b/src/mbgl/geometry/glyph_atlas.cpp index 378664f30..f2978de98 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 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 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 - } };