summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-06 19:44:22 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-07 13:01:58 +0300
commit858311d19b9879cf6ac1fea2d8746e136be3c4a3 (patch)
treeb6df43d9d460e3b4f8a825a9394639d50951b2ba /src
parent5e6f8d4ce5ad5c6ccb3e9a4525ec52a414e067a1 (diff)
downloadqtlocation-mapboxgl-858311d19b9879cf6ac1fea2d8746e136be3c4a3.tar.gz
[core] Do not expose TexturePool::Impl
Now using the same Pimpl mechanism from mbgl::Map.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/gl/texture_pool.cpp77
-rw-r--r--src/mbgl/gl/texture_pool.hpp21
2 files changed, 60 insertions, 38 deletions
diff --git a/src/mbgl/gl/texture_pool.cpp b/src/mbgl/gl/texture_pool.cpp
index 8818cbef0a..87e5aed256 100644
--- a/src/mbgl/gl/texture_pool.cpp
+++ b/src/mbgl/gl/texture_pool.cpp
@@ -7,35 +7,68 @@
namespace mbgl {
namespace gl {
-GLuint TexturePool::getTextureID(gl::ObjectStore& store) {
- auto nextAvailableID = [](auto& pool_) {
- auto it = pool_.availableIDs.begin();
- GLuint id = *it;
- pool_.availableIDs.erase(it);
- return id;
+class TexturePool::Impl : private util::noncopyable {
+public:
+ class Group : private util::noncopyable {
+ public:
+ Group(gl::ObjectStore& store) : pool(store.createTexturePool()), availableIDs(gl::TextureMax) {
+ std::copy(pool.get().begin(), pool.get().end(), availableIDs.begin());
+ }
+
+ Group(Group&& o) : pool(std::move(o.pool)), availableIDs(std::move(o.availableIDs)) {}
+ Group& operator=(Group&& o) { pool = std::move(o.pool); availableIDs = std::move(o.availableIDs); return *this; }
+
+ gl::UniqueTexturePool pool;
+ std::vector<GLuint> availableIDs;
};
- for (auto& pool : pools) {
- if (pool.availableIDs.empty()) continue;
- return nextAvailableID(pool);
- }
+ GLuint getTextureID(gl::ObjectStore& store) {
+ auto nextAvailableID = [](auto& pool_) {
+ auto it = pool_.availableIDs.begin();
+ GLuint id = *it;
+ pool_.availableIDs.erase(it);
+ return id;
+ };
- // All texture IDs are in use.
- pools.emplace_back(Impl { store });
- return nextAvailableID(pools.back());
-}
+ for (auto& pool : pools) {
+ if (pool.availableIDs.empty()) continue;
+ return nextAvailableID(pool);
+ }
-void TexturePool::releaseTextureID(GLuint& id) {
- for (auto it = pools.begin(); it != pools.end(); ++it) {
- 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);
+ // All texture IDs are in use.
+ pools.emplace_back(Group { store });
+ return nextAvailableID(pools.back());
+ }
+
+ void releaseTextureID(GLuint& id) {
+ for (auto it = pools.begin(); it != pools.end(); ++it) {
+ 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;
}
- return;
}
}
+
+private:
+ std::vector<Group> pools;
+};
+
+TexturePool::TexturePool() : impl(std::make_unique<Impl>()) {
+}
+
+TexturePool::~TexturePool() {
+}
+
+GLuint TexturePool::getTextureID(gl::ObjectStore& store) {
+ return impl->getTextureID(store);
+}
+
+void TexturePool::releaseTextureID(GLuint& id) {
+ impl->releaseTextureID(id);
}
} // namespace gl
diff --git a/src/mbgl/gl/texture_pool.hpp b/src/mbgl/gl/texture_pool.hpp
index a32ec76746..9ab7d14ef6 100644
--- a/src/mbgl/gl/texture_pool.hpp
+++ b/src/mbgl/gl/texture_pool.hpp
@@ -4,33 +4,22 @@
#include <mbgl/gl/gl.hpp>
#include <mbgl/gl/object_store.hpp>
-#include <algorithm>
#include <memory>
-#include <vector>
namespace mbgl {
namespace gl {
class TexturePool : private util::noncopyable {
public:
+ TexturePool();
+ ~TexturePool();
+
GLuint getTextureID(gl::ObjectStore&);
void releaseTextureID(GLuint&);
private:
- class Impl : private util::noncopyable {
- public:
- 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)), 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> availableIDs;
- };
-
- std::vector<Impl> pools;
+ class Impl;
+ const std::unique_ptr<Impl> impl;
};
} // namespace gl