UNPKG

1.04 kBJavaScriptView Raw
1import { BUFFER_TYPE } from '@pixi/constants';
2import { Runner } from '@pixi/runner';
3
4let UID = 0;
5class Buffer {
6 constructor(data, _static = true, index = false) {
7 this.data = data || new Float32Array(1);
8 this._glBuffers = {};
9 this._updateID = 0;
10 this.index = index;
11 this.static = _static;
12 this.id = UID++;
13 this.disposeRunner = new Runner("disposeBuffer");
14 }
15 update(data) {
16 if (data instanceof Array) {
17 data = new Float32Array(data);
18 }
19 this.data = data || this.data;
20 this._updateID++;
21 }
22 dispose() {
23 this.disposeRunner.emit(this, false);
24 }
25 destroy() {
26 this.dispose();
27 this.data = null;
28 }
29 set index(value) {
30 this.type = value ? BUFFER_TYPE.ELEMENT_ARRAY_BUFFER : BUFFER_TYPE.ARRAY_BUFFER;
31 }
32 get index() {
33 return this.type === BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
34 }
35 static from(data) {
36 if (data instanceof Array) {
37 data = new Float32Array(data);
38 }
39 return new Buffer(data);
40 }
41}
42
43export { Buffer };
44//# sourceMappingURL=Buffer.mjs.map