diff --git a/src/source/raster_dem_tile_source.js b/src/source/raster_dem_tile_source.js index be487be5e2e..ae7667eb3f8 100644 --- a/src/source/raster_dem_tile_source.js +++ b/src/source/raster_dem_tile_source.js @@ -19,6 +19,7 @@ import type {RasterDEMSourceSpecification} from '../style-spec/types'; class RasterDEMTileSource extends RasterTileSource implements Source { encoding: "mapbox" | "terrarium"; + _textureQueue: Array; constructor(id: string, options: RasterDEMSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) { super(id, options, dispatcher, eventedParent); @@ -26,6 +27,7 @@ class RasterDEMTileSource extends RasterTileSource implements Source { this.maxzoom = 22; this._options = extend({}, options); this.encoding = options.encoding || "mapbox"; + this._textureQueue = []; } serialize() { @@ -40,13 +42,11 @@ class RasterDEMTileSource extends RasterTileSource implements Source { } loadTile(tile: Tile, callback: Callback) { - 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'; @@ -58,10 +58,9 @@ class RasterDEMTileSource extends RasterTileSource implements Source { if (this.map._refreshExpiredTiles) tile.setExpiryData(img); delete (img: any).cacheControl; delete (img: any).expires; - this.map.style._textureQueue.push({tile, img, callback: textureCallback.bind(this)}); + this._textureQueue.push({tileKey: tile.tileID.key, img, callback: textureCallback.bind(this)}); callback(null); } - console.log('queue', this.map.style._textureQueue); } function textureCallback(tile, img) { diff --git a/src/source/raster_tile_source.js b/src/source/raster_tile_source.js index 77add1e6afa..4940f5a341e 100644 --- a/src/source/raster_tile_source.js +++ b/src/source/raster_tile_source.js @@ -36,6 +36,7 @@ class RasterTileSource extends Evented implements Source { dispatcher: Dispatcher; map: Map; tiles: Array; + _textureQueue: Array; _loaded: boolean; _options: RasterSourceSpecification | RasterDEMSourceSpecification; @@ -54,6 +55,7 @@ class RasterTileSource extends Evented implements Source { this.scheme = 'xyz'; this.tileSize = 512; this._loaded = false; + this._textureQueue = []; this._options = extend({}, options); extend(this, pick(options, ['url', 'scheme', 'tileSize'])); @@ -118,7 +120,7 @@ class RasterTileSource extends Evented implements Source { delete (img: any).cacheControl; delete (img: any).expires; - this.map.style._textureQueue.push({tile, img, callback: textureCallback.bind(this)}); + this._textureQueue.push({tileKey: tile.tileID.key, img, callback: textureCallback.bind(this)}); callback(null); } diff --git a/src/source/source.js b/src/source/source.js index 19eb5e97bca..b9f9b40d4f3 100644 --- a/src/source/source.js +++ b/src/source/source.js @@ -48,6 +48,7 @@ export interface Source { tileID?: CanonicalTileID; reparseOverscaled?: boolean, vectorLayerIds?: Array, + _textureQueue?: Array; hasTransition(): boolean; diff --git a/src/style/style.js b/src/style/style.js index f49a4f76e39..f78420f3518 100644 --- a/src/style/style.js +++ b/src/style/style.js @@ -119,7 +119,6 @@ class Style extends Evented { _removedLayers: {[string]: StyleLayer}; _updatedPaintProps: {[layer: string]: true}; _layerOrderChanged: boolean; - _textureQueue: Array; crossTileSymbolIndex: CrossTileSymbolIndex; pauseablePlacement: PauseablePlacement; @@ -146,7 +145,6 @@ class Style extends Evented { this.sourceCaches = {}; this.zoomHistory = new ZoomHistory(); this._loaded = false; - this._textureQueue = []; this._resetUpdates(); diff --git a/src/ui/map.js b/src/ui/map.js index af5fd47eaf1..ff858c67284 100755 --- a/src/ui/map.js +++ b/src/ui/map.js @@ -1685,22 +1685,29 @@ class Map extends Camera { // For performance reasons, we limit texture uploading to the GPU to // a max of two uploads per animation frame let continueRenderingTextures = false; - 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); + const sources = this.style && this.style.sourceCaches; + for (const id in sources) { + const cache = sources[id]; + const source = cache._source; + if ((source.type === 'raster' || source.type === 'raster-dem')) { + const textureQueue = Array.isArray(source._textureQueue) ? source._textureQueue : []; + const max = Math.min(2, textureQueue.length); + for (let i = 0; i < max; i++) { + const queued = textureQueue.shift(); + if (queued) { + const {tileKey, img, callback} = queued; + const tile = cache.getTileByID(tileKey); + // do not upload aborted tiles to the GPU + if (tile && !tile.aborted) { + console.log('create texture', textureQueue.length); + callback(tile, img); + } + if (textureQueue.length > 0) { + continueRenderingTextures = true; + } + } + } } - } - } - - if (this.style._textureQueue.length > 0) { - continueRenderingTextures = true; } // Actually draw