From c43016ce6c73c7305d259e7858efc0228d726660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 23 Apr 2015 12:30:15 +0200 Subject: [PATCH] make sure we always to a full upload after sprite atlas resizes We always need to do a full upload to adjust the image buffer size when we adjust the size of our sprite atlas. This can happen when we change the pixelRatio of the map we're rendering. --- src/mbgl/geometry/sprite_atlas.cpp | 7 ++++--- src/mbgl/geometry/sprite_atlas.hpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mbgl/geometry/sprite_atlas.cpp b/src/mbgl/geometry/sprite_atlas.cpp index a6156febb..9d0aeac8b 100644 --- a/src/mbgl/geometry/sprite_atlas.cpp +++ b/src/mbgl/geometry/sprite_atlas.cpp @@ -58,6 +58,7 @@ bool SpriteAtlas::resize(const float newRatio) { ::operator delete(old_data); dirty = true; + fullUploadRequired = true; // Mark all sprite images as in need of update for (const auto &pair : images) { @@ -237,7 +238,6 @@ void SpriteAtlas::upload() { } void SpriteAtlas::bind(bool linear) { - bool first = false; if (!texture) { MBGL_CHECK_ERROR(glGenTextures(1, &texture)); MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); @@ -248,7 +248,7 @@ void SpriteAtlas::bind(bool linear) { // We use those when the pixelRatio isn't a power of two, e.g. on iPhone 6 Plus. MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - first = true; + fullUploadRequired = true; } else { MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, texture)); } @@ -264,7 +264,7 @@ void SpriteAtlas::bind(bool linear) { std::lock_guard lock(mtx); allocate(); - if (first) { + if (fullUploadRequired) { MBGL_CHECK_ERROR(glTexImage2D( GL_TEXTURE_2D, // GLenum target 0, // GLint level @@ -276,6 +276,7 @@ void SpriteAtlas::bind(bool linear) { GL_UNSIGNED_BYTE, // GLenum type data // const GLvoid * data )); + fullUploadRequired = false; } else { MBGL_CHECK_ERROR(glTexSubImage2D( GL_TEXTURE_2D, // GLenum target diff --git a/src/mbgl/geometry/sprite_atlas.hpp b/src/mbgl/geometry/sprite_atlas.hpp index 560514310..6c4a381aa 100644 --- a/src/mbgl/geometry/sprite_atlas.hpp +++ b/src/mbgl/geometry/sprite_atlas.hpp @@ -79,6 +79,7 @@ private: std::set uninitialized; uint32_t *data = nullptr; std::atomic dirty; + bool fullUploadRequired = true; uint32_t texture = 0; uint32_t filter = 0; static const int buffer = 1;