fixes #70: raster tile rendering as toggleable mode from vector
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <llmr/style/resources.hpp>
|
||||
#include <llmr/style/sprite.hpp>
|
||||
#include <llmr/map/coverage.hpp>
|
||||
#include <llmr/util/animation.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -14,8 +15,9 @@ Map::Map(Settings& settings)
|
||||
transform(),
|
||||
style(),
|
||||
painter(transform, settings, style),
|
||||
texturepool(),
|
||||
min_zoom(0),
|
||||
max_zoom(14) {
|
||||
max_zoom((use_raster ? kTileRasterMaxZoom : kTileVectorMaxZoom)) {
|
||||
}
|
||||
|
||||
Map::~Map() {
|
||||
@@ -23,6 +25,7 @@ Map::~Map() {
|
||||
}
|
||||
|
||||
void Map::setup(float pixelRatio) {
|
||||
|
||||
painter.setup();
|
||||
|
||||
pixel_ratio = pixelRatio;
|
||||
@@ -33,10 +36,6 @@ void Map::setup(float pixelRatio) {
|
||||
style.loadJSON(resources::style, resources::style_size);
|
||||
}
|
||||
|
||||
void Map::loadSprite(const std::string& url) {
|
||||
|
||||
}
|
||||
|
||||
void Map::loadStyle(const uint8_t *const data, uint32_t bytes) {
|
||||
style.loadJSON(data, bytes);
|
||||
update();
|
||||
@@ -60,6 +59,13 @@ void Map::resize(uint32_t width, uint32_t height, uint32_t fb_width, uint32_t fb
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::toggleRaster() {
|
||||
use_raster = ! use_raster;
|
||||
max_zoom = (use_raster ? kTileRasterMaxZoom : kTileVectorMaxZoom);
|
||||
tiles.clear();
|
||||
update();
|
||||
}
|
||||
|
||||
void Map::moveBy(double dx, double dy, double duration) {
|
||||
transform.moveBy(dx, dy, duration);
|
||||
update();
|
||||
@@ -278,7 +284,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, use_raster, (pixel_ratio > 1.0));
|
||||
new_tile.data->request();
|
||||
tile_data.push_front(new_tile.data);
|
||||
}
|
||||
@@ -352,12 +358,14 @@ bool Map::updateTiles() {
|
||||
int32_t min_covering_zoom = zoom - 10;
|
||||
if (min_covering_zoom < min_zoom) min_covering_zoom = min_zoom;
|
||||
|
||||
int32_t max_dim = pow(2, zoom);
|
||||
|
||||
// Map four viewport corners to pixel coordinates
|
||||
box box = transform.mapCornersToBox(zoom);
|
||||
|
||||
// Performs a scanline algorithm search that covers the rectangle of the box
|
||||
// and sorts them by proximity to the center.
|
||||
std::forward_list<Tile::ID> required = llmr::covering_tiles(zoom, box);
|
||||
std::forward_list<Tile::ID> required = llmr::covering_tiles(zoom, box, use_raster, (pixel_ratio > 1.0));
|
||||
|
||||
// Retain is a list of tiles that we shouldn't delete, even if they are not
|
||||
// the most ideal tile for the current viewport. This may include tiles like
|
||||
@@ -369,6 +377,9 @@ bool Map::updateTiles() {
|
||||
const TileData::State state = addTile(id);
|
||||
|
||||
if (state != TileData::State::parsed) {
|
||||
if (use_raster && (transform.rotating || transform.scaling || transform.panning))
|
||||
break;
|
||||
|
||||
// The tile we require is not yet loaded. Try to find a parent or
|
||||
// child tile that we already have.
|
||||
|
||||
@@ -431,6 +442,10 @@ bool Map::render() {
|
||||
transform.updateAnimations();
|
||||
}
|
||||
|
||||
if (*style.sprite->raster && !style.sprite->raster->textured) {
|
||||
style.sprite->raster->setTexturepool(&texturepool);
|
||||
}
|
||||
|
||||
bool changed = updateTiles();
|
||||
|
||||
painter.clear();
|
||||
@@ -447,13 +462,20 @@ bool Map::render() {
|
||||
transform.matrixFor(tile.matrix, tile.id);
|
||||
matrix::multiply(tile.matrix, painter.projMatrix, tile.matrix);
|
||||
tile.clip_id = i++;
|
||||
painter.drawClippingMask(tile.matrix, tile.clip_id);
|
||||
painter.drawClippingMask(tile.matrix, tile.clip_id, !tile.data->use_raster);
|
||||
}
|
||||
}
|
||||
painter.finishClippingMask();
|
||||
|
||||
for (const Tile& tile : tiles) {
|
||||
if (tile.data && tile.data->state == TileData::State::parsed) {
|
||||
if (tile.data->use_raster && *tile.data->raster && !tile.data->raster->textured) {
|
||||
tile.data->raster->setTexturepool(&texturepool);
|
||||
tile.data->raster->beginFadeInAnimation();
|
||||
}
|
||||
if (tile.data->use_raster && tile.data->raster->needsAnimation()) {
|
||||
tile.data->raster->updateAnimations();
|
||||
}
|
||||
painter.render(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user