diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-06-08 13:58:46 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-06-13 10:18:43 -0700 |
commit | 3270440f234570f1426c442898c2400e36608ebf (patch) | |
tree | dfc2330d74187a2503b244e632592cd984c0d84f /src/mbgl/text | |
parent | f610e9bef969dc8d7ec1ea545e93919a03d98882 (diff) | |
download | qtlocation-mapboxgl-3270440f234570f1426c442898c2400e36608ebf.tar.gz |
[core] Per-tile glyph/icon atlases
Diffstat (limited to 'src/mbgl/text')
-rw-r--r-- | src/mbgl/text/glyph_atlas.cpp | 79 | ||||
-rw-r--r-- | src/mbgl/text/glyph_atlas.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/text/quads.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/text/quads.hpp | 2 |
4 files changed, 48 insertions, 46 deletions
diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp index a08455ec63..6636c23f34 100644 --- a/src/mbgl/text/glyph_atlas.cpp +++ b/src/mbgl/text/glyph_atlas.cpp @@ -6,58 +6,59 @@ namespace mbgl { static constexpr uint32_t padding = 1; -GlyphAtlas makeGlyphAtlas(const Glyphs& glyphs) { +GlyphAtlas makeGlyphAtlas(const GlyphMap& glyphs) { GlyphAtlas result; mapbox::ShelfPack::ShelfPackOptions options; options.autoResize = true; mapbox::ShelfPack pack(0, 0, options); - std::vector<mapbox::Bin> bins; - bins.reserve(glyphs.size()); + for (const auto& glyphMapEntry : glyphs) { + const FontStack& fontStack = glyphMapEntry.first; + GlyphPositionMap& positions = result.positions[fontStack]; - for (const auto& entry : glyphs) { - if (entry.second && (*entry.second)->bitmap.valid()) { - const Glyph& glyph = **entry.second; - bins.emplace_back(glyph.id, - glyph.bitmap.size.width + 2 * padding, - glyph.bitmap.size.height + 2 * padding); - } - } - - mapbox::ShelfPack::PackOptions packOptions; - packOptions.inPlace = true; - pack.pack(bins, packOptions); + for (const auto& entry : glyphMapEntry.second) { + if (entry.second && (*entry.second)->bitmap.valid()) { + const Glyph& glyph = **entry.second; - result.image = AlphaImage({ - static_cast<uint32_t>(pack.width()), - static_cast<uint32_t>(pack.height()) - }); + const mapbox::Bin& bin = *pack.packOne(-1, + glyph.bitmap.size.width + 2 * padding, + glyph.bitmap.size.height + 2 * padding); - for (const auto& bin : bins) { - const Glyph& glyph = **glyphs.at(bin.id); + result.image.resize({ + static_cast<uint32_t>(pack.width()), + static_cast<uint32_t>(pack.height()) + }); - AlphaImage::copy(glyph.bitmap, - result.image, - { 0, 0 }, - { - bin.x + padding, - bin.y + padding - }, - glyph.bitmap.size); + AlphaImage::copy(glyph.bitmap, + result.image, + { 0, 0 }, + { + bin.x + padding, + bin.y + padding + }, + glyph.bitmap.size); - result.positions.emplace(glyph.id, - GlyphPosition { - Rect<uint16_t> { - static_cast<uint16_t>(bin.x), - static_cast<uint16_t>(bin.y), - static_cast<uint16_t>(bin.w), - static_cast<uint16_t>(bin.h) - }, - glyph.metrics - }); + positions.emplace(glyph.id, + GlyphPosition { + Rect<uint16_t> { + static_cast<uint16_t>(bin.x), + static_cast<uint16_t>(bin.y), + static_cast<uint16_t>(bin.w), + static_cast<uint16_t>(bin.h) + }, + glyph.metrics + }); + } + } } +// pack.shrink(); +// result.image.resize({ +// static_cast<uint32_t>(pack.width()), +// static_cast<uint32_t>(pack.height()) +// }); + return result; } diff --git a/src/mbgl/text/glyph_atlas.hpp b/src/mbgl/text/glyph_atlas.hpp index 7a90085642..bb9115e4b4 100644 --- a/src/mbgl/text/glyph_atlas.hpp +++ b/src/mbgl/text/glyph_atlas.hpp @@ -11,7 +11,8 @@ struct GlyphPosition { GlyphMetrics metrics; }; -using GlyphPositions = std::map<GlyphID, GlyphPosition>; +using GlyphPositionMap = std::map<GlyphID, GlyphPosition>; +using GlyphPositions = std::map<FontStack, GlyphPositionMap>; class GlyphAtlas { public: @@ -19,6 +20,6 @@ public: GlyphPositions positions; }; -GlyphAtlas makeGlyphAtlas(const Glyphs&); +GlyphAtlas makeGlyphAtlas(const GlyphMap&); } // namespace mbgl diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 81827ca32e..ab10c5a6b7 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -307,18 +307,18 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const GeometryCoordinates& line, const SymbolLayoutProperties::Evaluated& layout, const style::SymbolPlacementType placement, - const GlyphPositions& face) { + const GlyphPositionMap& positions) { const float textRotate = layout.get<TextRotate>() * util::DEG2RAD; const bool keepUpright = layout.get<TextKeepUpright>(); SymbolQuads quads; for (const PositionedGlyph &positionedGlyph: shapedText.positionedGlyphs) { - auto face_it = face.find(positionedGlyph.glyph); - if (face_it == face.end()) + auto positionsIt = positions.find(positionedGlyph.glyph); + if (positionsIt == positions.end()) continue; - const GlyphPosition& glyph = face_it->second; + const GlyphPosition& glyph = positionsIt->second; const Rect<uint16_t>& rect = glyph.rect; const float centerX = (positionedGlyph.x + glyph.metrics.advance / 2.0f) * boxScale; diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index 89df423529..b29f6b0ad3 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -65,6 +65,6 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const GeometryCoordinates& line, const style::SymbolLayoutProperties::Evaluated&, style::SymbolPlacementType placement, - const GlyphPositions& face); + const GlyphPositionMap& positions); } // namespace mbgl |