Skip to content

Commit

Permalink
save and reuse tile textures AND fix missing tiles 😂
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Oct 5, 2017
1 parent 6ec50fd commit 6ebe2b2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/render/draw_hillshade.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,23 @@ function prepareHillshade(painter, tile) {

gl.activeTexture(gl.TEXTURE1);

// if UNPACK_PREMULTIPLY_ALPHA_WEBGL is set to true prior to drawHillshade being called
// tiles will appear blank, because as you can see above the alpha value for these textures
// is always 0
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, (false: any));


tile.demTexture = tile.demTexture || painter.getTileTexture(tile.tileSize);
if (tile.demTexture) {
tile.demTexture.update(pixelData[0], false);
// for some reason flow thinks tile.demTexture can be null or undefined here :sob:
(tile.demTexture: any).bind(gl.NEAREST, gl.CLAMP_TO_EDGE);
} else {
tile.demTexture = new Texture(gl, pixelData[0], gl.RGBA, false);
tile.demTexture.bind(gl.NEAREST, gl.CLAMP_TO_EDGE);
}

(tile.demTexture: any).bind(gl.NEAREST, gl.CLAMP_TO_EDGE);

gl.activeTexture(gl.TEXTURE0);

if (!tile.texture) {
Expand All @@ -131,7 +141,6 @@ function prepareHillshade(painter, tile) {
tile.texture.clear(TERRAIN_TILE_HEIGHT, TERRAIN_TILE_WIDTH);
}

gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, (false: any));
gl.viewport(0, 0, TERRAIN_TILE_WIDTH, TERRAIN_TILE_HEIGHT);


Expand Down
6 changes: 5 additions & 1 deletion src/source/raster_dem_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ class RasterDEMTileSource extends RasterTileSource implements Source {


unloadTile(tile: Tile) {
tile.unloadDEMData();
if (tile.demTexture) this.map.painter.saveTileTexture(tile.demTexture);
if (tile.dem) delete tile.dem;
delete tile.neighboringTiles;

tile.state = 'unloaded';
this.dispatcher.send('removeDEMTile', { uid: tile.uid, source: this.id }, undefined, tile.workerID);
}

Expand Down
6 changes: 0 additions & 6 deletions src/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,6 @@ class Tile {
this.state = 'unloaded';
}

unloadDEMData() {
this.dem = null;
this.neighboringTiles = null;
this.state = 'unloaded';
}

redoPlacement(source: any) {
if (source.type !== 'vector' && source.type !== 'geojson') {
return;
Expand Down

0 comments on commit 6ebe2b2

Please sign in to comment.