From 68ec9d3fd5725aa9bf0d2debf5f72551e8f4aef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 22 Aug 2016 17:57:22 +0200 Subject: [core] Make sure textures have a scaling filter set after upload --- src/mbgl/util/raster.cpp | 30 +++++++++++++++++------------- src/mbgl/util/raster.hpp | 3 +++ 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/mbgl/util/raster.cpp b/src/mbgl/util/raster.cpp index 498f6027b7..a7a56713b8 100644 --- a/src/mbgl/util/raster.cpp +++ b/src/mbgl/util/raster.cpp @@ -36,7 +36,7 @@ void Raster::bind(gl::ObjectStore& store, uint32_t unit, Scaling newFilter, MipMap newMipMap) { - bool updateFilter = false; + bool filterNeedsUpdate = false; if (!texture) { if (images.empty()) { @@ -44,35 +44,39 @@ void Raster::bind(gl::ObjectStore& store, return; } else { upload(store, config, unit); - updateFilter = true; + filterNeedsUpdate = true; } } else { if (config.texture[unit] != *texture) { config.activeTexture = unit; - config.texture[unit] = *texture; + config.texture[unit] = *texture; } - updateFilter = (filter != newFilter || mipmap != newMipMap); + filterNeedsUpdate = (filter != newFilter || mipmap != newMipMap); } - if (updateFilter) { + if (filterNeedsUpdate) { filter = newFilter; mipmap = newMipMap; - config.activeTexture = unit; - MBGL_CHECK_ERROR(glTexParameteri( - GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - filter == Scaling::Linear - ? (mipmap == MipMap::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR) - : (mipmap == MipMap::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST))); - MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, - filter == Scaling::Linear ? GL_LINEAR : GL_NEAREST)); + updateFilter(); } } +void Raster::updateFilter() { + MBGL_CHECK_ERROR(glTexParameteri( + GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + filter == Scaling::Linear + ? (mipmap == MipMap::Yes ? GL_LINEAR_MIPMAP_NEAREST : GL_LINEAR) + : (mipmap == MipMap::Yes ? GL_NEAREST_MIPMAP_NEAREST : GL_NEAREST))); + MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, + filter == Scaling::Linear ? GL_LINEAR : GL_NEAREST)); +} + void Raster::upload(gl::ObjectStore& store, gl::Config& config, uint32_t unit) { if (!images.empty() && !texture) { texture = store.createTexture(); config.activeTexture = unit; config.texture[unit] = *texture; + updateFilter(); #ifndef GL_ES_VERSION_2_0 MBGL_CHECK_ERROR(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, images.size())); #endif diff --git a/src/mbgl/util/raster.hpp b/src/mbgl/util/raster.hpp index 860c533086..ceb018c128 100644 --- a/src/mbgl/util/raster.hpp +++ b/src/mbgl/util/raster.hpp @@ -40,6 +40,9 @@ public: // size of uploaded image. std::array getSize() const; +private: + void updateFilter(); + private: // raw pixels have been loaded std::atomic loaded { false }; -- cgit v1.2.1