1 | import { BUFFER_TYPE } from '@pixi/constants';
|
2 | import { Runner } from '@pixi/runner';
|
3 |
|
4 | let UID = 0;
|
5 | class 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 |
|
43 | export { Buffer };
|
44 |
|