Skip to content

Commit efb7884

Browse files
karimnaajiSnailBones
authored andcommitted
Fix "output": "terrainDepth" render test option (mapbox#10754)
* Fix terrainDepth ouput render test option * Fixup
1 parent 990010d commit efb7884

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

test/integration/lib/render.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ setupHTML();
4141

4242
const {canvas: expectedCanvas, ctx: expectedCtx} = createCanvas();
4343
const {canvas: diffCanvas, ctx: diffCtx} = createCanvas();
44+
const {canvas: terrainDepthCanvas, ctx: terrainDepthCtx} = createCanvas();
4445
let map;
4546

4647
tape.onFinish(() => {
@@ -191,10 +192,11 @@ async function runTest(t) {
191192
// 1. get pixel data from test canvas as Uint8Array
192193
if (options.output === "terrainDepth") {
193194
const pixels = drawTerrainDepth(map, w, h);
194-
actualImageData = Uint8Array.from(pixels);
195-
}
196-
197-
if (!actualImageData) {
195+
if (!pixels) {
196+
throw new Error('Failed to render terrain depth, make sure that terrain is enabled on the render test');
197+
}
198+
actualImageData = Uint8ClampedArray.from(pixels);
199+
} else {
198200
actualImageData = new Uint8Array(gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
199201
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, actualImageData);
200202

@@ -230,7 +232,17 @@ async function runTest(t) {
230232
}
231233

232234
let fileInfo;
233-
const actual = map.getCanvas().toDataURL();
235+
let actual;
236+
237+
if (options.output === "terrainDepth") {
238+
terrainDepthCanvas.width = w;
239+
terrainDepthCanvas.height = h;
240+
const terrainDepthData = new ImageData(actualImageData, w, h);
241+
terrainDepthCtx.putImageData(terrainDepthData, 0, 0);
242+
actual = terrainDepthCanvas.toDataURL();
243+
} else {
244+
actual = map.getCanvas().toDataURL();
245+
}
234246

235247
if (process.env.UPDATE) {
236248
fileInfo = [

0 commit comments

Comments
 (0)