Repository: pixijs/pixijs
File: src/rendering/batcher/shared/Batcher.ts (TypeScript)

Code before:
     * Must be implemented by subclasses.
     * @param element - The BatchableQuadElement to pack.
     * @param float32View - The Float32Array view to pack into.
     * @param uint32View - The Uint32Array view to pack into.
     * @param index - The starting index in the views.
     * @param textureId - The texture ID to use.
     */
    public abstract packQuadAttributes(
        element: BatchableQuadElement,
        float32View: Float32Array,
        uint32View: Uint32Array,
        index: number,
        textureId: number
    ): void;

    constructor(options: BatcherOptions = {})
    {
        Batcher.defaultOptions.maxTextures = Batcher.defaultOptions.maxTextures ?? getMaxTexturesPerBatch();
        options = { ...Batcher.defaultOptions, ...options };

        const { maxTextures, attributesInitialSize, indicesInitialSize } = options;

        this.attributeBuffer = new ViewableBuffer(attributesInitialSize * 4);

        this.indexBuffer = new Uint16Array(indicesInitialSize);

        this.maxTextures = maxTextures;
    }

    public begin()
    {
        this.elementSize = 0;
        this.elementStart = 0;
        this.indexSize = 0;
        this.attributeSize = 0;

        for (let i = 0; i < this.batchIndex; i++)
        {
            returnBatchToPool(this.batches[i]);
        }

        this.batchIndex = 0;
        this._batchIndexStart = 0;
        this._batchIndexSize = 0;

        this.dirty = true;
    }

    public add(batchableObject: BatchableElement)
    {
        this._elements[this.elementSize++] = batchableObject;

Review comment (performance):
Since maxTextures is now a required option for the Batcher, consider updating all callers rather than relying on the deprecated fallback to ensure consistency across the codebase.
```suggestion
            throw new Error('maxTextures is a required option for Batcher. Please provide it in the options.');
```

Code after:

    /**
     * Packs the attributes of a BatchableQuadElement into the provided views.
     * Must be implemented by subclasses.
     * @param element - The BatchableQuadElement to pack.
     * @param float32View - The Float32Array view to pack into.
     * @param uint32View - The Uint32Array view to pack into.
     * @param index - The starting index in the views.
     * @param textureId - The texture ID to use.
     */
    public abstract packQuadAttributes(
        element: BatchableQuadElement,
        float32View: Float32Array,
        uint32View: Uint32Array,
        index: number,
        textureId: number
    ): void;

    constructor(options: BatcherOptions)
    {
        options = { ...Batcher.defaultOptions, ...options };

        if (!options.maxTextures)
        {
            deprecation('v8.8.0', 'maxTextures is a required option for Batcher now, please pass it in the options');
            options.maxTextures = getMaxTexturesPerBatch();
        }

        const { maxTextures, attributesInitialSize, indicesInitialSize } = options;

        this.attributeBuffer = new ViewableBuffer(attributesInitialSize * 4);

        this.indexBuffer = new Uint16Array(indicesInitialSize);

        this.maxTextures = maxTextures;
    }

    public begin()
    {
        this.elementSize = 0;
        this.elementStart = 0;
        this.indexSize = 0;
        this.attributeSize = 0;

        for (let i = 0; i < this.batchIndex; i++)
        {
            returnBatchToPool(this.batches[i]);
        }

        this.batchIndex = 0;
        this._batchIndexStart = 0;