UNPKG

5.82 kBSource Map (JSON)View Raw
1{"version":3,"file":"ArrayResource.js","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":["AbstractMultiResource","TARGETS"],"mappings":";;;;;;;AAaO,MAAM,sBAAsBA,2CACnC,CAAA;AAAA,EAQI,WAAA,CAAY,QAA6B,OACzC,EAAA;AACI,IAAA,MAAM,EAAE,KAAA,EAAO,MAAW,EAAA,GAAA,OAAA,IAAW,EAAC,CAAA;AAEtC,IAAI,IAAA,IAAA,CAAA;AACJ,IAAI,IAAA,MAAA,CAAA;AAEJ,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,MAAM,CACxB,EAAA;AACI,MAAO,IAAA,GAAA,MAAA,CAAA;AACP,MAAA,MAAA,GAAS,MAAO,CAAA,MAAA,CAAA;AAAA,KAGpB,MAAA;AACI,MAAS,MAAA,GAAA,MAAA,CAAA;AAAA,KACb;AAEA,IAAA,KAAA,CAAM,MAAQ,EAAA,EAAE,KAAO,EAAA,MAAA,EAAQ,CAAA,CAAA;AAE/B,IAAA,IAAI,IACJ,EAAA;AACI,MAAK,IAAA,CAAA,aAAA,CAAc,MAAM,OAAO,CAAA,CAAA;AAAA,KACpC;AAAA,GACJ;AAAA,EASA,gBAAA,CAAiB,aAA0B,KAC3C,EAAA;AACI,IAAA,IAAI,YAAY,QAChB,EAAA;AACI,MAAK,IAAA,CAAA,aAAA,CAAc,WAAY,CAAA,QAAA,EAAU,KAAK,CAAA,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