Files
nothoughts/node_modules/pixi.js/lib/rendering/renderers/shared/texture/TexturePool.mjs.map
2025-08-04 18:57:35 +02:00

1 line
8.4 KiB
Plaintext

{"version":3,"file":"TexturePool.mjs","sources":["../../../../../src/rendering/renderers/shared/texture/TexturePool.ts"],"sourcesContent":["import { nextPow2 } from '../../../../maths/misc/pow2';\nimport { TextureSource } from './sources/TextureSource';\nimport { Texture } from './Texture';\n\nimport type { TextureSourceOptions } from './sources/TextureSource';\n\nlet count = 0;\n\n/**\n * Texture pool, used by FilterSystem and plugins.\n *\n * Stores collection of temporary pow2 or screen-sized renderTextures\n *\n * If you use custom RenderTexturePool for your filters, you can use methods\n * `getFilterTexture` and `returnFilterTexture` same as in default pool\n * @memberof rendering\n * @name TexturePool\n */\nexport class TexturePoolClass\n{\n /** The default options for texture pool */\n public textureOptions: TextureSourceOptions;\n\n /**\n * Allow renderTextures of the same size as screen, not just pow2\n *\n * Automatically sets to true after `setScreenSize`\n * @default false\n */\n public enableFullScreen: boolean;\n\n private _texturePool: {[x in string | number]: Texture[]};\n private _poolKeyHash: Record<number, number> = Object.create(null);\n\n /**\n * @param textureOptions - options that will be passed to BaseRenderTexture constructor\n * @param {SCALE_MODE} [textureOptions.scaleMode] - See {@link SCALE_MODE} for possible values.\n */\n constructor(textureOptions?: TextureSourceOptions)\n {\n this._texturePool = {};\n this.textureOptions = textureOptions || {};\n this.enableFullScreen = false;\n }\n\n /**\n * Creates texture with params that were specified in pool constructor.\n * @param pixelWidth - Width of texture in pixels.\n * @param pixelHeight - Height of texture in pixels.\n * @param antialias\n */\n public createTexture(pixelWidth: number, pixelHeight: number, antialias: boolean): Texture\n {\n const textureSource = new TextureSource({\n ...this.textureOptions,\n\n width: pixelWidth,\n height: pixelHeight,\n resolution: 1,\n antialias,\n autoGarbageCollect: true,\n });\n\n return new Texture({\n source: textureSource,\n label: `texturePool_${count++}`,\n });\n }\n\n /**\n * Gets a Power-of-Two render texture or fullScreen texture\n * @param frameWidth - The minimum width of the render texture.\n * @param frameHeight - The minimum height of the render texture.\n * @param resolution - The resolution of the render texture.\n * @param antialias\n * @returns The new render texture.\n */\n public getOptimalTexture(frameWidth: number, frameHeight: number, resolution = 1, antialias: boolean): Texture\n {\n let po2Width = Math.ceil((frameWidth * resolution) - 1e-6);\n let po2Height = Math.ceil((frameHeight * resolution) - 1e-6);\n\n po2Width = nextPow2(po2Width);\n po2Height = nextPow2(po2Height);\n\n const key = (po2Width << 17) + (po2Height << 1) + (antialias ? 1 : 0);\n\n if (!this._texturePool[key])\n {\n this._texturePool[key] = [];\n }\n\n let texture = this._texturePool[key].pop();\n\n if (!texture)\n {\n texture = this.createTexture(po2Width, po2Height, antialias);\n }\n\n texture.source._resolution = resolution;\n texture.source.width = po2Width / resolution;\n texture.source.height = po2Height / resolution;\n texture.source.pixelWidth = po2Width;\n texture.source.pixelHeight = po2Height;\n\n // fit the layout to the requested original size\n texture.frame.x = 0;\n texture.frame.y = 0;\n texture.frame.width = frameWidth;\n texture.frame.height = frameHeight;\n\n texture.updateUvs();\n\n this._poolKeyHash[texture.uid] = key;\n\n return texture;\n }\n\n /**\n * Gets extra texture of the same size as input renderTexture\n * @param texture - The texture to check what size it is.\n * @param antialias - Whether to use antialias.\n * @returns A texture that is a power of two\n */\n public getSameSizeTexture(texture: Texture, antialias = false)\n {\n const source = texture.source;\n\n return this.getOptimalTexture(texture.width, texture.height, source._resolution, antialias);\n }\n\n /**\n * Place a render texture back into the pool.\n * @param renderTexture - The renderTexture to free\n */\n public returnTexture(renderTexture: Texture): void\n {\n const key = this._poolKeyHash[renderTexture.uid];\n\n this._texturePool[key].push(renderTexture);\n }\n\n /**\n * Clears the pool.\n * @param destroyTextures - Destroy all stored textures.\n */\n public clear(destroyTextures?: boolean): void\n {\n destroyTextures = destroyTextures !== false;\n if (destroyTextures)\n {\n for (const i in this._texturePool)\n {\n const textures = this._texturePool[i];\n\n if (textures)\n {\n for (let j = 0; j < textures.length; j++)\n {\n textures[j].destroy(true);\n }\n }\n }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