- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
import type {
BaseTexture,
Renderer,
State,
} from '@pixi/core';
import type { DisplayObject } from '@pixi/display';
/**
* Resources that need to be uploaded to WebGL to render one batch.
*
* To customize batches, you must create your own batch factory by extending the
* {@link StdBatchFactory} class.
*/
export class StdBatch
{
geometryOffset: number;
uidMap: any;
state: State;
batchBuffer: Array<DisplayObject>;
textureBuffer: Array<BaseTexture>;
constructor(geometryOffset?: number)
{
/**
* Index of the first vertex of this batch's geometry in the uploaded geometry.
*
* @member {number}
*/
this.geometryOffset = geometryOffset;
/**
* Textures that are used by the display-object's in this batch.
*
* @member {Array<PIXI.Texture>}
*/
this.textureBuffer = null;
/**
* Map of base-texture UIDs to texture indices into `uSamplers`.
*
* @member {Map<number, number>}
*/
this.uidMap = null;
/**
* State required to render this batch.
*
* @member {PIXI.State}
*/
this.state = null;
}
/**
* Uploads the resources required before rendering this batch. If you override
* this, you must call `super.upload`.
*
* @param {PIXI.Renderer} renderer
*/
upload(renderer: Renderer): void
{
this.textureBuffer.forEach((tex, i) =>
{
renderer.texture.bind(tex, i);
});
renderer.state.set(this.state);
}
/**
* Reset this batch to become "fresh"!
*/
reset(): void
{
this.textureBuffer = this.uidMap = this.state = null;
if (this.batchBuffer)
{
this.batchBuffer.length = 0;
}
}
}