@pixi/core
Version:
Core PixiJS
66 lines (61 loc) • 2.45 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var constants = require('@pixi/constants');
var utils = require('@pixi/utils');
var Resource = require('./Resource.js');
class BaseImageResource extends Resource.Resource {
constructor(source) {
const sourceAny = source;
const width = sourceAny.naturalWidth || sourceAny.videoWidth || sourceAny.width;
const height = sourceAny.naturalHeight || sourceAny.videoHeight || sourceAny.height;
super(width, height);
this.source = source;
this.noSubImage = false;
}
static crossOrigin(element, url, crossorigin) {
if (crossorigin === void 0 && !url.startsWith("data:")) {
element.crossOrigin = utils.determineCrossOrigin(url);
} else if (crossorigin !== false) {
element.crossOrigin = typeof crossorigin === "string" ? crossorigin : "anonymous";
}
}
upload(renderer, baseTexture, glTexture, source) {
const gl = renderer.gl;
const width = baseTexture.realWidth;
const height = baseTexture.realHeight;
source = source || this.source;
if (typeof HTMLImageElement !== "undefined" && source instanceof HTMLImageElement) {
if (!source.complete || source.naturalWidth === 0) {
return false;
}
} else if (typeof HTMLVideoElement !== "undefined" && source instanceof HTMLVideoElement) {
if (source.readyState <= 1 && source.buffered.length === 0) {
return false;
}
}
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === constants.ALPHA_MODES.UNPACK);
if (!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);
} else {
glTexture.width = width;
glTexture.height = height;
gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, baseTexture.format, glTexture.type, source);
}
return true;
}
update() {
if (this.destroyed) {
return;
}
const source = this.source;
const width = source.naturalWidth || source.videoWidth || source.width;
const height = source.naturalHeight || source.videoHeight || source.height;
this.resize(width, height);
super.update();
}
dispose() {
this.source = null;
}
}
exports.BaseImageResource = BaseImageResource;
//# sourceMappingURL=BaseImageResource.js.map
;