diff options
Diffstat (limited to 'src/mbgl/gl/texture_pool.cpp')
-rw-r--r-- | src/mbgl/gl/texture_pool.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mbgl/gl/texture_pool.cpp b/src/mbgl/gl/texture_pool.cpp new file mode 100644 index 0000000000..a875f4d579 --- /dev/null +++ b/src/mbgl/gl/texture_pool.cpp @@ -0,0 +1,41 @@ +#include <mbgl/gl/texture_pool.hpp> +#include <mbgl/gl/gl_object_store.hpp> + +#include <vector> + +namespace mbgl { +namespace gl { + +GLuint TexturePool::getTextureID(gl::GLObjectStore& glObjectStore) { + for (auto& impl : pools) { + if (impl.ids.empty()) continue; + auto it = impl.ids.begin(); + GLuint id = *it; + impl.ids.erase(it); + return id; + } + + // All texture IDs are in use. + pools.emplace_back(Impl(glObjectStore)); + auto it = pools.back().ids.begin(); + GLuint id = *it; + pools.back().ids.erase(it); + return id; +} + +void TexturePool::releaseTextureID(GLuint id) { + for (auto it = pools.begin(); it != pools.end(); ++it) { + for (GLsizei i = 0; i < gl::TexturePoolHolder::TextureMax; ++i) { + if (it->pool[i] == id) { + it->ids.push_back(id); + if (GLsizei(it->ids.size()) == gl::TexturePoolHolder::TextureMax) { + pools.erase(it); + } + return; + } + } + } +} + +} // namespace gl +} // namespace mbgl |