From 3270440f234570f1426c442898c2400e36608ebf Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 8 Jun 2017 13:58:46 -0700 Subject: [core] Per-tile glyph/icon atlases --- src/mbgl/renderer/buckets/symbol_bucket.cpp | 2 -- src/mbgl/renderer/buckets/symbol_bucket.hpp | 3 --- src/mbgl/renderer/image_atlas.cpp | 34 ++++++++++----------------- src/mbgl/renderer/image_manager.cpp | 9 +------ src/mbgl/renderer/painters/painter_symbol.cpp | 13 ++++++---- 5 files changed, 22 insertions(+), 39 deletions(-) (limited to 'src/mbgl/renderer') 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 vertices; gl::IndexVector triangles; gl::SegmentVector segments; - AlphaImage atlasImage; optional> vertexBuffer; optional> indexBuffer; - optional atlasTexture; } text; std::unique_ptr iconSizeBinder; @@ -63,7 +61,6 @@ public: optional> vertexBuffer; optional> indexBuffer; - optional 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 pointers; - pointers.reserve(images.size()); - - std::vector 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(pack.width()), - static_cast(pack.height()) - }); - - for (const auto& bin : bins) { - const style::Image::Impl& image = *pointers.at(bin.id); + result.image.resize({ + static_cast(pack.width()), + static_cast(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(pack.width()), +// static_cast(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 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 #include #include -#include +#include #include @@ -62,6 +62,9 @@ void Painter::renderSymbol(PaintParameters& parameters, ); }; + assert(dynamic_cast(&tile.tile)); + GeometryTile& geometryTile = static_cast(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().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, -- cgit v1.2.1