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
This commit is contained in:
Konstantin Käfer
2015-04-28 18:10:29 +02:00
parent 72964f5bef
commit 78073d6fdd

View File

@@ -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
}
};