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