1 | import { TARGETS } from "@pixi/constants";
|
2 | import { AbstractMultiResource } from "./AbstractMultiResource.mjs";
|
3 | class ArrayResource extends AbstractMultiResource {
|
4 | |
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | constructor(source, options) {
|
12 | const { width, height } = options || {};
|
13 | let urls, length;
|
14 | Array.isArray(source) ? (urls = source, length = source.length) : length = source, super(length, { width, height }), urls && this.initFromArray(urls, options);
|
15 | }
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | addBaseTextureAt(baseTexture, index) {
|
24 | if (baseTexture.resource)
|
25 | this.addResourceAt(baseTexture.resource, index);
|
26 | else
|
27 | throw new Error("ArrayResource does not support RenderTexture");
|
28 | return this;
|
29 | }
|
30 | |
31 |
|
32 |
|
33 |
|
34 | bind(baseTexture) {
|
35 | super.bind(baseTexture), baseTexture.target = TARGETS.TEXTURE_2D_ARRAY;
|
36 | }
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | upload(renderer, texture, glTexture) {
|
45 | const { length, itemDirtyIds, items } = this, { gl } = renderer;
|
46 | glTexture.dirtyId < 0 && gl.texImage3D(
|
47 | gl.TEXTURE_2D_ARRAY,
|
48 | 0,
|
49 | glTexture.internalFormat,
|
50 | this._width,
|
51 | this._height,
|
52 | length,
|
53 | 0,
|
54 | texture.format,
|
55 | glTexture.type,
|
56 | null
|
57 | );
|
58 | for (let i = 0; i < length; i++) {
|
59 | const item = items[i];
|
60 | itemDirtyIds[i] < item.dirtyId && (itemDirtyIds[i] = item.dirtyId, item.valid && gl.texSubImage3D(
|
61 | gl.TEXTURE_2D_ARRAY,
|
62 | 0,
|
63 | 0,
|
64 |
|
65 | 0,
|
66 |
|
67 | i,
|
68 |
|
69 | item.resource.width,
|
70 | item.resource.height,
|
71 | 1,
|
72 | texture.format,
|
73 | glTexture.type,
|
74 | item.resource.source
|
75 | ));
|
76 | }
|
77 | return !0;
|
78 | }
|
79 | }
|
80 | export {
|
81 | ArrayResource
|
82 | };
|
83 |
|