From 3261d29b83b9268357ffed563bff184f68294a4f Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 8 May 2017 13:36:29 -0400 Subject: [PATCH] skip pattern layer when pattern is missing No error or warning is printed for missing patterns. fix #4660 --- src/render/draw_background.js | 1 + src/render/draw_fill.js | 2 + src/render/draw_fill_extrusion.js | 1 + src/render/pattern.js | 16 ++++- .../background-pattern/missing/expected.png | Bin 0 -> 108 bytes .../background-pattern/missing/style.json | 20 ++++++ .../missing/expected.png | Bin 0 -> 600 bytes .../fill-extrusion-pattern/missing/style.json | 68 ++++++++++++++++++ .../fill-pattern/missing/expected.png | Bin 0 -> 108 bytes .../fill-pattern/missing/style.json | 53 ++++++++++++++ 10 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 test/integration/render-tests/background-pattern/missing/expected.png create mode 100644 test/integration/render-tests/background-pattern/missing/style.json create mode 100644 test/integration/render-tests/fill-extrusion-pattern/missing/expected.png create mode 100644 test/integration/render-tests/fill-extrusion-pattern/missing/style.json create mode 100644 test/integration/render-tests/fill-pattern/missing/expected.png create mode 100644 test/integration/render-tests/fill-pattern/missing/style.json diff --git a/src/render/draw_background.js b/src/render/draw_background.js index ad75fbfa241..d90a1a9f39a 100644 --- a/src/render/draw_background.js +++ b/src/render/draw_background.js @@ -21,6 +21,7 @@ function drawBackground(painter, sourceCache, layer) { let program; if (image) { + if (pattern.isPatternMissing(image, painter)) return; program = painter.useProgram('fillPattern', painter.basicFillProgramConfiguration); pattern.prepare(image, painter, program); painter.tileExtentPatternVAO.bind(gl, program, painter.tileExtentBuffer); diff --git a/src/render/draw_fill.js b/src/render/draw_fill.js index a08454d12b7..b01b2f2039a 100644 --- a/src/render/draw_fill.js +++ b/src/render/draw_fill.js @@ -42,6 +42,8 @@ function drawFill(painter, sourceCache, layer, coords) { } function drawFillTiles(painter, sourceCache, layer, coords, drawFn) { + if (pattern.isPatternMissing(layer.paint['fill-pattern'], painter)) return; + let firstTile = true; for (const coord of coords) { const tile = sourceCache.getTile(coord); diff --git a/src/render/draw_fill_extrusion.js b/src/render/draw_fill_extrusion.js index a5a4c7c9161..e429d730fc0 100644 --- a/src/render/draw_fill_extrusion.js +++ b/src/render/draw_fill_extrusion.js @@ -151,6 +151,7 @@ function drawExtrusion(painter, source, layer, coord) { programConfiguration.setUniforms(gl, program, layer, {zoom: painter.transform.zoom}); if (image) { + if (pattern.isPatternMissing(image, painter)) return; pattern.prepare(image, painter, program); pattern.setTile(tile, painter, program); gl.uniform1f(program.u_height_factor, -Math.pow(2, coord.z) / tile.tileSize / 8); diff --git a/src/render/pattern.js b/src/render/pattern.js index cfe3539caaf..45ebd48af12 100644 --- a/src/render/pattern.js +++ b/src/render/pattern.js @@ -1,13 +1,27 @@ 'use strict'; +const assert = require('assert'); + const pixelsToTileUnits = require('../source/pixels_to_tile_units'); +/** + * Checks whether a pattern image is needed, and if it is, whether it is not loaded. + * + * @returns {boolean} true if a needed image is missing and rendering needs to be skipped. + */ +exports.isPatternMissing = function(image, painter) { + if (!image) return false; + const imagePosA = painter.spriteAtlas.getPosition(image.from, true); + const imagePosB = painter.spriteAtlas.getPosition(image.to, true); + return !imagePosA || !imagePosB; +}; + exports.prepare = function (image, painter, program) { const gl = painter.gl; const imagePosA = painter.spriteAtlas.getPosition(image.from, true); const imagePosB = painter.spriteAtlas.getPosition(image.to, true); - if (!imagePosA || !imagePosB) return; + assert(imagePosA && imagePosB); gl.uniform1i(program.u_image, 0); gl.uniform2fv(program.u_pattern_tl_a, imagePosA.tl); diff --git a/test/integration/render-tests/background-pattern/missing/expected.png b/test/integration/render-tests/background-pattern/missing/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..724d17cd7d363c15e2712b76e90d158b55fb812b GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Or9=|Ar*{or0OmKd8#1Z+k=d} nK=vVp-^=Ux%oBi2WN=_FgM$MDW1#iXi6CK5S3j3^P6+m3x=TQgAc*(& tU?Wh1;qZdr!RH^aTm`X5!N?4O9ZZZB42-+&uWbkU-_zC4Wt~$(699R}7`6Za literal 0 HcmV?d00001 diff --git a/test/integration/render-tests/fill-extrusion-pattern/missing/style.json b/test/integration/render-tests/fill-extrusion-pattern/missing/style.json new file mode 100644 index 00000000000..adb17f0672b --- /dev/null +++ b/test/integration/render-tests/fill-extrusion-pattern/missing/style.json @@ -0,0 +1,68 @@ +{ + "version": 8, + "metadata": { + "test": { + "height": 256, + "ignored": { + "js": "https://github.com/mapbox/mapbox-gl-js/issues/3327", + "native": "https://github.com/mapbox/mapbox-gl-js/issues/3327" + } + } + }, + "sources": { + "geojson": { + "type": "geojson", + "data": { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": { + "property": 20 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ [ -0.0004, 0 ], + [ -0.0002, 0.0002 ], + [ 0.0000, 0 ], + [ -0.0002, -0.0002 ], + [ -0.0004, 0 ] ] + ] + } + }, + { + "type": "Feature", + "properties": { + "property": 20 + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ [ -0.0000, -0.0002 ], + [ -0.0000, 0.0002 ], + [ 0.0003, 0.0002 ], + [ 0.0003, -0.0002 ], + [ -0.0000, -0.0002 ] ] + ] + } + } + ] + } + } + }, + "sprite": "local://sprites/emerald", + "pitch": 60, + "zoom": 18, + "layers": [ + { + "id": "extrusion", + "type": "fill-extrusion", + "source": "geojson", + "paint": { + "fill-extrusion-pattern": "missing", + "fill-extrusion-height": 10 + } + } + ] +} diff --git a/test/integration/render-tests/fill-pattern/missing/expected.png b/test/integration/render-tests/fill-pattern/missing/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..724d17cd7d363c15e2712b76e90d158b55fb812b GIT binary patch literal 108 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=Or9=|Ar*{or0OmKd8#1Z+k=d} nK=vVp-^=Ux%oBi2WN=_FgM$MDW1#iXi6CK5S3j3^P6