1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var constants = require('@pixi/constants');
|
6 | var AbstractMultiResource = require('./AbstractMultiResource.js');
|
7 |
|
8 | class ArrayResource extends AbstractMultiResource.AbstractMultiResource {
|
9 | constructor(source, options) {
|
10 | const { width, height } = options || {};
|
11 | let urls;
|
12 | let length;
|
13 | if (Array.isArray(source)) {
|
14 | urls = source;
|
15 | length = source.length;
|
16 | } else {
|
17 | length = source;
|
18 | }
|
19 | super(length, { width, height });
|
20 | if (urls) {
|
21 | this.initFromArray(urls, options);
|
22 | }
|
23 | }
|
24 | addBaseTextureAt(baseTexture, index) {
|
25 | if (baseTexture.resource) {
|
26 | this.addResourceAt(baseTexture.resource, index);
|
27 | } else {
|
28 | throw new Error("ArrayResource does not support RenderTexture");
|
29 | }
|
30 | return this;
|
31 | }
|
32 | bind(baseTexture) {
|
33 | super.bind(baseTexture);
|
34 | baseTexture.target = constants.TARGETS.TEXTURE_2D_ARRAY;
|
35 | }
|
36 | upload(renderer, texture, glTexture) {
|
37 | const { length, itemDirtyIds, items } = this;
|
38 | const { gl } = renderer;
|
39 | if (glTexture.dirtyId < 0) {
|
40 | gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, glTexture.internalFormat, this._width, this._height, length, 0, texture.format, glTexture.type, null);
|
41 | }
|
42 | for (let i = 0; i < length; i++) {
|
43 | const item = items[i];
|
44 | if (itemDirtyIds[i] < item.dirtyId) {
|
45 | itemDirtyIds[i] = item.dirtyId;
|
46 | if (item.valid) {
|
47 | gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, i, item.resource.width, item.resource.height, 1, texture.format, glTexture.type, item.resource.source);
|
48 | }
|
49 | }
|
50 | }
|
51 | return true;
|
52 | }
|
53 | }
|
54 |
|
55 | exports.ArrayResource = ArrayResource;
|
56 |
|