1 | import { ALPHA_MODES } from "@pixi/constants";
|
2 | import { determineCrossOrigin } from "@pixi/utils";
|
3 | import { Resource } from "./Resource.mjs";
|
4 | class BaseImageResource extends Resource {
|
5 | |
6 |
|
7 |
|
8 | constructor(source) {
|
9 | const sourceAny = source, width = sourceAny.naturalWidth || sourceAny.videoWidth || sourceAny.displayWidth || sourceAny.width, height = sourceAny.naturalHeight || sourceAny.videoHeight || sourceAny.displayHeight || sourceAny.height;
|
10 | super(width, height), this.source = source, this.noSubImage = !1;
|
11 | }
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | static crossOrigin(element, url, crossorigin) {
|
19 | crossorigin === void 0 && !url.startsWith("data:") ? element.crossOrigin = determineCrossOrigin(url) : crossorigin !== !1 && (element.crossOrigin = typeof crossorigin == "string" ? crossorigin : "anonymous");
|
20 | }
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | upload(renderer, baseTexture, glTexture, source) {
|
30 | const gl = renderer.gl, width = baseTexture.realWidth, height = baseTexture.realHeight;
|
31 | if (source = source || this.source, typeof HTMLImageElement < "u" && source instanceof HTMLImageElement) {
|
32 | if (!source.complete || source.naturalWidth === 0)
|
33 | return !1;
|
34 | } else if (typeof HTMLVideoElement < "u" && source instanceof HTMLVideoElement && source.readyState <= 1)
|
35 | return !1;
|
36 | return gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK), !this.noSubImage && baseTexture.target === gl.TEXTURE_2D && glTexture.width === width && glTexture.height === height ? gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, baseTexture.format, glTexture.type, source) : (glTexture.width = width, glTexture.height = height, gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, baseTexture.format, glTexture.type, source)), !0;
|
37 | }
|
38 | |
39 |
|
40 |
|
41 |
|
42 | update() {
|
43 | if (this.destroyed)
|
44 | return;
|
45 | const source = this.source, width = source.naturalWidth || source.videoWidth || source.width, height = source.naturalHeight || source.videoHeight || source.height;
|
46 | this.resize(width, height), super.update();
|
47 | }
|
48 |
|
49 | dispose() {
|
50 | this.source = null;
|
51 | }
|
52 | }
|
53 | export {
|
54 | BaseImageResource
|
55 | };
|
56 |
|