Skip to content

Commit

Permalink
fix hillshade layers with non-mercator projections (#11224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored Nov 4, 2021
1 parent ddd5ce3 commit 302e679
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/render/draw_hillshade.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function prepareHillshade(painter, tile, layer, depthMode, stencilMode, colorMod
context.bindFramebuffer.set(fbo.framebuffer);
context.viewport.set([0, 0, tileSize, tileSize]);

const {tileBoundsBuffer, tileBoundsIndexBuffer, tileBoundsSegments} = painter.getTileBoundsBuffers(tile);
const {tileBoundsBuffer, tileBoundsIndexBuffer, tileBoundsSegments} = painter.getMercatorTileBoundsBuffers();

painter.useProgram('hillshadePrepare').draw(context, gl.TRIANGLES,
depthMode, stencilMode, colorMode, CullFaceMode.disabled,
Expand Down
21 changes: 13 additions & 8 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,25 @@ class Painter {
this.loadTimeStamps.push(window.performance.now());
}

getMercatorTileBoundsBuffers() {
return {
tileBoundsBuffer: this.mercatorBoundsBuffer,
tileBoundsIndexBuffer: this.quadTriangleIndexBuffer,
tileBoundsSegments: this.mercatorBoundsSegments
};
}

getTileBoundsBuffers(tile: Tile) {
let tileBoundsBuffer, tileBoundsIndexBuffer, tileBoundsSegments;
tile._makeTileBoundsBuffers(this.context, this.transform.projection);
if (tile._tileBoundsBuffer) {
tileBoundsBuffer = tile._tileBoundsBuffer;
tileBoundsIndexBuffer = tile._tileBoundsIndexBuffer;
tileBoundsSegments = tile._tileBoundsSegments;
const tileBoundsBuffer = tile._tileBoundsBuffer;
const tileBoundsIndexBuffer = tile._tileBoundsIndexBuffer;
const tileBoundsSegments = tile._tileBoundsSegments;
return {tileBoundsBuffer, tileBoundsIndexBuffer, tileBoundsSegments};
} else {
tileBoundsBuffer = this.mercatorBoundsBuffer;
tileBoundsIndexBuffer = this.quadTriangleIndexBuffer;
tileBoundsSegments = this.mercatorBoundsSegments;
return this.getMercatorTileBoundsBuffers();
}

return {tileBoundsBuffer, tileBoundsIndexBuffer, tileBoundsSegments};
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class SourceCache extends Evented {
const cached = Boolean(tile);
if (!cached) {
const painter = this.map ? this.map.painter : null;
tile = new Tile(tileID, this._source.tileSize * tileID.overscaleFactor(), this.transform.tileZoom, painter, this._source.type === 'raster');
tile = new Tile(tileID, this._source.tileSize * tileID.overscaleFactor(), this.transform.tileZoom, painter, this._source.type === 'raster' || this._source.type === 'raster-dem');
this._loadTile(tile, this._tileLoaded.bind(this, tile, tileID.key, tile.state));
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions test/integration/render-tests/hillshade/projected/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256,
"width": 256
}
},
"center": [-113.26903, 35.9654],
"zoom": 11,
"projection": {
"name": "albers"
},
"sources": {
"source": {
"type": "raster-dem",
"tiles": [
"local://tiles/{z}-{x}-{y}.terrain.png"
],
"maxzoom": 15,
"tileSize": 256
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "hillshade",
"type": "hillshade",
"source": "source"
}
]
}

0 comments on commit 302e679

Please sign in to comment.