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

Refactor tile coverage to support level of detail #16335

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 9 additions & 9 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,11 +84,12 @@ 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.
if (maxParentOverscaleFactor && (dataTileZoom - overscaledZ) > *maxParentOverscaleFactor) {
if (maxParentOverscaleFactor &&
(idealDataTileID.overscaledZ - overscaledZ) > *maxParentOverscaleFactor) {
break;
}

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
17 changes: 5 additions & 12 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 @@ -185,18 +185,11 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
[](const UnwrappedTileID&, Tile&) {},
panTiles,
zoomRange,
panZoom,
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