Skip to content

Commit

Permalink
Allow 2 textures to be uploaded per frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Feb 4, 2019
1 parent 6530f6a commit 3e2f9a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/source/raster_dem_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class RasterDEMTileSource extends RasterTileSource implements Source {
}

loadTile(tile: Tile, callback: Callback<void>) {
console.log('loadTile', tile);
const url = normalizeURL(tile.tileID.canonical.url(this.tiles, this.scheme), this.url, this.tileSize);
tile.request = getImage(this.map._transformRequest(url, ResourceType.Tile), imageLoaded.bind(this));

tile.neighboringTiles = this._getNeighboringTiles(tile.tileID);
function imageLoaded(err, img) {
console.log('imageLoaded', img);
delete tile.request;
if (tile.aborted) {
tile.state = 'unloaded';
Expand All @@ -57,7 +59,9 @@ class RasterDEMTileSource extends RasterTileSource implements Source {
delete (img: any).cacheControl;
delete (img: any).expires;
this.map.style._textureQueue.push({tile, img, callback: textureCallback.bind(this)});
callback(null);
}
console.log('queue', this.map.style._textureQueue);
}

function textureCallback(tile, img) {
Expand Down
13 changes: 9 additions & 4 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1683,15 +1683,20 @@ class Map extends Camera {
this._placementDirty = this.style && this.style._updatePlacement(this.painter.transform, this.showCollisionBoxes, this._fadeDuration, this._crossSourceCollisions);

// For performance reasons, we limit texture uploading to the GPU to
// one upload per animation frame
// a max of two uploads per animation frame
let continueRenderingTextures = false;
const queued = this.style._textureQueue.shift();
if (queued) {
console.log('render called');
let max = Math.min(2, this.style._textureQueue.length);
for (let i = 0; i < max; i++) {
const queued = this.style._textureQueue.shift();
console.log('upload texture*********', this.style._textureQueue.length, queued);
if (queued) {
const {tile, img, callback} = queued;
// do not upload aborted tiles to the GPU
if (tile && !tile.aborted) {
callback(tile, img);
callback(tile, img);
}
}
}

if (this.style._textureQueue.length > 0) {
Expand Down

0 comments on commit 3e2f9a8

Please sign in to comment.