[core] Do not expose TexturePool::Impl
Now using the same Pimpl mechanism from mbgl::Map.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
for (auto& pool : pools) {
|
||||
if (pool.availableIDs.empty()) continue;
|
||||
return nextAvailableID(pool);
|
||||
}
|
||||
|
||||
// All texture IDs are in use.
|
||||
pools.emplace_back(Group { store });
|
||||
return nextAvailableID(pools.back());
|
||||
}
|
||||
|
||||
// All texture IDs are in use.
|
||||
pools.emplace_back(Impl { 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
impl->releaseTextureID(id);
|
||||
}
|
||||
|
||||
} // namespace gl
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user