@pixi/core
Version:
Core PixiJS
72 lines (67 loc) • 1.91 kB
JavaScript
Object.defineProperty(exports, '__esModule', { value: true });
var extensions = require('@pixi/extensions');
var ObjectRenderer = require('./ObjectRenderer.js');
class BatchSystem {
constructor(renderer) {
this.renderer = renderer;
this.emptyRenderer = new ObjectRenderer.ObjectRenderer(renderer);
this.currentRenderer = this.emptyRenderer;
}
setObjectRenderer(objectRenderer) {
if (this.currentRenderer === objectRenderer) {
return;
}
this.currentRenderer.stop();
this.currentRenderer = objectRenderer;
this.currentRenderer.start();
}
flush() {
this.setObjectRenderer(this.emptyRenderer);
}
reset() {
this.setObjectRenderer(this.emptyRenderer);
}
copyBoundTextures(arr, maxTextures) {
const { boundTextures } = this.renderer.texture;
for (let i = maxTextures - 1; i >= 0; --i) {
arr[i] = boundTextures[i] || null;
if (arr[i]) {
arr[i]._batchLocation = i;
}
}
}
boundArray(texArray, boundTextures, batchId, maxTextures) {
const { elements, ids, count } = texArray;
let j = 0;
for (let i = 0; i < count; i++) {
const tex = elements[i];
const loc = tex._batchLocation;
if (loc >= 0 && loc < maxTextures && boundTextures[loc] === tex) {
ids[i] = loc;
continue;
}
while (j < maxTextures) {
const bound = boundTextures[j];
if (bound && bound._batchEnabled === batchId && bound._batchLocation === j) {
j++;
continue;
}
ids[i] = j;
tex._batchLocation = j;
boundTextures[j] = tex;
break;
}
}
}
destroy() {
this.renderer = null;
}
}
BatchSystem.extension = {
type: extensions.ExtensionType.RendererSystem,
name: "batch"
};
extensions.extensions.add(BatchSystem);
exports.BatchSystem = BatchSystem;
//# sourceMappingURL=BatchSystem.js.map
;