diff --git a/src/geometry/glyph_atlas.cpp b/src/geometry/glyph_atlas.cpp index 50524f018..9e74e21b2 100644 --- a/src/geometry/glyph_atlas.cpp +++ b/src/geometry/glyph_atlas.cpp @@ -122,10 +122,36 @@ void GlyphAtlas::removeGlyphs(uint64_t tile_id) { void GlyphAtlas::upload() { if (dirty) { + const bool exists = texture; bind(); std::lock_guard lock(mtx); - glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); + + if (!exists) { + 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 // const GLvoid * data + ); + } else { + 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 // const GLvoid *pixels + ); + } dirty = false; #if defined(DEBUG) diff --git a/src/geometry/sprite_atlas.cpp b/src/geometry/sprite_atlas.cpp index 3d7c1ecd0..730551dbe 100644 --- a/src/geometry/sprite_atlas.cpp +++ b/src/geometry/sprite_atlas.cpp @@ -215,7 +215,7 @@ void SpriteAtlas::bind(bool linear) { void SpriteAtlas::upload() { if (dirty) { - bool exists = texture; + const bool exists = texture; bind(filter); // Make sure we don't change the filter value. std::lock_guard lock(mtx); @@ -234,7 +234,8 @@ void SpriteAtlas::upload() { data // const GLvoid * data ); } else { - glTexSubImage2D(GL_TEXTURE_2D, // GLenum target + glTexSubImage2D( + GL_TEXTURE_2D, // GLenum target 0, // GLint level 0, // GLint xoffset 0, // GLint yoffset