@pixi/core
Version:
Core PixiJS
53 lines (50 loc) • 1.61 kB
JavaScript
import { TARGETS } from '@pixi/constants';
import { AbstractMultiResource } from './AbstractMultiResource.mjs';
class ArrayResource extends AbstractMultiResource {
constructor(source, options) {
const { width, height } = options || {};
let urls;
let length;
if (Array.isArray(source)) {
urls = source;
length = source.length;
} else {
length = source;
}
super(length, { width, height });
if (urls) {
this.initFromArray(urls, options);
}
}
addBaseTextureAt(baseTexture, index) {
if (baseTexture.resource) {
this.addResourceAt(baseTexture.resource, index);
} else {
throw new Error("ArrayResource does not support RenderTexture");
}
return this;
}
bind(baseTexture) {
super.bind(baseTexture);
baseTexture.target = TARGETS.TEXTURE_2D_ARRAY;
}
upload(renderer, texture, glTexture) {
const { length, itemDirtyIds, items } = this;
const { gl } = renderer;
if (glTexture.dirtyId < 0) {
gl.texImage3D(gl.TEXTURE_2D_ARRAY, 0, glTexture.internalFormat, this._width, this._height, length, 0, texture.format, glTexture.type, null);
}
for (let i = 0; i < length; i++) {
const item = items[i];
if (itemDirtyIds[i] < item.dirtyId) {
itemDirtyIds[i] = item.dirtyId;
if (item.valid) {
gl.texSubImage3D(gl.TEXTURE_2D_ARRAY, 0, 0, 0, i, item.resource.width, item.resource.height, 1, texture.format, glTexture.type, item.resource.source);
}
}
}
return true;
}
}
export { ArrayResource };
//# sourceMappingURL=ArrayResource.mjs.map