diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 18:29:42 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-12-04 20:02:50 +0100 |
commit | abafb52f37beb5659efc2105ccd1568e1f754898 (patch) | |
tree | 6a60636d3497560ca61e5aae5f6d7061c4f18553 /src/mbgl/util/texture_pool.cpp | |
parent | bff6aeb4da41dee1f5f1cfa0be81b6c257257253 (diff) | |
download | qtlocation-mapboxgl-abafb52f37beb5659efc2105ccd1568e1f754898.tar.gz |
make most headers private
Diffstat (limited to 'src/mbgl/util/texture_pool.cpp')
-rw-r--r-- | src/mbgl/util/texture_pool.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mbgl/util/texture_pool.cpp b/src/mbgl/util/texture_pool.cpp new file mode 100644 index 0000000000..9c8c24b085 --- /dev/null +++ b/src/mbgl/util/texture_pool.cpp @@ -0,0 +1,58 @@ +#include <mbgl/util/texture_pool.hpp> + +#include <vector> + +const int TextureMax = 64; + +using namespace mbgl; + +GLuint TexturePool::getTextureID() { + if (texture_ids.empty()) { + GLuint new_texture_ids[TextureMax]; + glGenTextures(TextureMax, new_texture_ids); + for (uint32_t id = 0; id < TextureMax; id++) { + texture_ids.insert(new_texture_ids[id]); + } + } + + GLuint id = 0; + + if (!texture_ids.empty()) { + std::set<GLuint>::iterator id_iterator = texture_ids.begin(); + id = *id_iterator; + texture_ids.erase(id_iterator); + } + + return id; +} + +void TexturePool::removeTextureID(GLuint texture_id) { + bool needs_clear = false; + + texture_ids.insert(texture_id); + + if (texture_ids.size() > TextureMax) { + needs_clear = true; + } + + if (needs_clear) { + // TODO: We need to find a better way to deal with texture pool cleanup +// clearTextureIDs(); + } +} + +void TexturePool::clearTextureIDs() { + std::vector<GLuint> ids_to_remove; + ids_to_remove.reserve(texture_ids.size()); + + for (std::set<GLuint>::iterator id_iterator = texture_ids.begin(); + id_iterator != texture_ids.end(); ++id_iterator) { + ids_to_remove.push_back(*id_iterator); + } + + if (!ids_to_remove.empty()) { + glDeleteTextures((GLsizei)ids_to_remove.size(), &ids_to_remove[0]); + } + + texture_ids.clear(); +} |