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

1 line
7.3 KiB
Plaintext

{"version":3,"file":"TextureGCSystem.mjs","sources":["../../../../../src/rendering/renderers/shared/texture/TextureGCSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../../extensions/Extensions';\n\nimport type { Renderer } from '../../types';\nimport type { System } from '../system/System';\n\n/**\n * Options for the {@link TextureGCSystem}.\n * @memberof rendering\n * @property {boolean} [textureGCActive=true] - If set to true, this will enable the garbage collector on the GPU.\n * @property {number} [textureGCAMaxIdle=60 * 60] -\n * The maximum idle frames before a texture is destroyed by garbage collection.\n * @property {number} [textureGCCheckCountMax=600] - Frames between two garbage collections.\n */\nexport interface TextureGCSystemOptions\n{\n /**\n * If set to true, this will enable the garbage collector on the GPU.\n * @default true\n * @memberof rendering.SharedRendererOptions\n */\n textureGCActive: boolean;\n /**\n * @deprecated since 8.3.0\n * @see {@link TextureGCSystem.textureGCMaxIdle}\n * @memberof rendering.SharedRendererOptions\n */\n textureGCAMaxIdle: number;\n /**\n * The maximum idle frames before a texture is destroyed by garbage collection.\n * @default 60 * 60\n * @memberof rendering.SharedRendererOptions\n */\n textureGCMaxIdle: number;\n /**\n * Frames between two garbage collections.\n * @default 600\n * @memberof rendering.SharedRendererOptions\n */\n textureGCCheckCountMax: number;\n}\n/**\n * System plugin to the renderer to manage texture garbage collection on the GPU,\n * ensuring that it does not get clogged up with textures that are no longer being used.\n * @memberof rendering\n */\nexport class TextureGCSystem implements System<TextureGCSystemOptions>\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ExtensionType.WebGPUSystem,\n ],\n name: 'textureGC',\n } as const;\n\n /** default options for the TextureGCSystem */\n public static defaultOptions: TextureGCSystemOptions = {\n /**\n * If set to true, this will enable the garbage collector on the GPU.\n * @default true\n */\n textureGCActive: true,\n /**\n * @deprecated since 8.3.0\n * @see {@link TextureGCSystem.textureGCMaxIdle}\n */\n textureGCAMaxIdle: null,\n /**\n * The maximum idle frames before a texture is destroyed by garbage collection.\n * @default 60 * 60\n */\n textureGCMaxIdle: 60 * 60,\n /**\n * Frames between two garbage collections.\n * @default 600\n */\n textureGCCheckCountMax: 600,\n };\n\n /**\n * Frame count since started.\n * @readonly\n */\n public count: number;\n\n /**\n * Frame count since last garbage collection.\n * @readonly\n */\n public checkCount: number;\n\n /**\n * Maximum idle frames before a texture is destroyed by garbage collection.\n * @see TextureGCSystem.defaultMaxIdle\n */\n public maxIdle: number;\n\n /**\n * Frames between two garbage collections.\n * @see TextureGCSystem.defaultCheckCountMax\n */\n public checkCountMax: number;\n\n /**\n * Current garbage collection mode.\n * @see TextureGCSystem.defaultMode\n */\n public active: boolean;\n private _renderer: Renderer;\n\n /** @param renderer - The renderer this System works for. */\n constructor(renderer: Renderer)\n {\n this._renderer = renderer;\n\n this.count = 0;\n this.checkCount = 0;\n }\n\n public init(options: TextureGCSystemOptions): void\n {\n options = { ...TextureGCSystem.defaultOptions, ...options };\n\n this.checkCountMax = options.textureGCCheckCountMax;\n this.maxIdle = options.textureGCAMaxIdle ?? options.textureGCMaxIdle;\n this.active = options.textureGCActive;\n }\n\n /**\n * Checks to see when the last time a texture was used.\n * If the texture has not been used for a specified amount of time, it will be removed from the GPU.\n */\n protected postrender(): void\n {\n if (!this._renderer.renderingToScreen)\n {\n return;\n }\n\n this.count++;\n\n if (!this.active) return;\n\n this.checkCount++;\n\n if (this.checkCount > this.checkCountMax)\n {\n this.checkCount = 0;\n\n this.run();\n }\n }\n\n /**\n * Checks to see when the last time a texture was used.\n * If the texture has not been used for a specified amount of time, it will be removed from the GPU.\n */\n public run(): void\n {\n const managedTextures = this._renderer.texture.managedTextures;\n\n for (let i = 0; i < managedTextures.length; i++)\n {\n const texture = managedTextures[i];\n\n // Only supports non generated textures at the moment!\n if (\n texture.autoGarbageCollect\n && texture.resource\n && texture._touched > -1\n && this.count - texture._touched > this.maxIdle\n )\n {\n texture._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