1 | {"version":3,"file":"ArrayResource.mjs","sources":["../../../src/textures/resources/ArrayResource.ts"],"sourcesContent":["import { TARGETS } from '@pixi/constants';\nimport { AbstractMultiResource } from './AbstractMultiResource';\n\nimport type { ISize } from '@pixi/math';\nimport type { Renderer } from '../../Renderer';\nimport type { BaseTexture } from '../BaseTexture';\nimport type { GLTexture } from '../GLTexture';\nimport type { BaseImageResource } from './BaseImageResource';\n\n/**\n * A resource that contains a number of sources.\n * @memberof PIXI\n */\nexport class ArrayResource extends AbstractMultiResource\n{\n /**\n * @param source - Number of items in array or the collection\n * of image URLs to use. Can also be resources, image elements, canvas, etc.\n * @param options - Options to apply to {@link PIXI.autoDetectResource}\n * @param {number} [options.width] - Width of the resource\n * @param {number} [options.height] - Height of the resource\n */\n constructor(source: number | Array<any>, options?: ISize)\n {\n const { width, height } = options || {};\n\n let urls;\n let length: number;\n\n if (Array.isArray(source))\n {\n urls = source;\n length = source.length;\n }\n else\n {\n length = source;\n }\n\n super(length, { width, height });\n\n if (urls)\n {\n this.initFromArray(urls, options);\n }\n }\n\n /**\n * Set a baseTexture by ID,\n * ArrayResource just takes resource from it, nothing more\n * @param baseTexture\n * @param index - Zero-based index of resource to set\n * @returns - Instance for chaining\n */\n addBaseTextureAt(baseTexture: BaseTexture, index: number): this\n {\n if (baseTexture.resource)\n {\n this.addResourceAt(baseTexture.resource, index);\n }\n else\n {\n throw new Error('ArrayResource does not support RenderTexture');\n }\n\n return this;\n }\n\n /**\n * Add binding\n * @param baseTexture\n */\n bind(baseTexture: BaseTexture): void\n {\n super.bind(baseTexture);\n\n baseTexture.target = TARGETS.TEXTURE_2D_ARRAY;\n }\n\n /**\n * Upload the resources to the GPU.\n * @param renderer\n * @param texture\n * @param glTexture\n * @returns - whether texture was uploaded\n */\n upload(renderer: Renderer, texture: BaseTexture, glTexture: GLTexture): boolean\n {\n const { length, itemDirtyIds, items } = this;\n const { gl } = renderer;\n\n if (glTexture.dirtyId < 0)\n {\n gl.texImage3D(\n gl.TEXTURE_2D_ARRAY,\n 0,\n glTexture.internalFormat,\n this._width,\n this._height,\n length,\n 0,\n texture.format,\n glTexture.type,\n null\n );\n }\n\n for (let i = 0; i < length; i++)\n {\n const item = items[i];\n\n if (itemDirtyIds[i] < item.dirtyId)\n {\n itemDirtyIds[i] = item.dirtyId;\n if (item.valid)\n {\n gl.texSubImage3D(\n gl.TEXTURE_2D_ARRAY,\n 0,\n 0, // xoffset\n 0, // yoffset\n i, // zoffset\n item.resource.width,\n item.resource.height,\n 1,\n texture.format,\n glTexture.type,\n (item.resource as BaseImageResource).source\n );\n }\n }\n }\n\n return true;\n }\n}\n"],"names":[],"mappings":";;AAaO,MAAM,sBAAsB,sBACnC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,YAAY,QAA6B,SACzC;AACI,UAAM,EAAE,OAAO,WAAW,WAAW,CAAA;AAErC,QAAI,MACA;AAEA,UAAM,QAAQ,MAAM,KAEpB,OAAO,QACP,SAAS,OAAO,UAIhB,SAAS,QAGb,MAAM,QAAQ,EAAE,OAAO,QAAQ,GAE3B,QAEA,KAAK,cAAc,MAAM,OAAO;AAAA,EAExC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,iBAAiB,aAA0B,OAC3C;AACI,QAAI,YAAY;AAEP,WAAA,cAAc,YAAY,UAAU,KAAK;AAAA;AAIxC,YAAA,IAAI,MAAM,8CAA8C;AAG3D,WAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,KAAK,aACL;AACI,UAAM,KAAK,WAAW,GAEtB,YAAY,SAAS,QAAQ;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,UAAoB,SAAsB,WACjD;AACU,UAAA,EAAE,QAAQ,cAAc,MAAA,IAAU,MAClC,EAAE,GAAO,IAAA;AAEX,cAAU,UAAU,KAEpB,GAAG;AAAA,MACC,GAAG;AAAA,MACH;AAA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