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.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/mbgl/renderer/image_atlas.cpp b/src/mbgl/renderer/image_atlas.cpp
index b39c788ced..282f135ac9 100644
--- a/src/mbgl/renderer/image_atlas.cpp
+++ b/src/mbgl/renderer/image_atlas.cpp
@@ -1,4 +1,6 @@
#include <mbgl/renderer/image_atlas.hpp>
+#include <mbgl/gfx/context.hpp>
+#include <mbgl/renderer/image_manager.hpp>
#include <mapbox/shelf-pack.hpp>
@@ -6,14 +8,15 @@ namespace mbgl {
static constexpr uint32_t padding = 1;
-ImagePosition::ImagePosition(const mapbox::Bin& bin, const style::Image::Impl& image)
+ImagePosition::ImagePosition(const mapbox::Bin& bin, const style::Image::Impl& image, uint32_t version_)
: pixelRatio(image.pixelRatio),
textureRect(
bin.x + padding,
bin.y + padding,
bin.w - padding * 2,
bin.h - padding * 2
- ) {
+ ),
+ version(version_) {
}
const mapbox::Bin& _packImage(mapbox::ShelfPack& pack, const style::Image::Impl& image, ImageAtlas& resultImage, ImageType imageType) {
@@ -49,7 +52,30 @@ const mapbox::Bin& _packImage(mapbox::ShelfPack& pack, const style::Image::Impl&
return bin;
}
-ImageAtlas makeImageAtlas(const ImageMap& icons, const ImageMap& patterns) {
+void ImageAtlas::patchUpdatedImages(gfx::Context& context, gfx::Texture& atlasTexture, const ImageManager& imageManager) {
+ for (auto& updatedImageVersion : imageManager.updatedImageVersions) {
+ auto iconPosition = iconPositions.find(updatedImageVersion.first);
+ if (iconPosition != iconPositions.end()) {
+ patchUpdatedImage(context, atlasTexture, iconPosition->second, imageManager, updatedImageVersion.first, updatedImageVersion.second);
+ }
+ auto patternPosition = patternPositions.find(updatedImageVersion.first);
+ if (patternPosition != patternPositions.end()) {
+ patchUpdatedImage(context, atlasTexture, patternPosition->second, imageManager, updatedImageVersion.first, updatedImageVersion.second);
+ }
+ }
+}
+
+void ImageAtlas::patchUpdatedImage(gfx::Context& context, 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;
+
+ context.updateTextureSub(atlasTexture, updatedImage->image, position.textureRect.x, position.textureRect.y);
+ position.version = version;
+}
+
+ImageAtlas makeImageAtlas(const ImageMap& icons, const ImageMap& patterns, const std::unordered_map<std::string, uint32_t>& versionMap) {
ImageAtlas result;
mapbox::ShelfPack::ShelfPackOptions options;
@@ -59,13 +85,17 @@ ImageAtlas makeImageAtlas(const ImageMap& icons, const ImageMap& patterns) {
for (const auto& entry : icons) {
const style::Image::Impl& image = *entry.second;
const mapbox::Bin& bin = _packImage(pack, image, result, ImageType::Icon);
- result.iconPositions.emplace(image.id, ImagePosition { bin, image });
+ auto it = versionMap.find(entry.first);
+ auto version = it != versionMap.end() ? it->second : 0;
+ result.iconPositions.emplace(image.id, ImagePosition { bin, image, version });
}
for (const auto& entry : patterns) {
const style::Image::Impl& image = *entry.second;
const mapbox::Bin& bin = _packImage(pack, image, result, ImageType::Pattern);
- result.patternPositions.emplace(image.id, ImagePosition { bin, image });
+ auto it = versionMap.find(entry.first);
+ auto version = it != versionMap.end() ? it->second : 0;
+ result.patternPositions.emplace(image.id, ImagePosition { bin, image, version });
}
pack.shrink();