1 | {"version":3,"file":"BufferResource.js","sources":["../../../src/textures/resources/BufferResource.ts"],"sourcesContent":["import { ALPHA_MODES } from '@pixi/constants';\nimport { Resource } from './Resource';\n\nimport type { ISize } from '@pixi/math';\nimport type { Renderer } from '../../Renderer';\nimport type { BaseTexture } from '../BaseTexture';\nimport type { GLTexture } from '../GLTexture';\n\nexport type BufferType = null | Int8Array | Uint8Array | Uint8ClampedArray\n| Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array;\n\n/**\n * Constructor options for BufferResource.\n * @memberof PIXI\n */\nexport interface IBufferResourceOptions extends ISize\n{\n unpackAlignment?: 1 | 2 | 4 | 8\n}\n\n/**\n * Buffer resource with data of typed array.\n * @memberof PIXI\n */\nexport class BufferResource extends Resource\n{\n /** The data of this resource. */\n public data: BufferType;\n\n /** The alignment of the rows in the data. */\n public unpackAlignment: 1 | 2 | 4 | 8;\n\n /**\n * @param source - Source buffer\n * @param options - Options\n * @param {number} options.width - Width of the texture\n * @param {number} options.height - Height of the texture\n * @param {1|2|4|8} [options.unpackAlignment=4] - The alignment of the pixel rows.\n */\n constructor(source: BufferType, options: IBufferResourceOptions)\n {\n const { width, height } = options || {};\n\n if (!width || !height)\n {\n throw new Error('BufferResource width or height invalid');\n }\n\n super(width, height);\n\n this.data = source;\n this.unpackAlignment = options.unpackAlignment ?? 4;\n }\n\n /**\n * Upload the texture to the GPU.\n * @param renderer - Upload to the renderer\n * @param baseTexture - Reference to parent texture\n * @param glTexture - glTexture\n * @returns - true is success\n */\n upload(renderer: Renderer, baseTexture: BaseTexture, glTexture: GLTexture): boolean\n {\n const gl = renderer.gl;\n\n gl.pixelStorei(gl.UNPACK_ALIGNMENT, this.unpackAlignment);\n gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, baseTexture.alphaMode === ALPHA_MODES.UNPACK);\n\n const width = baseTexture.realWidth;\n const height = baseTexture.realHeight;\n\n if (glTexture.width === width && glTexture.height === height)\n {\n gl.texSubImage2D(\n baseTexture.target,\n 0,\n 0,\n 0,\n width,\n height,\n baseTexture.format,\n glTexture.type,\n this.data\n );\n }\n else\n {\n glTexture.width = width;\n glTexture.height = height;\n\n gl.texImage2D(\n baseTexture.target,\n 0,\n glTexture.internalFormat,\n width,\n height,\n 0,\n baseTexture.format,\n glTexture.type,\n this.data\n );\n }\n\n return true;\n }\n\n /** Destroy and don't use after this. */\n dispose(): void\n {\n this.data = null;\n }\n\n /**\n * Used to auto-detect the type of resource.\n * @param {*} source - The source object\n * @returns {boolean} `true` if buffer source\n */\n static test(source: unknown): source is BufferType\n {\n return source === null\n || source instanceof Int8Array\n || source instanceof Uint8Array\n || source instanceof Uint8ClampedArray\n || source instanceof Int16Array\n || source instanceof Uint16Array\n || source instanceof Int32Array\n || source instanceof Uint32Array\n || source instanceof Float32Array;\n }\n}\n"],"names":["Resource","ALPHA_MODES"],"mappings":";;AAwBO,MAAM,uBAAuBA,SAAAA,SACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcI,YAAY,QAAoB,SAChC;AACI,UAAM,EAAE,OAAO,WAAW,WAAW,CAAA;AAEjC,QAAA,CAAC,SAAS,CAAC;AAEL,YAAA,IAAI,MAAM,wCAAwC;AAG5D,UAAM,OAAO,MAAM,GAEnB,KAAK,OAAO,QACZ,KAAK,kBAAkB,QAAQ,mBAAmB;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,OAAO,UAAoB,aAA0B,WACrD;AACI,UAAM,KAAK,SAAS;AAEpB,OAAG,YAAY,GAAG,kBAAkB,KAAK,eAAe,GACxD,GAAG,YAAY,GAAG,gCAAgC,YAAY,cAAcC,UAAAA,YAAY,MAAM;AAE9F,UAAM,QAAQ,YAAY,WACpB,SAAS,YAAY;AAE3B,WAAI,UAAU,UAAU,SAAS,UAAU,WAAW,SAElD,GAAG;AAAA,MACC,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAA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