summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/image_atlas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/renderer/image_atlas.cpp')
-rw-r--r--src/mbgl/renderer/image_atlas.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/mbgl/renderer/image_atlas.cpp b/src/mbgl/renderer/image_atlas.cpp
index da7f5a30be..c9cedb3386 100644
--- a/src/mbgl/renderer/image_atlas.cpp
+++ b/src/mbgl/renderer/image_atlas.cpp
@@ -1,6 +1,4 @@
#include <mbgl/renderer/image_atlas.hpp>
-#include <mbgl/gfx/upload_pass.hpp>
-#include <mbgl/gfx/context.hpp>
#include <mbgl/renderer/image_manager.hpp>
#include <mapbox/shelf-pack.hpp>
@@ -53,27 +51,36 @@ const mapbox::Bin& _packImage(mapbox::ShelfPack& pack, const style::Image::Impl&
return bin;
}
-void ImageAtlas::patchUpdatedImages(gfx::UploadPass& uploadPass, gfx::Texture& atlasTexture, const ImageManager& imageManager) {
+namespace {
+
+void populateImagePatches(
+ ImagePositions& imagePositions,
+ const ImageManager& imageManager,
+ std::vector<ImagePatch>& /*out*/ patches) {
for (auto& updatedImageVersion : imageManager.updatedImageVersions) {
- auto iconPosition = iconPositions.find(updatedImageVersion.first);
- if (iconPosition != iconPositions.end()) {
- patchUpdatedImage(uploadPass, atlasTexture, iconPosition->second, imageManager, updatedImageVersion.first, updatedImageVersion.second);
- }
- auto patternPosition = patternPositions.find(updatedImageVersion.first);
- if (patternPosition != patternPositions.end()) {
- patchUpdatedImage(uploadPass, atlasTexture, patternPosition->second, imageManager, updatedImageVersion.first, updatedImageVersion.second);
+ const std::string& name = updatedImageVersion.first;
+ const uint32_t version = updatedImageVersion.second;
+ auto it = imagePositions.find(updatedImageVersion.first);
+ if (it != imagePositions.end()) {
+ auto& position = it->second;
+ if (position.version == version) continue;
+
+ auto updatedImage = imageManager.getSharedImage(name);
+ if (updatedImage == nullptr) continue;
+
+ patches.emplace_back(*updatedImage, position.textureRect);
+ position.version = version;
}
}
}
-void ImageAtlas::patchUpdatedImage(gfx::UploadPass& uploadPass, gfx::Texture& atlasTexture, ImagePosition& position, const ImageManager& imageManager, const std::string& name, uint16_t version) {
- if (position.version == version) return;
-
- auto updatedImage = imageManager.getImage(name);
- if (updatedImage == nullptr) return;
+} // namespace
- uploadPass.updateTextureSub(atlasTexture, updatedImage->image, position.textureRect.x, position.textureRect.y);
- position.version = version;
+std::vector<ImagePatch> ImageAtlas::getImagePatchesAndUpdateVersions(const ImageManager& imageManager) {
+ std::vector<ImagePatch> imagePatches;
+ populateImagePatches(iconPositions, imageManager, imagePatches);
+ populateImagePatches(patternPositions, imageManager, imagePatches);
+ return imagePatches;
}
ImageAtlas makeImageAtlas(const ImageMap& icons, const ImageMap& patterns, const std::unordered_map<std::string, uint32_t>& versionMap) {