summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-12-11 11:58:46 +0100
committerKonstantin Käfer <mail@kkaefer.com>2014-12-12 12:37:55 +0100
commitfebfb7ac0965852ee224744bd33a3e3e5461ba80 (patch)
tree91c78a7d130cbbd0526d1c8e1bf4190e94a350af /src/mbgl/geometry
parentf8ba23377d4377a6047f8cb9b28c8ce94a00e8f5 (diff)
downloadqtlocation-mapboxgl-febfb7ac0965852ee224744bd33a3e3e5461ba80.tar.gz
fix rendering errors
Diffstat (limited to 'src/mbgl/geometry')
-rw-r--r--src/mbgl/geometry/sprite_atlas.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/mbgl/geometry/sprite_atlas.cpp b/src/mbgl/geometry/sprite_atlas.cpp
index db75414c0b..d3771b4695 100644
--- a/src/mbgl/geometry/sprite_atlas.cpp
+++ b/src/mbgl/geometry/sprite_atlas.cpp
@@ -77,15 +77,12 @@ void copy_bitmap(const uint32_t *src, const int src_stride, const int src_x, con
}
}
-Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t pixel_width, size_t pixel_height) {
- uint16_t pack_width = pixel_width + buffer * 2;
- uint16_t pack_height = pixel_height + buffer * 2;
-
+Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(const size_t pixel_width, const size_t pixel_height) {
// Increase to next number divisible by 4, but at least 1.
// This is so we can scale down the texture coordinates and pack them
// into 2 bytes rather than 4 bytes.
- pack_width += (4 - pack_width % 4);
- pack_height += (4 - pack_height % 4);
+ const uint16_t pack_width = pixel_width + (4 - pixel_width % 4);
+ const uint16_t pack_height = pixel_height + (4 - pixel_width % 4);
// We have to allocate a new area in the bin, and store an empty image in it.
// Add a 1px border around every image.
@@ -96,8 +93,6 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::allocateImage(size_t pixel_width, size
rect.x += buffer;
rect.y += buffer;
- rect.w = pixel_width;
- rect.h = pixel_height;
return rect;
}
@@ -132,15 +127,24 @@ Rect<SpriteAtlas::dimension> SpriteAtlas::getImage(const std::string& name) {
SpriteAtlasPosition SpriteAtlas::getPosition(const std::string& name, bool repeating) {
std::lock_guard<std::recursive_mutex> lock(mtx);
- // `repeating` indicates that the image will be used in a repeating pattern
- // repeating pattern images are assumed to have a 1px padding that mirrors the opposite edge
- // positions for repeating images are adjusted to exclude the edge
+
Rect<dimension> rect = getImage(name);
- const int r = repeating ? 1 : 0;
+ if (repeating) {
+ // When the image is repeating, get the correct position of the image, rather than the
+ // one rounded up to 4 pixels.
+ const SpritePosition &pos = sprite->getSpritePosition(name);
+ if (!pos.width || !pos.height) {
+ return SpriteAtlasPosition {};
+ }
+
+ rect.w = pos.width;
+ rect.h = pos.height;
+ }
+
return SpriteAtlasPosition {
- {{ float(rect.w) / pixelRatio, float(rect.h) / pixelRatio }},
- {{ float(rect.x + r) / width, float(rect.y + r) / height }},
- {{ float(rect.x + rect.w - 2*r) / width, float(rect.y + rect.h - 2*r) / height }}
+ {{ float(rect.w) / pixelRatio, float(rect.h) / pixelRatio }},
+ {{ float(rect.x) / width, float(rect.y) / height }},
+ {{ float(rect.x + rect.w) / width, float(rect.y + rect.h) / height }}
};
}