summaryrefslogtreecommitdiff
path: root/src/mbgl/util/raster.cpp
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-06 20:17:12 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-07 13:01:58 +0300
commit83d349ee16f1918d7e0275d47b9c22abc1a4f50c (patch)
tree3db5a34ec11598cc2e82df4534200f9a8d7f308c /src/mbgl/util/raster.cpp
parent858311d19b9879cf6ac1fea2d8746e136be3c4a3 (diff)
downloadqtlocation-mapboxgl-83d349ee16f1918d7e0275d47b9c22abc1a4f50c.tar.gz
[core] Use RAII for TexturePool textures
TexturePool now disposes acquirable ids via SharedTexture, which guarantees that these are going back to TexturePool once released.
Diffstat (limited to 'src/mbgl/util/raster.cpp')
-rw-r--r--src/mbgl/util/raster.cpp19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp
index 70fdf7b02a..514472010f 100644
--- a/src/mbgl/util/raster.cpp
+++ b/src/mbgl/util/raster.cpp
@@ -13,12 +13,6 @@ Raster::Raster(gl::TexturePool& texturePool_)
: texturePool(texturePool_)
{}
-Raster::~Raster() {
- if (textured) {
- texturePool.releaseTextureID(textureID);
- }
-}
-
bool Raster::isLoaded() const {
std::lock_guard<std::mutex> lock(mtx);
return loaded;
@@ -42,10 +36,10 @@ void Raster::bind(bool linear, gl::ObjectStore& store) {
return;
}
- if (img.data && !textured) {
+ if (img.data && !texture) {
upload(store);
- } else if (textured) {
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID));
+ } else if (texture) {
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
}
GLint new_filter = linear ? GL_LINEAR : GL_NEAREST;
@@ -57,15 +51,14 @@ void Raster::bind(bool linear, gl::ObjectStore& store) {
}
void Raster::upload(gl::ObjectStore& store) {
- if (img.data && !textured) {
- textureID = texturePool.getTextureID(store);
- MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, textureID));
+ if (img.data && !texture) {
+ texture = texturePool.acquireTexture(store);
+ MBGL_CHECK_ERROR(glBindTexture(GL_TEXTURE_2D, *texture));
#ifndef GL_ES_VERSION_2_0
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0));
#endif
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
MBGL_CHECK_ERROR(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, img.data.release()));
- textured = true;
}
}