Skip to content

Commit

Permalink
add raster-scaling raster paint property
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewharvey committed Mar 28, 2018
1 parent 6b848e5 commit 2a8cd04
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 6 deletions.
7 changes: 5 additions & 2 deletions debug/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@
"id": "background",
"type": "background",
"paint": {
"background-color": "rgb(4,7,14)"
"background-color": "rgb(128,128,128)"
}
}, {
"id": "image",
"type": "raster",
"source": "image"
"source": "image",
"paint": {
"raster-scaling": "nearest"
}
}]
};

Expand Down
17 changes: 14 additions & 3 deletions src/render/draw_raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,29 @@ function drawRaster(painter: Painter, sourceCache: SourceCache, layer: RasterSty

let parentScaleBy, parentTL;

let textureFilter;
switch (layer.paint.get('raster-scaling')) {
case 'nearest':
textureFilter = gl.NEAREST;
break;
case 'linear':
default:
textureFilter = gl.LINEAR;
break;
}

context.activeTexture.set(gl.TEXTURE0);
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);

context.activeTexture.set(gl.TEXTURE1);

if (parentTile) {
parentTile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
parentTile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
parentScaleBy = Math.pow(2, parentTile.tileID.overscaledZ - tile.tileID.overscaledZ);
parentTL = [tile.tileID.canonical.x * parentScaleBy % 1, tile.tileID.canonical.y * parentScaleBy % 1];

} else {
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
}

// cross-fade parameters
Expand Down
2 changes: 1 addition & 1 deletion src/source/image_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ImageSource extends Evented implements Source {

if (!this.texture) {
this.texture = new Texture(context, this.image, gl.RGBA);
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
this.texture.bind(gl.NEAREST, gl.CLAMP_TO_EDGE);
}

for (const w in this.tiles) {
Expand Down
21 changes: 21 additions & 0 deletions src/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,27 @@
"data-driven styling": {}
}
},
"raster-scaling": {
"type": "enum",
"doc": "The raster scaling to use for overscaling",
"values": {
"linear": {
"doc": "(Bi)linear filtering"
},
"nearest": {
"doc": "Nearest neighbor filtering"
}
},
"default": "linear",
"function": "piecewise-constant",
"zoom-function": true,
"sdk-support": {
"basic functionality": {
"js": "0.45.0"
},
"data-driven styling": {}
}
},
"raster-fade-duration": {
"type": "number",
"default": 300,
Expand Down
2 changes: 2 additions & 0 deletions src/style/style_layer/raster_style_layer_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type PaintProps = {|
"raster-brightness-max": DataConstantProperty<number>,
"raster-saturation": DataConstantProperty<number>,
"raster-contrast": DataConstantProperty<number>,
"raster-scaling": DataConstantProperty<"linear" | "nearest">,
"raster-fade-duration": DataConstantProperty<number>,
|};

Expand All @@ -32,6 +33,7 @@ const paint: Properties<PaintProps> = new Properties({
"raster-brightness-max": new DataConstantProperty(styleSpec["paint_raster"]["raster-brightness-max"]),
"raster-saturation": new DataConstantProperty(styleSpec["paint_raster"]["raster-saturation"]),
"raster-contrast": new DataConstantProperty(styleSpec["paint_raster"]["raster-contrast"]),
"raster-scaling": new DataConstantProperty(styleSpec["paint_raster"]["raster-scaling"]),
"raster-fade-duration": new DataConstantProperty(styleSpec["paint_raster"]["raster-fade-duration"]),
});

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/integration/render-tests/raster-scaling/default/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 16,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 10,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions test/integration/render-tests/raster-scaling/function/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 16,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 10,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0,
"raster-scaling": {
"stops": [
[
16,
"linear"
],
[
17,
"nearest"
]
]
}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test/integration/render-tests/raster-scaling/literal/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"version": 8,
"metadata": {
"test": {
"height": 256
}
},
"center": [
13.418056,
52.499167
],
"zoom": 16,
"sources": {
"satellite": {
"type": "raster",
"tiles": [
"local://tiles/{z}-{x}-{y}.satellite.png"
],
"maxzoom": 10,
"tileSize": 256
}
},
"layers": [
{
"id": "raster",
"type": "raster",
"source": "satellite",
"paint": {
"raster-fade-duration": 0,
"raster-scaling": "nearest"
}
}
]
}

0 comments on commit 2a8cd04

Please sign in to comment.