From c1280f0b380bfb21ce9e811b87bcf7d8ab380f25 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 2 Sep 2014 15:18:52 -0700 Subject: [PATCH] Revert "coalesce texture uploads at the beginning of a frame" This reverts commit 8c2c7f769fffcd217698824719b0a0ba45fbef13. See #454 Conflicts: src/geometry/glyph_atlas.cpp src/geometry/sprite_atlas.cpp --- include/mbgl/geometry/glyph_atlas.hpp | 1 - include/mbgl/geometry/sprite_atlas.hpp | 6 ++-- src/geometry/glyph_atlas.cpp | 50 ++++++-------------------- src/geometry/sprite_atlas.cpp | 11 +++--- src/map/map.cpp | 4 --- 5 files changed, 16 insertions(+), 56 deletions(-) diff --git a/include/mbgl/geometry/glyph_atlas.hpp b/include/mbgl/geometry/glyph_atlas.hpp index 8df9fd0f7..336c4af28 100644 --- a/include/mbgl/geometry/glyph_atlas.hpp +++ b/include/mbgl/geometry/glyph_atlas.hpp @@ -33,7 +33,6 @@ public: const SDFGlyph& glyph); void removeGlyphs(uint64_t tile_id); void bind(); - void upload(); public: const uint16_t width = 0; diff --git a/include/mbgl/geometry/sprite_atlas.hpp b/include/mbgl/geometry/sprite_atlas.hpp index 36f0f338e..5044e4d3e 100644 --- a/include/mbgl/geometry/sprite_atlas.hpp +++ b/include/mbgl/geometry/sprite_atlas.hpp @@ -42,12 +42,10 @@ public: // NEVER CALL THIS FUNCTION FROM THE RENDER THREAD! it is blocking. Rect waitForImage(const std::string &name, const Sprite &sprite); - // Binds the image buffer of this sprite atlas to the GPU. + // Binds the image buffer of this sprite atlas to the GPU, and uploads data if it is out + // of date. void bind(bool linear = false); - // Uploads the image buffer to the GPU if it is out of date. - void upload(); - inline float getWidth() const { return width; } inline float getHeight() const { return height; } inline float getTextureWidth() const { return width * pixelRatio; } diff --git a/src/geometry/glyph_atlas.cpp b/src/geometry/glyph_atlas.cpp index 9e74e21b2..76df941d9 100644 --- a/src/geometry/glyph_atlas.cpp +++ b/src/geometry/glyph_atlas.cpp @@ -120,46 +120,6 @@ void GlyphAtlas::removeGlyphs(uint64_t tile_id) { } } -void GlyphAtlas::upload() { - if (dirty) { - const bool exists = texture; - bind(); - - std::lock_guard lock(mtx); - - 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) - // platform::show_debug_image("Glyph Atlas", data, width, height); -#endif - } -} - void GlyphAtlas::bind() { if (!texture) { glGenTextures(1, &texture); @@ -171,4 +131,14 @@ void GlyphAtlas::bind() { } else { glBindTexture(GL_TEXTURE_2D, texture); } + + if (dirty) { + std::lock_guard lock(mtx); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data); + dirty = false; + +#if defined(DEBUG) + // platform::show_debug_image("Glyph Atlas", data, width, height); +#endif + } }; diff --git a/src/geometry/sprite_atlas.cpp b/src/geometry/sprite_atlas.cpp index 730551dbe..43c7da5fe 100644 --- a/src/geometry/sprite_atlas.cpp +++ b/src/geometry/sprite_atlas.cpp @@ -196,11 +196,13 @@ void SpriteAtlas::update(const Sprite &sprite) { } void SpriteAtlas::bind(bool linear) { + bool first = false; if (!texture) { glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + first = true; } else { glBindTexture(GL_TEXTURE_2D, texture); } @@ -211,17 +213,12 @@ void SpriteAtlas::bind(bool linear) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_val); filter = filter_val; } -} -void SpriteAtlas::upload() { if (dirty) { - const bool exists = texture; - bind(filter); // Make sure we don't change the filter value. - std::lock_guard lock(mtx); allocate(); - if (!exists) { + if (first) { glTexImage2D( GL_TEXTURE_2D, // GLenum target 0, // GLint level @@ -252,7 +249,7 @@ void SpriteAtlas::upload() { #endif dirty = false; } -} +}; SpriteAtlas::~SpriteAtlas() { std::lock_guard lock(mtx); diff --git a/src/map/map.cpp b/src/map/map.cpp index 45fae8444..9984f1b18 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -545,10 +545,6 @@ void Map::render() { #if defined(DEBUG) std::vector debug; #endif - - glyphAtlas->upload(); - spriteAtlas->upload(); - painter.clear(); painter.resize();