Skip to content

Commit

Permalink
Fix gradient texture invalidation across zoom levels
Browse files Browse the repository at this point in the history
Use a generation identifier instead of a single boolean to prevent stale data.
  • Loading branch information
karimnaaji committed Jun 1, 2020
1 parent 06a8ff5 commit 421c734
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class LineBucket implements Bucket {
layoutVertexBuffer2: VertexBuffer;
gradientTexture: ?Texture;
gradient: ?RGBAImage;
gradientGeneration: number;

indexArray: TriangleIndexArray;
indexBuffer: IndexBuffer;
Expand Down
5 changes: 2 additions & 3 deletions src/render/draw_line.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function drawLine(painter: Painter, sourceCache: SourceCache, lay
painter.lineAtlas.bind(context);
} else if (gradient) {
let gradientTexture = bucket.gradientTexture;
if (!gradientTexture || layer.gradientTextureInvalidated) {
if (!gradientTexture || (gradientTexture && layer.gradientGeneration !== bucket.gradientGeneration)) {
const sourceMaxZoom = sourceCache.getSource().maxzoom;
const potentialOverzoom = coord.canonical.z === sourceMaxZoom ?
Math.ceil(1 << (painter.transform.maxZoom - coord.canonical.z)) : 1;
Expand All @@ -103,6 +103,7 @@ export default function drawLine(painter: Painter, sourceCache: SourceCache, lay
}
context.activeTexture.set(gl.TEXTURE0);
gradientTexture.bind(layer.stepInterpolant ? gl.NEAREST : gl.LINEAR, gl.CLAMP_TO_EDGE);
bucket.gradientGeneration = layer.gradientGeneration;
}

program.draw(context, gl.TRIANGLES, depthMode,
Expand All @@ -113,6 +114,4 @@ export default function drawLine(painter: Painter, sourceCache: SourceCache, lay
firstTile = false;
// once refactored so that bound texture state is managed, we'll also be able to remove this firstTile/programChanged logic
}

layer.gradientTextureInvalidated = false;
}
5 changes: 3 additions & 2 deletions src/style/style_layer/line_style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LineStyleLayer extends StyleLayer {
_unevaluatedLayout: Layout<LayoutProps>;
layout: PossiblyEvaluated<LayoutProps>;

gradientTextureInvalidated: boolean;
gradientGeneration: number;
stepInterpolant: boolean;

_transitionablePaint: Transitionable<PaintProps>;
Expand All @@ -53,13 +53,14 @@ class LineStyleLayer extends StyleLayer {

constructor(layer: LayerSpecification) {
super(layer, properties);
this.gradientGeneration = 0;
}

_handleSpecialPaintPropertyUpdate(name: string) {
if (name === 'line-gradient') {
const expression: ZoomConstantExpression<'source'> = ((this._transitionablePaint._values['line-gradient'].value.expression): any);
this.stepInterpolant = expression._styleExpression.expression instanceof Step;
this.gradientTextureInvalidated = true;
this.gradientGeneration++;
}
}
Expand Down

0 comments on commit 421c734

Please sign in to comment.