summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-02 19:47:20 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-03 11:03:16 +0300
commit623da8bfeb7adcbf1774a14c9a0dc46469891cef (patch)
tree7beed5a783599fe4dd60a8d4ad81090f4d5a8b16 /test
parent679a68078c1dfdf7c0bf1cbac6d0ab82d052e38b (diff)
downloadqtlocation-mapboxgl-623da8bfeb7adcbf1774a14c9a0dc46469891cef.tar.gz
[test] Added mbgl::gl::TexturePool tests
Diffstat (limited to 'test')
-rw-r--r--test/gl/object.cpp91
1 files changed, 85 insertions, 6 deletions
diff --git a/test/gl/object.cpp b/test/gl/object.cpp
index c804040950..4511fc4d1c 100644
--- a/test/gl/object.cpp
+++ b/test/gl/object.cpp
@@ -6,6 +6,7 @@
#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>
@@ -73,35 +74,35 @@ TEST(GLObject, Store) {
EXPECT_TRUE(store.empty());
mbgl::gl::UniqueProgram program = store.createProgram();
- EXPECT_TRUE(program.get() != 0);
+ EXPECT_NE(program.get(), 0);
program.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
EXPECT_TRUE(store.empty());
mbgl::gl::UniqueShader shader = store.createShader(GL_VERTEX_SHADER);
- EXPECT_TRUE(shader.get() != 0);
+ EXPECT_NE(shader.get(), 0);
shader.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
EXPECT_TRUE(store.empty());
mbgl::gl::UniqueBuffer buffer = store.createBuffer();
- EXPECT_TRUE(buffer.get() != 0);
+ EXPECT_NE(buffer.get(), 0);
buffer.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
EXPECT_TRUE(store.empty());
mbgl::gl::UniqueTexture texture = store.createTexture();
- EXPECT_TRUE(texture.get() != 0);
+ EXPECT_NE(texture.get(), 0);
texture.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
EXPECT_TRUE(store.empty());
mbgl::gl::UniqueVAO vao = store.createVAO();
- EXPECT_TRUE(vao.get() != 0);
+ EXPECT_NE(vao.get(), 0);
vao.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
@@ -109,8 +110,9 @@ TEST(GLObject, Store) {
mbgl::gl::UniqueTexturePool texturePool = store.createTexturePool();
for (auto& id : texturePool.get()) {
- EXPECT_TRUE(id != 0);
+ EXPECT_NE(id, 0);
}
+ EXPECT_TRUE(texturePool.get().size() == size_t(mbgl::gl::TextureMax));
texturePool.reset();
EXPECT_FALSE(store.empty());
store.performCleanup();
@@ -118,3 +120,80 @@ TEST(GLObject, Store) {
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;
+
+ // Fill an entire texture pool.
+ for (auto i = 0; i != mbgl::gl::TextureMax; ++i) {
+ EXPECT_EQ(pool.getTextureID(store), GLuint(i + 1));
+ EXPECT_TRUE(store.empty());
+ }
+
+ // Reuse texture ids from the same pool.
+ for (auto i = 0; i != mbgl::gl::TextureMax; ++i) {
+ GLuint id = i + 1;
+ pool.releaseTextureID(id);
+ EXPECT_EQ(id, 0);
+ EXPECT_EQ(pool.getTextureID(store), GLuint(i + 1));
+ EXPECT_TRUE(store.empty());
+ }
+
+ // Trigger a new texture pool creation.
+ {
+ GLuint id = pool.getTextureID(store);
+ EXPECT_EQ(id, mbgl::gl::TextureMax + 1);
+ EXPECT_TRUE(store.empty());
+
+ pool.releaseTextureID(id);
+ EXPECT_EQ(id, 0);
+ // 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.
+ GLuint id1 = pool.getTextureID(store);
+ EXPECT_GT(id1, mbgl::gl::TextureMax);
+ EXPECT_TRUE(store.empty());
+
+ // Release all textures from the first pool.
+ for (auto i = 0; i != mbgl::gl::TextureMax; ++i) {
+ GLuint id = i + 1;
+ pool.releaseTextureID(id);
+ if (i == mbgl::gl::TextureMax - 1) {
+ // Last texture from pool triggers pool recycling.
+ EXPECT_FALSE(store.empty());
+ } else {
+ EXPECT_TRUE(store.empty());
+ }
+ }
+
+ store.performCleanup();
+ EXPECT_TRUE(store.empty());
+
+ // The first pool is now gone, the next pool is now in use.
+ GLuint id2 = pool.getTextureID(store);
+ EXPECT_GT(id2, id1);
+ pool.releaseTextureID(id2);
+ EXPECT_EQ(id2, 0);
+ EXPECT_TRUE(store.empty());
+
+ // Last used texture from the pool triggers pool recycling.
+ pool.releaseTextureID(id1);
+ EXPECT_EQ(id1, 0);
+ EXPECT_FALSE(store.empty());
+
+ store.performCleanup();
+ EXPECT_TRUE(store.empty());
+
+ view.deactivate();
+}