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 Mar 27, 2020
1 parent 7cf5350 commit f0dc2a8
Show file tree
Hide file tree
Showing 16 changed files with 942 additions and 183 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
17 changes: 8 additions & 9 deletions src/mbgl/algorithm/update_renderables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ void updateRenderables(GetTileFn getTile,
RetainTileFn retainTile,
RenderTileFn renderTile,
const IdealTileIDs& idealTileIDs,
const Range<uint8_t>& zoomRange,
const uint8_t dataTileZoom) {
const Range<uint8_t>& zoomRange) {
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 @@ -54,7 +53,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 @@ -83,7 +82,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);

if (checked.find(parentDataTileID) != checked.end()) {
Expand Down
8 changes: 8 additions & 0 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligne
const float dya = -std::modf(dy, &devNull) + bearingCos * yShift + bearingSin * xShift;
matrix::translate(projMatrix, projMatrix, dxa > 0.5 ? dxa - 1 : dxa, dya > 0.5 ? dya - 1 : dya, 0);
}

// Compute inverted projection matrix
matrix::invert(invProjectionMatrix, projectionMatrix);
}

void TransformState::updateMatricesIfNeeded() const {
Expand All @@ -179,6 +182,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 @@ -117,14 +117,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 @@ -142,7 +143,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
15 changes: 7 additions & 8 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,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 @@ -117,7 +117,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 @@ -176,13 +176,12 @@ void TilePyramid::update(const std::vector<Immutable<style::LayerProperties>>& l
renderedTiles.clear();

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

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

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

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

0 comments on commit f0dc2a8

Please sign in to comment.