summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-02 19:44:28 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-03 11:03:16 +0300
commit679a68078c1dfdf7c0bf1cbac6d0ab82d052e38b (patch)
tree2fc19fcf7f9b23f3cbc1348928afe4441ad471bc
parent61dad6eae59e284fdba63fcd76d9192aba900db4 (diff)
downloadqtlocation-mapboxgl-679a68078c1dfdf7c0bf1cbac6d0ab82d052e38b.tar.gz
[core] Refresh Texture Pool logic
Take advantage of mbgl::gl::ObjectPool being iterable, and also let TexturePool update the texture ID value when releasing.
-rw-r--r--src/mbgl/gl/object_store.hpp2
-rw-r--r--src/mbgl/gl/texture_pool.cpp35
-rw-r--r--src/mbgl/gl/texture_pool.hpp12
-rw-r--r--src/mbgl/util/raster.cpp1
4 files changed, 26 insertions, 24 deletions
diff --git a/src/mbgl/gl/object_store.hpp b/src/mbgl/gl/object_store.hpp
index a7b1993b5a..e430214013 100644
--- a/src/mbgl/gl/object_store.hpp
+++ b/src/mbgl/gl/object_store.hpp
@@ -7,6 +7,7 @@
#include <array>
#include <algorithm>
+#include <cassert>
#include <memory>
#include <vector>
@@ -89,6 +90,7 @@ public:
UniqueTexturePool createTexturePool() {
ObjectPool ids;
MBGL_CHECK_ERROR(glGenTextures(TextureMax, ids.data()));
+ assert(ids.size() == size_t(TextureMax));
return UniqueTexturePool(std::move(ids), { this });
}
diff --git a/src/mbgl/gl/texture_pool.cpp b/src/mbgl/gl/texture_pool.cpp
index 915e73f82a..8818cbef0a 100644
--- a/src/mbgl/gl/texture_pool.cpp
+++ b/src/mbgl/gl/texture_pool.cpp
@@ -1,38 +1,39 @@
#include <mbgl/gl/texture_pool.hpp>
#include <mbgl/gl/object_store.hpp>
+#include <algorithm>
#include <vector>
namespace mbgl {
namespace gl {
GLuint TexturePool::getTextureID(gl::ObjectStore& store) {
- for (auto& impl : pools) {
- if (impl.ids.empty()) continue;
- auto it = impl.ids.begin();
+ auto nextAvailableID = [](auto& pool_) {
+ auto it = pool_.availableIDs.begin();
GLuint id = *it;
- impl.ids.erase(it);
+ pool_.availableIDs.erase(it);
return id;
+ };
+
+ for (auto& pool : pools) {
+ if (pool.availableIDs.empty()) continue;
+ return nextAvailableID(pool);
}
// All texture IDs are in use.
- pools.emplace_back(Impl(store));
- auto it = pools.back().ids.begin();
- GLuint id = *it;
- pools.back().ids.erase(it);
- return id;
+ pools.emplace_back(Impl { store });
+ return nextAvailableID(pools.back());
}
-void TexturePool::releaseTextureID(GLuint id) {
+void TexturePool::releaseTextureID(GLuint& id) {
for (auto it = pools.begin(); it != pools.end(); ++it) {
- for (GLsizei i = 0; i < gl::TextureMax; ++i) {
- if (it->pool.get()[i] == id) {
- it->ids.push_back(id);
- if (GLsizei(it->ids.size()) == gl::TextureMax) {
- pools.erase(it);
- }
- return;
+ if (std::find(it->pool.get().begin(), it->pool.get().end(), id) != it->pool.get().end()) {
+ it->availableIDs.push_back(id);
+ id = 0;
+ if (GLsizei(it->availableIDs.size()) == gl::TextureMax) {
+ pools.erase(it);
}
+ return;
}
}
}
diff --git a/src/mbgl/gl/texture_pool.hpp b/src/mbgl/gl/texture_pool.hpp
index 549b5ce144..a32ec76746 100644
--- a/src/mbgl/gl/texture_pool.hpp
+++ b/src/mbgl/gl/texture_pool.hpp
@@ -14,20 +14,20 @@ namespace gl {
class TexturePool : private util::noncopyable {
public:
GLuint getTextureID(gl::ObjectStore&);
- void releaseTextureID(GLuint);
+ void releaseTextureID(GLuint&);
private:
class Impl : private util::noncopyable {
public:
- Impl(gl::ObjectStore& store) : pool(store.createTexturePool()), ids(gl::TextureMax) {
- std::copy(pool.get().begin(), pool.get().end(), ids.begin());
+ Impl(gl::ObjectStore& store) : pool(store.createTexturePool()), availableIDs(gl::TextureMax) {
+ std::copy(pool.get().begin(), pool.get().end(), availableIDs.begin());
}
- Impl(Impl&& o) : pool(std::move(o.pool)), ids(std::move(o.ids)) {}
- Impl& operator=(Impl&& o) { pool = std::move(o.pool); ids = std::move(o.ids); return *this; }
+ Impl(Impl&& o) : pool(std::move(o.pool)), availableIDs(std::move(o.availableIDs)) {}
+ Impl& operator=(Impl&& o) { pool = std::move(o.pool); availableIDs = std::move(o.availableIDs); return *this; }
gl::UniqueTexturePool pool;
- std::vector<GLuint> ids;
+ std::vector<GLuint> availableIDs;
};
std::vector<Impl> pools;
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index 4a57909a08..70fdf7b02a 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -16,7 +16,6 @@ Raster::Raster(gl::TexturePool& texturePool_)
Raster::~Raster() {
if (textured) {
texturePool.releaseTextureID(textureID);
- textureID = 0;
}
}