UNPKG

1.29 kBJavaScriptView Raw
1import { ALPHA_MODES } from '@pixi/constants';
2import { Resource } from './Resource.mjs';
3
4class BufferResource extends Resource {
5 constructor(source, options) {
6 const { width, height } = options || {};
7 if (!width || !height) {
8 throw new Error("BufferResource width or height invalid");
9 }
10 super(width, height);
11 this.data = source;
12 }
13 upload(renderer, baseTexture, glTexture) {
14 const gl = renderer.gl;
15 gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
16 const width = baseTexture.realWidth;
17 const height = baseTexture.realHeight;
18 if (glTexture.width === width && glTexture.height === height) {
19 gl.texSubImage2D(baseTexture.target, 0, 0, 0, width, height, baseTexture.format, glTexture.type, this.data);
20 } else {
21 glTexture.width = width;
22 glTexture.height = height;
23 gl.texImage2D(baseTexture.target, 0, glTexture.internalFormat, width, height, 0, baseTexture.format, glTexture.type, this.data);
24 }
25 return true;
26 }
27 dispose() {
28 this.data = null;
29 }
30 static test(source) {
31 return source instanceof Float32Array || source instanceof Uint8Array || source instanceof Uint32Array;
32 }
33}
34
35export { BufferResource };
36//# sourceMappingURL=BufferResource.mjs.map