1 | import { ALPHA_MODES } from "@pixi/constants";
|
2 | import { Resource } from "./Resource.mjs";
|
3 | class BufferResource extends Resource {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | constructor(source, options) {
|
12 | const { width, height } = options || {};
|
13 | if (!width || !height)
|
14 | throw new Error("BufferResource width or height invalid");
|
15 | super(width, height), this.data = source, this.unpackAlignment = options.unpackAlignment ?? 4;
|
16 | }
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | upload(renderer, baseTexture, glTexture) {
|
25 | const gl = renderer.gl;
|
26 | gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment), gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);
|
27 | const width = baseTexture.realWidth, height = baseTexture.realHeight;
|
28 | return glTexture.width === width && glTexture.height === height ? gl.texSubImage2D(
|
29 | baseTexture.target,
|
30 | 0,
|
31 | 0,
|
32 | 0,
|
33 | width,
|
34 | height,
|
35 | baseTexture.format,
|
36 | glTexture.type,
|
37 | this.data
|
38 | ) : (glTexture.width = width, glTexture.height = height, gl.texImage2D(
|
39 | baseTexture.target,
|
40 | 0,
|
41 | glTexture.internalFormat,
|
42 | width,
|
43 | height,
|
44 | 0,
|
45 | baseTexture.format,
|
46 | glTexture.type,
|
47 | this.data
|
48 | )), !0;
|
49 | }
|
50 |
|
51 | dispose() {
|
52 | this.data = null;
|
53 | }
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 | static test(source) {
|
60 | return source === null || source instanceof Int8Array || source instanceof Uint8Array || source instanceof Uint8ClampedArray || source instanceof Int16Array || source instanceof Uint16Array || source instanceof Int32Array || source instanceof Uint32Array || source instanceof Float32Array;
|
61 | }
|
62 | }
|
63 | export {
|
64 | BufferResource
|
65 | };
|
66 |
|