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