Repository: pixijs/pixijs
File: src/rendering/renderers/gl/texture/GlTextureSystem.ts (TypeScript)

Code before:
import { glUploadCompressedTextureResource } from './uploaders/glUploadCompressedTextureResource';
import { glUploadImageResource } from './uploaders/glUploadImageResource';
import { glUploadVideoResource } from './uploaders/glUploadVideoResource';
import { applyStyleParams } from './utils/applyStyleParams';
import { mapFormatToGlFormat } from './utils/mapFormatToGlFormat';
import { mapFormatToGlInternalFormat } from './utils/mapFormatToGlInternalFormat';
import { mapFormatToGlType } from './utils/mapFormatToGlType';
import { unpremultiplyAlpha } from './utils/unpremultiplyAlpha';

import type { ICanvas } from '../../../../environment/canvas/ICanvas';
import type { System } from '../../shared/system/System';
import type { CanvasGenerator, GetPixelsOutput } from '../../shared/texture/GenerateCanvas';
import type { TextureSource } from '../../shared/texture/sources/TextureSource';
import type { BindableTexture } from '../../shared/texture/Texture';
import type { TextureStyle } from '../../shared/texture/TextureStyle';
import type { GlRenderingContext } from '../context/GlRenderingContext';
import type { WebGLRenderer } from '../WebGLRenderer';
import type { GLTextureUploader } from './uploaders/GLTextureUploader';

const BYTES_PER_PIXEL = 4;

/**
 * Stores GPU-specific data for a Texture instance in WebGL context.
 * @internal
 */
export class GlTextureGpuData implements GPUData
{
    public glTexture: GlTexture;

    constructor(glTexture: GlTexture)
    {
        this.glTexture = glTexture;
    }

    public destroy(): void
    {
        this.glTexture = null;
    }
}

/**
 * The system for managing textures in WebGL.
 * @category rendering
 * @advanced
 */
export class GlTextureSystem implements System, CanvasGenerator
{
    /** @ignore */
    public static extension = {
        type: [
            ExtensionType.WebGLSystem,

Review comment (suggestion):
rather than create GlTextureGpuData 
could  we just make destroy optional in the ManagedHash? 
then we can just go:

 source._gpuData[this._renderer.uid] = glTexture

Code after:
import { glUploadImageResource } from './uploaders/glUploadImageResource';
import { glUploadVideoResource } from './uploaders/glUploadVideoResource';
import { applyStyleParams } from './utils/applyStyleParams';
import { mapFormatToGlFormat } from './utils/mapFormatToGlFormat';
import { mapFormatToGlInternalFormat } from './utils/mapFormatToGlInternalFormat';
import { mapFormatToGlType } from './utils/mapFormatToGlType';
import { unpremultiplyAlpha } from './utils/unpremultiplyAlpha';

import type { ICanvas } from '../../../../environment/canvas/ICanvas';
import type { System } from '../../shared/system/System';
import type { CanvasGenerator, GetPixelsOutput } from '../../shared/texture/GenerateCanvas';
import type { TextureSource } from '../../shared/texture/sources/TextureSource';
import type { BindableTexture } from '../../shared/texture/Texture';
import type { TextureStyle } from '../../shared/texture/TextureStyle';
import type { GlRenderingContext } from '../context/GlRenderingContext';
import type { WebGLRenderer } from '../WebGLRenderer';
import type { GLTextureUploader } from './uploaders/GLTextureUploader';

const BYTES_PER_PIXEL = 4;

/**
 * The system for managing textures in WebGL.
 * @category rendering
 * @advanced
 */
export class GlTextureSystem implements System, CanvasGenerator
{
    /** @ignore */
    public static extension = {
        type: [
            ExtensionType.WebGLSystem,
        ],
        name: 'texture',
    } as const;

    private readonly _renderer: WebGLRenderer;
    private readonly _managedTextures: ManagedHash<TextureSource>;
    /**
     * @deprecated since 8.15.0
     */
    public get managedTextures(): Readonly<TextureSource[]> { return Object.values(this._managedTextures.items); }

    private _glSamplers: Record<string, WebGLSampler> = Object.create(null);

    private _boundTextures: TextureSource[] = [];
    private _activeTextureLocation = -1;

    private _boundSamplers: Record<number, WebGLSampler> = Object.create(null);

    private readonly _uploads: Record<string, GLTextureUploader> = {
        image: glUploadImageResource,