[core] Merge TexturePool into ObjectStore; pool all textures (#5477)
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <mbgl/gl/gl_helper.hpp>
|
||||
#include <mbgl/gl/gl_config.hpp>
|
||||
#include <mbgl/gl/object_store.hpp>
|
||||
#include <mbgl/gl/texture_pool.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -99,6 +98,8 @@ TEST(GLObject, Store) {
|
||||
texture.reset();
|
||||
EXPECT_FALSE(store.empty());
|
||||
store.performCleanup();
|
||||
EXPECT_FALSE(store.empty());
|
||||
store.reset();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
mbgl::gl::UniqueVAO vao = store.createVAO();
|
||||
@@ -108,84 +109,7 @@ TEST(GLObject, Store) {
|
||||
store.performCleanup();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
mbgl::gl::UniqueTexturePool texturePool = store.createTexturePool();
|
||||
for (auto& id : texturePool.get()) {
|
||||
EXPECT_NE(id, 0u);
|
||||
}
|
||||
EXPECT_TRUE(texturePool.get().size() == size_t(mbgl::gl::TextureMax));
|
||||
texturePool.reset();
|
||||
EXPECT_FALSE(store.empty());
|
||||
store.performCleanup();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
view.deactivate();
|
||||
}
|
||||
|
||||
TEST(GLObject, TexturePool) {
|
||||
mbgl::HeadlessView view(std::make_shared<mbgl::HeadlessDisplay>(), 1);
|
||||
view.activate();
|
||||
|
||||
mbgl::gl::ObjectStore store;
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
mbgl::gl::TexturePool pool;
|
||||
|
||||
std::vector<mbgl::gl::PooledTexture> ids;
|
||||
|
||||
// Fill an entire texture pool.
|
||||
for (auto i = 0; i != mbgl::gl::TextureMax; ++i) {
|
||||
ids.push_back(pool.acquireTexture(store));
|
||||
EXPECT_EQ(ids.back().get(), GLuint(i + 1));
|
||||
EXPECT_TRUE(store.empty());
|
||||
}
|
||||
|
||||
// Reuse texture ids from the same pool.
|
||||
for (auto i = 0; i != mbgl::gl::TextureMax; ++i) {
|
||||
ids[i].reset();
|
||||
ids.push_back(pool.acquireTexture(store));
|
||||
EXPECT_EQ(ids.back().get(), GLuint(i + 1));
|
||||
EXPECT_TRUE(store.empty());
|
||||
}
|
||||
|
||||
// Trigger a new texture pool creation.
|
||||
{
|
||||
mbgl::gl::PooledTexture id = pool.acquireTexture(store);
|
||||
EXPECT_EQ(id, GLuint(mbgl::gl::TextureMax + 1));
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
id.reset();
|
||||
|
||||
// Last used texture from pool triggers pool recycling.
|
||||
EXPECT_FALSE(store.empty());
|
||||
|
||||
store.performCleanup();
|
||||
EXPECT_TRUE(store.empty());
|
||||
}
|
||||
|
||||
// First pool is still full, thus creating a new pool.
|
||||
mbgl::gl::PooledTexture id1 = pool.acquireTexture(store);
|
||||
EXPECT_GT(id1.get(), GLuint(mbgl::gl::TextureMax));
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
// Release all textures from the first pool.
|
||||
ids.clear();
|
||||
EXPECT_FALSE(store.empty());
|
||||
|
||||
store.performCleanup();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
// The first pool is now gone, the next pool is now in use.
|
||||
mbgl::gl::PooledTexture id2 = pool.acquireTexture(store);
|
||||
EXPECT_GT(id2.get(), id1.get());
|
||||
|
||||
id2.reset();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
// Last used texture from the pool triggers pool recycling.
|
||||
id1.reset();
|
||||
EXPECT_FALSE(store.empty());
|
||||
|
||||
store.performCleanup();
|
||||
store.reset();
|
||||
EXPECT_TRUE(store.empty());
|
||||
|
||||
view.deactivate();
|
||||
|
||||
Reference in New Issue
Block a user