Skip to content

Commit dd2a355

Browse files
spepsunderoot
authored andcommitted
[GLJS-1054] Fix canvas source not rendering correctly when canvas is being resized smaller (internal-2104)
1 parent b1f0021 commit dd2a355

File tree

5 files changed

+72
-2
lines changed

5 files changed

+72
-2
lines changed

src/render/texture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class Texture {
6565
const {gl} = context;
6666
const {x, y} = options && options.position ? options.position : {x: 0, y: 0};
6767

68-
const width = Math.max(x + srcWidth, this.size ? this.size[0] : 0);
69-
const height = Math.max(y + srcHeight, this.size ? this.size[1] : 0);
68+
const width = x + srcWidth;
69+
const height = y + srcHeight;
7070

7171
if (this.size && (this.size[0] !== width || this.size[1] !== height)) {
7272
gl.bindTexture(gl.TEXTURE_2D, null);
226 KB
Loading

test/integration/lib/operation-handlers.js

+2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ function updateCanvas(imagePath) {
256256
const image = new Image();
257257
image.src = imagePath.replace('./', '');
258258
image.onload = () => {
259+
canvas.width = image.width;
260+
canvas.height = image.height;
259261
resolve(ctx.drawImage(image, 0, 0, image.width, image.height));
260262
};
261263

Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"version": 8,
3+
"metadata": {
4+
"test": {
5+
"width": 512,
6+
"height": 512,
7+
"addFakeCanvas": {
8+
"id": "fake-canvas",
9+
"image": "./image/1.png"
10+
},
11+
"operations": [
12+
["wait"],
13+
["updateFakeCanvas", "canvas", "./image/0-half-size.png", "./image/0-half-size.png"]
14+
]
15+
}
16+
},
17+
"center": [
18+
-122,
19+
37
20+
],
21+
"zoom": 2,
22+
"projection": {
23+
"name": "globe"
24+
},
25+
"sources": {
26+
"canvas": {
27+
"type": "canvas",
28+
"animate": false,
29+
"coordinates": [
30+
[
31+
-112,
32+
27
33+
],
34+
[
35+
-132,
36+
27
37+
],
38+
[
39+
-132,
40+
47
41+
],
42+
[
43+
-112,
44+
47
45+
]
46+
],
47+
"canvas": "fake-canvas"
48+
}
49+
},
50+
"layers": [
51+
{
52+
"id": "background",
53+
"type": "background",
54+
"paint": {
55+
"background-color": "#ff00ff"
56+
}
57+
},
58+
{
59+
"id": "canvas",
60+
"type": "raster",
61+
"source": "canvas",
62+
"paint": {
63+
"raster-fade-duration": 0
64+
}
65+
}
66+
]
67+
}
68+

0 commit comments

Comments
 (0)