add glyph atlas to map
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <llmr/geometry/glyph_atlas.hpp>
|
||||
#include <llmr/map/vector_tile.hpp>
|
||||
#include <llmr/platform/gl.hpp>
|
||||
|
||||
#include <cassert>
|
||||
@@ -11,7 +12,8 @@ GlyphAtlas::GlyphAtlas(uint16_t width, uint16_t height)
|
||||
: width(width),
|
||||
height(height),
|
||||
bin(width, height),
|
||||
data(new char[width *height]) {
|
||||
data(new char[width *height]),
|
||||
dirty(true) {
|
||||
}
|
||||
|
||||
GlyphAtlas::~GlyphAtlas() {
|
||||
@@ -19,7 +21,11 @@ GlyphAtlas::~GlyphAtlas() {
|
||||
}
|
||||
|
||||
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_name,
|
||||
const Glyph& glyph, uint8_t buffer) {
|
||||
const VectorTileGlyph& glyph) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
// Use constant value for now.
|
||||
const uint8_t buffer = 3;
|
||||
|
||||
std::map<uint32_t, GlyphValue>& face = index[face_name];
|
||||
std::map<uint32_t, GlyphValue>::iterator it = face.find(glyph.id);
|
||||
@@ -77,6 +83,8 @@ Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_na
|
||||
}
|
||||
|
||||
void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
for (auto& faces : index) {
|
||||
std::map<uint32_t, GlyphValue>& face = faces.second;
|
||||
for (auto it = face.begin(); it != face.end(); /* we advance in the body */) {
|
||||
@@ -124,6 +132,7 @@ void GlyphAtlas::bind() {
|
||||
}
|
||||
|
||||
if (dirty) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, data);
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ Map::Map(Settings& settings)
|
||||
transform(),
|
||||
style(),
|
||||
painter(transform, settings, style),
|
||||
glyphAtlas(1024, 1024),
|
||||
min_zoom(0),
|
||||
max_zoom(14) {
|
||||
}
|
||||
@@ -278,7 +279,7 @@ TileData::State Map::addTile(const Tile::ID& id) {
|
||||
|
||||
if (!new_tile.data) {
|
||||
// If we don't find working tile data, we're just going to load it.
|
||||
new_tile.data = std::make_shared<TileData>(normalized_id, style);
|
||||
new_tile.data = std::make_shared<TileData>(normalized_id, style, glyphAtlas);
|
||||
new_tile.data->request();
|
||||
tile_data.push_front(new_tile.data);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
TileData::TileData(Tile::ID id, const Style& style)
|
||||
TileData::TileData(Tile::ID id, const Style& style, GlyphAtlas& glyphAtlas)
|
||||
: id(id),
|
||||
state(State::initial),
|
||||
fillVertexBuffer(std::make_shared<FillVertexBuffer>()),
|
||||
@@ -29,7 +29,8 @@ TileData::TileData(Tile::ID id, const Style& style)
|
||||
triangleElementsBuffer(std::make_shared<TriangleElementsBuffer>()),
|
||||
lineElementsBuffer(std::make_shared<LineElementsBuffer>()),
|
||||
pointElementsBuffer(std::make_shared<PointElementsBuffer>()),
|
||||
style(style) {
|
||||
style(style),
|
||||
glyphAtlas(glyphAtlas) {
|
||||
|
||||
// Initialize tile debug coordinates
|
||||
char coord[32];
|
||||
@@ -87,6 +88,7 @@ bool TileData::parse() {
|
||||
try {
|
||||
double parse_time_start = platform::time();
|
||||
VectorTile tile(pbf((const uint8_t *)data.data(), data.size()));
|
||||
loadGlyphs(tile.faces);
|
||||
parseStyleLayers(tile, style.layers);
|
||||
// double parse_time = (platform::time() - parse_time_start) * 1000.0;
|
||||
if (state == State::obsolete) {
|
||||
@@ -109,6 +111,21 @@ bool TileData::parse() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void TileData::loadGlyphs(const std::map<std::string, const VectorTileFace>& faces) {
|
||||
std::map<std::string, std::map<uint32_t, Rect<uint16_t>>> rects;
|
||||
for (const std::pair<std::string, const VectorTileFace> pair : faces) {
|
||||
const std::string& name = pair.first;
|
||||
const VectorTileFace& face = pair.second;
|
||||
|
||||
std::map<uint32_t, Rect<uint16_t>>& rect = rects[name];
|
||||
|
||||
for (const VectorTileGlyph& glyph : face.glyphs) {
|
||||
rect.emplace({ glyph.id, glyphAtlas.addGlyph((uint64_t)id, name, glyph) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileData::parseStyleLayers(const VectorTile& tile, const std::vector<LayerDescription>& layers) {
|
||||
for (const LayerDescription& layer_desc : layers) {
|
||||
// Cancel early when parsing.
|
||||
|
||||
Reference in New Issue
Block a user