Skip to content

Commit 9722a0d

Browse files
authored
Merge pull request #5060 from ShenpaiSharma/Issue_#5046
Fixes tint in 2d canvas with webgl p5.Graphics
2 parents a509c43 + 4159995 commit 9722a0d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/image/filters.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,25 @@ Filters._toPixels = function(canvas) {
3535
if (canvas instanceof ImageData) {
3636
return canvas.data;
3737
} else {
38-
return canvas
39-
.getContext('2d')
40-
.getImageData(0, 0, canvas.width, canvas.height).data;
38+
if (canvas.getContext('2d')) {
39+
return canvas
40+
.getContext('2d')
41+
.getImageData(0, 0, canvas.width, canvas.height).data;
42+
} else if (canvas.getContext('webgl')) {
43+
const gl = canvas.getContext('webgl');
44+
const len = gl.drawingBufferWidth * gl.drawingBufferHeight * 4;
45+
const data = new Uint8Array(len);
46+
gl.readPixels(
47+
0,
48+
0,
49+
canvas.width,
50+
canvas.height,
51+
gl.RGBA,
52+
gl.UNSIGNED_BYTE,
53+
data
54+
);
55+
return data;
56+
}
4157
}
4258
};
4359

0 commit comments

Comments
 (0)