UNPKG

@pixi/core

Version:
68 lines (65 loc) 1.8 kB
import { ExtensionType, extensions } from '@pixi/extensions'; import { ObjectRenderer } from './ObjectRenderer.mjs'; class BatchSystem { constructor(renderer) { this.renderer = renderer; this.emptyRenderer = new 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: ExtensionType.RendererSystem, name: "batch" }; extensions.add(BatchSystem); export { BatchSystem }; //# sourceMappingURL=BatchSystem.mjs.map