diff options
Diffstat (limited to 'src/mbgl/gl/object_store.hpp')
-rw-r--r-- | src/mbgl/gl/object_store.hpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/mbgl/gl/object_store.hpp b/src/mbgl/gl/object_store.hpp index 956d65bda1..96bb8008f1 100644 --- a/src/mbgl/gl/object_store.hpp +++ b/src/mbgl/gl/object_store.hpp @@ -5,7 +5,6 @@ #include <unique_resource.hpp> -#include <array> #include <algorithm> #include <memory> #include <vector> @@ -42,19 +41,11 @@ struct VAODeleter { void operator()(GLuint) const; }; -using ObjectPool = std::array<GLuint, TextureMax>; - -struct TexturePoolDeleter { - ObjectStore* store; - void operator()(ObjectPool) const; -}; - using UniqueProgram = std_experimental::unique_resource<GLuint, ProgramDeleter>; using UniqueShader = std_experimental::unique_resource<GLuint, ShaderDeleter>; using UniqueBuffer = std_experimental::unique_resource<GLuint, BufferDeleter>; using UniqueTexture = std_experimental::unique_resource<GLuint, TextureDeleter>; using UniqueVAO = std_experimental::unique_resource<GLuint, VAODeleter>; -using UniqueTexturePool = std_experimental::unique_resource<ObjectPool, TexturePoolDeleter>; class ObjectStore : private util::noncopyable { public: @@ -75,8 +66,13 @@ public: } UniqueTexture createTexture() { - GLuint id = 0; - MBGL_CHECK_ERROR(glGenTextures(1, &id)); + if (pooledTextures.empty()) { + pooledTextures.resize(TextureMax); + MBGL_CHECK_ERROR(glGenTextures(TextureMax, pooledTextures.data())); + } + + GLuint id = pooledTextures.back(); + pooledTextures.pop_back(); return UniqueTexture { std::move(id), { this } }; } @@ -86,19 +82,17 @@ public: return UniqueVAO { std::move(id), { this } }; } - UniqueTexturePool createTexturePool() { - ObjectPool ids; - MBGL_CHECK_ERROR(glGenTextures(TextureMax, ids.data())); - static_assert(ids.size() == size_t(TextureMax), "Texture ids size mismatch"); - return UniqueTexturePool { std::move(ids), { this } }; - } - // Actually remove the objects we marked as abandoned with the above methods. // Only call this while the OpenGL context is exclusive to this thread. void performCleanup(); + // Drain pools and remove abandoned objects, in preparation for destroying the store. + // Only call this while the OpenGL context is exclusive to this thread. + void reset(); + bool empty() const { - return abandonedPrograms.empty() + return pooledTextures.empty() + && abandonedPrograms.empty() && abandonedShaders.empty() && abandonedBuffers.empty() && abandonedTextures.empty() @@ -111,7 +105,8 @@ private: friend BufferDeleter; friend TextureDeleter; friend VAODeleter; - friend TexturePoolDeleter; + + std::vector<GLuint> pooledTextures; std::vector<GLuint> abandonedPrograms; std::vector<GLuint> abandonedShaders; |