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

Fix flickering on lines #5094

Merged
merged 11 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- _...Add new stuff here..._

### 🐞 Bug fixes
- Fixes line flickering problem ([#5094](https://github.com/maplibre/maplibre-gl-js/pull/5094))
- _...Add new stuff here..._

## 5.0.0-pre.7
Expand Down
10 changes: 8 additions & 2 deletions src/render/draw_line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import {clamp, nextPowerOfTwo} from '../util/util';
import {renderColorRamp} from '../util/color_ramp';
import {EXTENT} from '../data/extent';
import {StencilMode} from '../gl/stencil_mode';

export function drawLine(painter: Painter, sourceCache: SourceCache, layer: LineStyleLayer, coords: Array<OverscaledTileID>, renderOptions: RenderOptions) {
if (painter.renderPass !== 'translucent') return;
Expand Down Expand Up @@ -124,8 +125,13 @@
gradientTexture.bind(layer.stepInterpolant ? gl.NEAREST : gl.LINEAR, gl.CLAMP_TO_EDGE);
}

const [stencilModes] = painter.stencilConfigForOverlap(coords);
const stencil = isRenderingToTexture ? stencilModes[coord.overscaledZ] : painter.stencilModeForClipping(coord);
let stencil: StencilMode;
if (isRenderingToTexture) {
const [stencilModes] = painter.stencilConfigForOverlap(coords);
stencil = stencilModes[coord.overscaledZ];

Check warning on line 131 in src/render/draw_line.ts

View check run for this annotation

Codecov / codecov/patch

src/render/draw_line.ts#L130-L131

Added lines #L130 - L131 were not covered by tests
} else {
stencil = painter.stencilModeForClipping(coord);
}

program.draw(context, gl.TRIANGLES, depthMode,
stencil, colorMode, CullFaceMode.disabled, uniformValues, terrainData, projectionData,
Expand Down
3 changes: 3 additions & 0 deletions src/render/painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ export class Painter {
* mask area of tile overlapped by children tiles.
* Stencil ref values continue range used in _tileClippingMaskIDs.
*
* Attention: This function changes this.nextStencilID even if the result of it
HarelM marked this conversation as resolved.
Show resolved Hide resolved
* is not used, which might cause problems when rendering due to invalid stencil
* values.
* Returns [StencilMode for tile overscaleZ map, sortedCoords].
*/
stencilConfigForOverlap(tileIDs: Array<OverscaledTileID>): [{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions test/integration/render/tests/line-overlap/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"version": 8,
"sources": {
"labels": {
"type": "geojson",
"data": "https://zerda.de/labels_small.geojson"
HarelM marked this conversation as resolved.
Show resolved Hide resolved
}
},
"layers": [
{
"id": "lines-red",
"type": "line",
"source": "labels",
"layout": {
"visibility": "visible"
},
"paint": {
"line-color": "rgba(255, 0, 0, 1.0)",
"line-width": 20
}
},
{
"id": "lines-green",
"type": "line",
"source": "labels",
"layout": {
"visibility": "visible"
},
"paint": {
"line-color": "rgba(0, 255, 0, 1.0)",
"line-width": 12
}
},
{
"id": "lines-blue",
"type": "line",
"source": "labels",
"layout": {
"visibility": "visible"
},
"paint": {
"line-color": "rgba(0, 0, 255, 1.0)",
"line-width": 4
}
}
],
"zoom": 6.9801106061514195,
"center": [10.907878576288454, 31.329259918093854],
"pitch": 60,
"bearing": -117.25161852328324,
"roll": 0.7795022736613696
}