UNPKG

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