Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[projections] Fix performance regression in draw_background #10747

Merged
merged 4 commits into from
Jun 24, 2021
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
10 changes: 8 additions & 2 deletions src/render/draw_background.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function drawBackground(painter: Painter, sourceCache: SourceCache, layer: Backg

const program = painter.useProgram(image ? 'backgroundPattern' : 'background');

const tileIDs = coords ? coords : transform.coveringTiles({tileSize});
let tileIDs = coords;
let backgroundTiles;
if (!tileIDs) {
backgroundTiles = painter.getBackgroundTiles();
tileIDs = Object.values(backgroundTiles).map(tile => (tile: any).tileID);
}

if (image) {
context.activeTexture.set(gl.TEXTURE0);
Expand All @@ -51,7 +56,8 @@ function drawBackground(painter: Painter, sourceCache: SourceCache, layer: Backg
const matrix = coords ? tileID.projMatrix : painter.transform.calculateProjMatrix(unwrappedTileID);
painter.prepareDrawTile(tileID);

const tile = new Tile(tileID, tileSize, transform.zoom, painter);
const tile = sourceCache ? sourceCache.getTile(tileID) :
backgroundTiles ? backgroundTiles[tileID.key] : new Tile(tileID, tileSize, transform.zoom, painter);

const uniformValues = image ?
backgroundPatternUniformValues(matrix, opacity, painter, image, {tileID, tileSize}, crossfade) :
Expand Down
16 changes: 15 additions & 1 deletion src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import custom from './draw_custom.js';
import sky from './draw_sky.js';
import {Terrain} from '../terrain/terrain.js';
import {Debug} from '../util/debug.js';
import Tile from '../source/tile.js';

const draw = {
symbol,
Expand All @@ -59,7 +60,6 @@ const draw = {
};

import type Transform from '../geo/transform.js';
import type Tile from '../source/tile.js';
import type {OverscaledTileID, UnwrappedTileID} from '../source/tile_id.js';
import type Style from '../style/style.js';
import type StyleLayer from '../style/style_layer.js';
Expand Down Expand Up @@ -149,6 +149,7 @@ class Painter {
tileLoaded: boolean;
frameCopies: Array<WebGLTexture>;
loadTimeStamps: Array<number>;
_backgroundTiles: {[_: number | string]: Tile};

constructor(gl: WebGLRenderingContext, transform: Transform) {
this.context = new Context(gl);
Expand All @@ -168,6 +169,7 @@ class Painter {

this.gpuTimers = {};
this.frameCounter = 0;
this._backgroundTiles = {};
}

updateTerrain(style: Style, cameraChanging: boolean) {
Expand Down Expand Up @@ -910,6 +912,18 @@ class Painter {

return true;
}

getBackgroundTiles() {
const oldTiles = this._backgroundTiles;
const newTiles = this._backgroundTiles = {};

const tileSize = 512;
const tileIDs = this.transform.coveringTiles({tileSize});
for (const tileID of tileIDs) {
newTiles[tileID.key] = oldTiles[tileID.key] || new Tile(tileID, tileSize, this.transform.tileZoom, this);
}
return newTiles;
}
}

export default Painter;