UNPKG

1.91 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5var extensions = require('@pixi/extensions');
6var ObjectRenderer = require('./ObjectRenderer.js');
7
8class BatchSystem {
9 constructor(renderer) {
10 this.renderer = renderer;
11 this.emptyRenderer = new ObjectRenderer.ObjectRenderer(renderer);
12 this.currentRenderer = this.emptyRenderer;
13 }
14 setObjectRenderer(objectRenderer) {
15 if (this.currentRenderer === objectRenderer) {
16 return;
17 }
18 this.currentRenderer.stop();
19 this.currentRenderer = objectRenderer;
20 this.currentRenderer.start();
21 }
22 flush() {
23 this.setObjectRenderer(this.emptyRenderer);
24 }
25 reset() {
26 this.setObjectRenderer(this.emptyRenderer);
27 }
28 copyBoundTextures(arr, maxTextures) {
29 const { boundTextures } = this.renderer.texture;
30 for (let i = maxTextures - 1; i >= 0; --i) {
31 arr[i] = boundTextures[i] || null;
32 if (arr[i]) {
33 arr[i]._batchLocation = i;
34 }
35 }
36 }
37 boundArray(texArray, boundTextures, batchId, maxTextures) {
38 const { elements, ids, count } = texArray;
39 let j = 0;
40 for (let i = 0; i < count; i++) {
41 const tex = elements[i];
42 const loc = tex._batchLocation;
43 if (loc >= 0 && loc < maxTextures && boundTextures[loc] === tex) {
44 ids[i] = loc;
45 continue;
46 }
47 while (j < maxTextures) {
48 const bound = boundTextures[j];
49 if (bound && bound._batchEnabled === batchId && bound._batchLocation === j) {
50 j++;
51 continue;
52 }
53 ids[i] = j;
54 tex._batchLocation = j;
55 boundTextures[j] = tex;
56 break;
57 }
58 }
59 }
60 destroy() {
61 this.renderer = null;
62 }
63}
64BatchSystem.extension = {
65 type: extensions.ExtensionType.RendererSystem,
66 name: "batch"
67};
68extensions.extensions.add(BatchSystem);
69
70exports.BatchSystem = BatchSystem;
71//# sourceMappingURL=BatchSystem.js.map