Skip to content

Commit

Permalink
feat: reserve texture units for batching (pixijs#10703)
Browse files Browse the repository at this point in the history
* feat: reserve texture units for batching

* maxTextures instead of reservedTextures

---------

Co-authored-by: Zyie <[email protected]>
  • Loading branch information
dev7355608 and Zyie committed Jul 29, 2024
1 parent aea26be commit 90f2372
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/rendering/batcher/shared/Batcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export interface BatcherOptions
vertexSize?: number;
/** The size of the index buffer. */
indexSize?: number;
/** The maximum number of textures per batch. */
maxTextures?: number;
}

/**
Expand All @@ -122,6 +124,7 @@ export class Batcher
public static defaultOptions: BatcherOptions = {
vertexSize: 4,
indexSize: 6,
maxTextures: getMaxTexturesPerBatch(),
};

/** unique id for this batcher */
Expand All @@ -146,19 +149,21 @@ export class Batcher

private _batchIndexStart: number;
private _batchIndexSize: number;
private readonly _maxTextures: number;

/** The maximum number of textures per batch. */
public readonly maxTextures: number;

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

const { vertexSize, indexSize } = options;
const { vertexSize, indexSize, maxTextures } = options;

this.attributeBuffer = new ViewableBuffer(vertexSize * this._vertexSize * 4);

this.indexBuffer = new Uint16Array(indexSize);

this._maxTextures = getMaxTexturesPerBatch();
this.maxTextures = maxTextures;
}

public begin()
Expand Down Expand Up @@ -256,7 +261,7 @@ export class Batcher

let action: BatchAction = 'startBatch';

const maxTextures = this._maxTextures;
const maxTextures = this.maxTextures;

for (let i = this.elementStart; i < this.elementSize; ++i)
{
Expand Down

0 comments on commit 90f2372

Please sign in to comment.