Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix ImageBitmap instances not being passed to appropriate gl.texImage…
…2D call (mapbox#9103)
  • Loading branch information
Arindam Bose committed Dec 13, 2019
1 parent a41d3c5 commit 920bd16
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/render/texture.js
@@ -1,7 +1,7 @@
// @flow

import window from '../util/window';
const {HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageData} = window;
const {HTMLImageElement, HTMLCanvasElement, HTMLVideoElement, ImageData, ImageBitmap} = window;

import type Context from '../gl/context';
import type {RGBAImage, AlphaImage} from '../util/image';
Expand Down Expand Up @@ -31,7 +31,8 @@ export type TextureImage =
| HTMLCanvasElement
| HTMLVideoElement
| ImageData
| EmptyImage;
| EmptyImage
| ImageBitmap;

class Texture {
context: Context;
Expand Down Expand Up @@ -65,15 +66,15 @@ class Texture {
if (resize) {
this.size = [width, height];

if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData) {
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || (ImageBitmap && image instanceof ImageBitmap)) {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, gl.UNSIGNED_BYTE, image);
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, image.data);
}

} else {
const {x, y} = position || {x: 0, y: 0};
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData) {
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || (ImageBitmap && image instanceof ImageBitmap)) {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, image.data);
Expand Down

0 comments on commit 920bd16

Please sign in to comment.