Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Refactor tileCover to support lod tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mpulkki-mapbox committed Apr 2, 2020
1 parent b7728d2 commit 8dbc84d
Show file tree
Hide file tree
Showing 16 changed files with 941 additions and 194 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ add_library(
${PROJECT_SOURCE_DIR}/src/mbgl/tile/vector_tile.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/tile/vector_tile_data.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/tile/vector_tile_data.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/bounding_volumes.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/bounding_volumes.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/chrono.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/color.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/util/constants.cpp
Expand Down
15 changes: 7 additions & 8 deletions src/mbgl/algorithm/update_renderables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ void updateRenderables(GetTileFn getTile,
RenderTileFn renderTile,
const IdealTileIDs& idealTileIDs,
const Range<uint8_t>& zoomRange,
const uint8_t dataTileZoom,
const optional<uint8_t>& maxParentOverscaleFactor = nullopt) {
std::unordered_set<OverscaledTileID> checked;
bool covered;
int32_t overscaledZ;

// for (all in the set of ideal tiles of the source) {
for (const auto& idealRenderTileID : idealTileIDs) {
assert(idealRenderTileID.canonical.z >= zoomRange.min);
assert(idealRenderTileID.canonical.z <= zoomRange.max);
assert(dataTileZoom >= idealRenderTileID.canonical.z);
for (const auto& idealDataTileID : idealTileIDs) {
assert(idealDataTileID.canonical.z >= zoomRange.min);
assert(idealDataTileID.canonical.z <= zoomRange.max);
assert(idealDataTileID.overscaledZ >= idealDataTileID.canonical.z);

const OverscaledTileID idealDataTileID(dataTileZoom, idealRenderTileID.wrap, idealRenderTileID.canonical);
const UnwrappedTileID idealRenderTileID = idealDataTileID.toUnwrapped();
auto tile = getTile(idealDataTileID);
if (!tile) {
tile = createTile(idealDataTileID);
Expand All @@ -56,7 +55,7 @@ void updateRenderables(GetTileFn getTile,
// The tile isn't loaded yet, but retain it anyway because it's an ideal tile.
retainTile(*tile, TileNecessity::Required);
covered = true;
overscaledZ = dataTileZoom + 1;
overscaledZ = idealDataTileID.overscaledZ + 1;
if (overscaledZ > zoomRange.max) {
// We're looking for an overzoomed child tile.
const auto childDataTileID = idealDataTileID.scaledTo(overscaledZ);
Expand Down Expand Up @@ -85,7 +84,7 @@ void updateRenderables(GetTileFn getTile,

if (!covered) {
// We couldn't find child tiles that entirely cover the ideal tile.
for (overscaledZ = dataTileZoom - 1; overscaledZ >= zoomRange.min; --overscaledZ) {
for (overscaledZ = idealDataTileID.overscaledZ - 1; overscaledZ >= zoomRange.min; --overscaledZ) {
const auto parentDataTileID = idealDataTileID.scaledTo(overscaledZ);

// Request / render parent tile only if it's overscale factor is less than defined maximum.
Expand Down
10 changes: 9 additions & 1 deletion src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ void TransformState::updateMatricesIfNeeded() const {
getProjMatrix(projectionMatrix);
coordMatrix = coordinatePointMatrix(projectionMatrix);

bool err = matrix::invert(invertedMatrix, coordMatrix);
bool err = matrix::invert(invProjectionMatrix, projectionMatrix);
if (err) throw std::runtime_error("failed to invert projectionMatrix");

err = matrix::invert(invertedMatrix, coordMatrix);
if (err) throw std::runtime_error("failed to invert coordinatePointMatrix");

requestMatricesUpdate = false;
}

Expand All @@ -182,6 +185,11 @@ const mat4& TransformState::getProjectionMatrix() const {
return projectionMatrix;
}

const mat4& TransformState::getInvProjectionMatrix() const {
updateMatricesIfNeeded();
return invProjectionMatrix;
}

const mat4& TransformState::getCoordMatrix() const {
updateMatricesIfNeeded();
return coordMatrix;
Expand Down
2 changes: 2 additions & 0 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class TransformState {

void constrain(double& scale, double& x, double& y) const;
const mat4& getProjectionMatrix() const;
const mat4& getInvProjectionMatrix() const;

private:
bool rotatedNorth() const;
Expand Down Expand Up @@ -282,6 +283,7 @@ class TransformState {

mutable bool requestMatricesUpdate{true};
mutable mat4 projectionMatrix;
mutable mat4 invProjectionMatrix;
mutable mat4 coordMatrix;
mutable mat4 invertedMatrix;
};
Expand Down
7 changes: 4 additions & 3 deletions src/mbgl/renderer/layers/render_background_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,15 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {

uint32_t i = 0;
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
const UnwrappedTileID unwrappedTileID = tileID.toUnwrapped();
draw(parameters.programs.getBackgroundLayerPrograms().backgroundPattern,
BackgroundPatternProgram::layoutUniformValues(parameters.matrixForTile(tileID),
BackgroundPatternProgram::layoutUniformValues(parameters.matrixForTile(unwrappedTileID),
evaluated.get<BackgroundOpacity>(),
parameters.patternAtlas.getPixelSize(),
*imagePosA,
*imagePosB,
crossfade,
tileID,
unwrappedTileID,
parameters.state),
BackgroundPatternProgram::TextureBindings{
textures::image::Value{parameters.patternAtlas.textureBinding()},
Expand All @@ -141,7 +142,7 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) {
for (const auto& tileID : util::tileCover(parameters.state, parameters.state.getIntegerZoom())) {
draw(parameters.programs.getBackgroundLayerPrograms().background,
BackgroundProgram::LayoutUniformValues{
uniforms::matrix::Value(parameters.matrixForTile(tileID)),
uniforms::matrix::Value(parameters.matrixForTile(tileID.toUnwrapped())),
uniforms::color::Value(evaluated.get<BackgroundColor>()),
uniforms::opacity::Value(evaluated.get<BackgroundOpacity>()),
},
Expand Down
24 changes: 5 additions & 19 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
int32_t tileZoom = overscaledZoom;
int32_t panZoom = zoomRange.max;

std::vector<UnwrappedTileID> idealTiles;
std::vector<UnwrappedTileID> panTiles;
std::vector<OverscaledTileID> idealTiles;
std::vector<OverscaledTileID> panTiles;

if (overscaledZoom >= zoomRange.min) {
int32_t idealZoom = std::min<int32_t>(zoomRange.max, overscaledZoom);
Expand All @@ -118,7 +118,7 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
}
}

idealTiles = util::tileCover(parameters.transformState, idealZoom);
idealTiles = util::tileCover(parameters.transformState, idealZoom, tileZoom);
}

// Stores a list of all the tiles that we're definitely going to retain. There are two
Expand Down Expand Up @@ -179,24 +179,10 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l

if (!panTiles.empty()) {
algorithm::updateRenderables(
getTileFn,
createTileFn,
retainTileFn,
[](const UnwrappedTileID&, Tile&) {},
panTiles,
zoomRange,
panZoom,
maxParentTileOverscaleFactor);
getTileFn, createTileFn, retainTileFn, [](const UnwrappedTileID&, Tile&) {}, panTiles, zoomRange, maxParentTileOverscaleFactor);
}

algorithm::updateRenderables(getTileFn,
createTileFn,
retainTileFn,
renderTileFn,
idealTiles,
zoomRange,
tileZoom,
maxParentTileOverscaleFactor);
algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn, renderTileFn, idealTiles, zoomRange, maxParentTileOverscaleFactor);

for (auto previouslyRenderedTile : previouslyRenderedTiles) {
Tile& tile = previouslyRenderedTile.second;
Expand Down
Loading

0 comments on commit 8dbc84d

Please sign in to comment.