summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-06-08 13:58:46 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-06-13 10:18:43 -0700
commit3270440f234570f1426c442898c2400e36608ebf (patch)
treedfc2330d74187a2503b244e632592cd984c0d84f /src/mbgl/renderer
parentf610e9bef969dc8d7ec1ea545e93919a03d98882 (diff)
downloadqtlocation-mapboxgl-3270440f234570f1426c442898c2400e36608ebf.tar.gz
[core] Per-tile glyph/icon atlases
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/buckets/symbol_bucket.cpp2
-rw-r--r--src/mbgl/renderer/buckets/symbol_bucket.hpp3
-rw-r--r--src/mbgl/renderer/image_atlas.cpp34
-rw-r--r--src/mbgl/renderer/image_manager.cpp9
-rw-r--r--src/mbgl/renderer/painters/painter_symbol.cpp13
5 files changed, 22 insertions, 39 deletions
diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp
index 21d463b1fc..cbddade899 100644
--- a/src/mbgl/renderer/buckets/symbol_bucket.cpp
+++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp
@@ -39,14 +39,12 @@ void SymbolBucket::upload(gl::Context& context) {
if (hasTextData()) {
text.vertexBuffer = context.createVertexBuffer(std::move(text.vertices));
text.indexBuffer = context.createIndexBuffer(std::move(text.triangles));
- text.atlasTexture = context.createTexture(std::move(text.atlasImage), 0);
textSizeBinder->upload(context);
}
if (hasIconData()) {
icon.vertexBuffer = context.createVertexBuffer(std::move(icon.vertices));
icon.indexBuffer = context.createIndexBuffer(std::move(icon.triangles));
- icon.atlasTexture = context.createTexture(std::move(icon.atlasImage), 0);
iconSizeBinder->upload(context);
}
diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp
index bc9d564aac..002b6e28b3 100644
--- a/src/mbgl/renderer/buckets/symbol_bucket.hpp
+++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp
@@ -46,11 +46,9 @@ public:
gl::VertexVector<SymbolLayoutVertex> vertices;
gl::IndexVector<gl::Triangles> triangles;
gl::SegmentVector<SymbolTextAttributes> segments;
- AlphaImage atlasImage;
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
- optional<gl::Texture> atlasTexture;
} text;
std::unique_ptr<SymbolSizeBinder> iconSizeBinder;
@@ -63,7 +61,6 @@ public:
optional<gl::VertexBuffer<SymbolLayoutVertex>> vertexBuffer;
optional<gl::IndexBuffer<gl::Triangles>> indexBuffer;
- optional<gl::Texture> atlasTexture;
} icon;
struct CollisionBoxBuffer {
diff --git a/src/mbgl/renderer/image_atlas.cpp b/src/mbgl/renderer/image_atlas.cpp
index b53c2162ea..9649187175 100644
--- a/src/mbgl/renderer/image_atlas.cpp
+++ b/src/mbgl/renderer/image_atlas.cpp
@@ -23,31 +23,17 @@ ImageAtlas makeImageAtlas(const ImageMap& images) {
options.autoResize = true;
mapbox::ShelfPack pack(0, 0, options);
- std::vector<const style::Image::Impl*> pointers;
- pointers.reserve(images.size());
-
- std::vector<mapbox::Bin> bins;
- bins.reserve(images.size());
-
for (const auto& entry : images) {
const style::Image::Impl& image = *entry.second;
- pointers.emplace_back(&image);
- bins.emplace_back(pointers.size() - 1,
- image.image.size.width + 2 * padding,
- image.image.size.height + 2 * padding);
- }
- mapbox::ShelfPack::PackOptions packOptions;
- packOptions.inPlace = true;
- pack.pack(bins, packOptions);
+ const mapbox::Bin& bin = *pack.packOne(-1,
+ image.image.size.width + 2 * padding,
+ image.image.size.height + 2 * padding);
- result.image = PremultipliedImage({
- static_cast<uint32_t>(pack.width()),
- static_cast<uint32_t>(pack.height())
- });
-
- for (const auto& bin : bins) {
- const style::Image::Impl& image = *pointers.at(bin.id);
+ result.image.resize({
+ static_cast<uint32_t>(pack.width()),
+ static_cast<uint32_t>(pack.height())
+ });
PremultipliedImage::copy(image.image,
result.image,
@@ -62,6 +48,12 @@ ImageAtlas makeImageAtlas(const ImageMap& images) {
ImagePosition { bin, image });
}
+// pack.shrink();
+// result.image.resize({
+// static_cast<uint32_t>(pack.width()),
+// static_cast<uint32_t>(pack.height())
+// });
+
return result;
}
diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp
index be47004b69..d0a106ede6 100644
--- a/src/mbgl/renderer/image_manager.cpp
+++ b/src/mbgl/renderer/image_manager.cpp
@@ -119,14 +119,7 @@ optional<ImagePosition> ImageManager::getPattern(const std::string& id) {
return {};
}
- if (!atlasImage.valid()) {
- atlasImage = PremultipliedImage(getPixelSize());
- atlasImage.fill(0);
- } else if (atlasImage.size != getPixelSize()) {
- PremultipliedImage newImage(getPixelSize());
- PremultipliedImage::copy(atlasImage, newImage, { 0, 0 }, { 0, 0 }, atlasImage.size);
- atlasImage = std::move(newImage);
- }
+ atlasImage.resize(getPixelSize());
const PremultipliedImage& src = image->image;
diff --git a/src/mbgl/renderer/painters/painter_symbol.cpp b/src/mbgl/renderer/painters/painter_symbol.cpp
index 13baa1a514..58700fc4e8 100644
--- a/src/mbgl/renderer/painters/painter_symbol.cpp
+++ b/src/mbgl/renderer/painters/painter_symbol.cpp
@@ -9,7 +9,7 @@
#include <mbgl/programs/symbol_program.hpp>
#include <mbgl/programs/collision_box_program.hpp>
#include <mbgl/util/math.hpp>
-#include <mbgl/tile/tile.hpp>
+#include <mbgl/tile/geometry_tile.hpp>
#include <cmath>
@@ -62,6 +62,9 @@ void Painter::renderSymbol(PaintParameters& parameters,
);
};
+ assert(dynamic_cast<GeometryTile*>(&tile.tile));
+ GeometryTile& geometryTile = static_cast<GeometryTile&>(tile.tile);
+
if (bucket.hasIconData()) {
auto values = layer.iconPropertyValues(layout);
auto paintPropertyValues = layer.iconPaintProperties();
@@ -69,11 +72,11 @@ void Painter::renderSymbol(PaintParameters& parameters,
const bool iconScaled = layout.get<IconSize>().constantOr(1.0) != 1.0 || bucket.iconsNeedLinear;
const bool iconTransformed = values.rotationAlignment == AlignmentType::Map || state.getPitch() != 0;
- context.bindTexture(*bucket.icon.atlasTexture, 0,
+ context.bindTexture(*geometryTile.iconAtlasTexture, 0,
bucket.sdfIcons || state.isChanging() || iconScaled || iconTransformed
? gl::TextureFilter::Linear : gl::TextureFilter::Nearest);
- const Size texsize = bucket.icon.atlasTexture->size;
+ const Size texsize = geometryTile.iconAtlasTexture->size;
if (bucket.sdfIcons) {
if (values.hasHalo) {
@@ -107,12 +110,12 @@ void Painter::renderSymbol(PaintParameters& parameters,
}
if (bucket.hasTextData()) {
- context.bindTexture(*bucket.text.atlasTexture, 0, gl::TextureFilter::Linear);
+ context.bindTexture(*geometryTile.glyphAtlasTexture, 0, gl::TextureFilter::Linear);
auto values = layer.textPropertyValues(layout);
auto paintPropertyValues = layer.textPaintProperties();
- const Size texsize = bucket.text.atlasTexture->size;
+ const Size texsize = geometryTile.glyphAtlasTexture->size;
if (values.hasHalo) {
draw(parameters.programs.symbolGlyph,