@pixi/core
Version:
Core PixiJS
41 lines (36 loc) • 1.4 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var constants = require('@pixi/constants');
var Resource = require('./Resource.js');
class BufferResource extends Resource.Resource {
constructor(source, options) {
const { width, height } = options || {};
if (!width || !height) {
throw new Error("BufferResource width or height invalid");
}
super(width, height);
this.data = source;
}
upload(renderer, baseTexture, glTexture) {
const gl = renderer.gl;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === constants.ALPHA_MODES.UNPACK);
const width = baseTexture.realWidth;
const height = baseTexture.realHeight;
if (glTexture.width === width && glTexture.height === height) {
gl.texSubImage2D(baseTexture.target, 0, 0, 0, width, height, baseTexture.format, glTexture.type, this.data);
} else {
glTexture.width = width;
glTexture.height = height;
gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, width, height, 0, baseTexture.format, glTexture.type, this.data);
}
return true;
}
dispose() {
this.data = null;
}
static test(source) {
return source instanceof Float32Array || source instanceof Uint8Array || source instanceof Uint32Array;
}
}
exports.BufferResource = BufferResource;
//# sourceMappingURL=BufferResource.js.map
;