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 | const _CubeResource = class extends AbstractMultiResource.AbstractMultiResource {
|
9 | constructor(source, options) {
|
10 | const { width, height, autoLoad, linkBaseTexture } = options || {};
|
11 | if (source && source.length !== _CubeResource.SIDES) {
|
12 | throw new Error(`Invalid length. Got ${source.length}, expected 6`);
|
13 | }
|
14 | super(6, { width, height });
|
15 | for (let i = 0; i < _CubeResource.SIDES; i++) {
|
16 | this.items[i].target = constants.TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + i;
|
17 | }
|
18 | this.linkBaseTexture = linkBaseTexture !== false;
|
19 | if (source) {
|
20 | this.initFromArray(source, options);
|
21 | }
|
22 | if (autoLoad !== false) {
|
23 | this.load();
|
24 | }
|
25 | }
|
26 | bind(baseTexture) {
|
27 | super.bind(baseTexture);
|
28 | baseTexture.target = constants.TARGETS.TEXTURE_CUBE_MAP;
|
29 | }
|
30 | addBaseTextureAt(baseTexture, index, linkBaseTexture) {
|
31 | if (linkBaseTexture === void 0) {
|
32 | linkBaseTexture = this.linkBaseTexture;
|
33 | }
|
34 | if (!this.items[index]) {
|
35 | throw new Error(`Index ${index} is out of bounds`);
|
36 | }
|
37 | if (!this.linkBaseTexture || baseTexture.parentTextureArray || Object.keys(baseTexture._glTextures).length > 0) {
|
38 | if (baseTexture.resource) {
|
39 | this.addResourceAt(baseTexture.resource, index);
|
40 | } else {
|
41 | throw new Error(`CubeResource does not support copying of renderTexture.`);
|
42 | }
|
43 | } else {
|
44 | baseTexture.target = constants.TARGETS.TEXTURE_CUBE_MAP_POSITIVE_X + index;
|
45 | baseTexture.parentTextureArray = this.baseTexture;
|
46 | this.items[index] = baseTexture;
|
47 | }
|
48 | if (baseTexture.valid && !this.valid) {
|
49 | this.resize(baseTexture.realWidth, baseTexture.realHeight);
|
50 | }
|
51 | this.items[index] = baseTexture;
|
52 | return this;
|
53 | }
|
54 | upload(renderer, _baseTexture, glTexture) {
|
55 | const dirty = this.itemDirtyIds;
|
56 | for (let i = 0; i < _CubeResource.SIDES; i++) {
|
57 | const side = this.items[i];
|
58 | if (dirty[i] < side.dirtyId || glTexture.dirtyId < _baseTexture.dirtyId) {
|
59 | if (side.valid && side.resource) {
|
60 | side.resource.upload(renderer, side, glTexture);
|
61 | dirty[i] = side.dirtyId;
|
62 | } else if (dirty[i] < -1) {
|
63 | renderer.gl.texImage2D(side.target, 0, glTexture.internalFormat, _baseTexture.realWidth, _baseTexture.realHeight, 0, _baseTexture.format, glTexture.type, null);
|
64 | dirty[i] = -1;
|
65 | }
|
66 | }
|
67 | }
|
68 | return true;
|
69 | }
|
70 | static test(source) {
|
71 | return Array.isArray(source) && source.length === _CubeResource.SIDES;
|
72 | }
|
73 | };
|
74 | let CubeResource = _CubeResource;
|
75 | CubeResource.SIDES = 6;
|
76 |
|
77 | exports.CubeResource = CubeResource;
|
78 |
|