UNPKG

@pixi/core

Version:
37 lines (34 loc) 1.29 kB
import { ALPHA_MODES } from '@pixi/constants'; import { Resource } from './Resource.mjs'; class BufferResource extends 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 === 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; } } export { BufferResource }; //# sourceMappingURL=BufferResource.mjs.map