1 | ;
|
2 | var constants = require("@pixi/constants"), runner = require("@pixi/runner");
|
3 | let UID = 0;
|
4 | class Buffer {
|
5 | /**
|
6 | * @param {PIXI.IArrayBuffer} data - the data to store in the buffer.
|
7 | * @param _static - `true` for static buffer
|
8 | * @param index - `true` for index buffer
|
9 | */
|
10 | constructor(data, _static = !0, index = !1) {
|
11 | this.data = data || new Float32Array(1), this._glBuffers = {}, this._updateID = 0, this.index = index, this.static = _static, this.id = UID++, this.disposeRunner = new runner.Runner("disposeBuffer");
|
12 | }
|
13 | // TODO could explore flagging only a partial upload?
|
14 | /**
|
15 | * Flags this buffer as requiring an upload to the GPU.
|
16 | * @param {PIXI.IArrayBuffer|number[]} [data] - the data to update in the buffer.
|
17 | */
|
18 | update(data) {
|
19 | data instanceof Array && (data = new Float32Array(data)), this.data = data || this.data, this._updateID++;
|
20 | }
|
21 | /** Disposes WebGL resources that are connected to this geometry. */
|
22 | dispose() {
|
23 | this.disposeRunner.emit(this, !1);
|
24 | }
|
25 | /** Destroys the buffer. */
|
26 | destroy() {
|
27 | this.dispose(), this.data = null;
|
28 | }
|
29 | /**
|
30 | * Flags whether this is an index buffer.
|
31 | *
|
32 | * Index buffers are of type `ELEMENT_ARRAY_BUFFER`. Note that setting this property to false will make
|
33 | * the buffer of type `ARRAY_BUFFER`.
|
34 | *
|
35 | * For backwards compatibility.
|
36 | */
|
37 | set index(value) {
|
38 | this.type = value ? constants.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER : constants.BUFFER_TYPE.ARRAY_BUFFER;
|
39 | }
|
40 | get index() {
|
41 | return this.type === constants.BUFFER_TYPE.ELEMENT_ARRAY_BUFFER;
|
42 | }
|
43 | /**
|
44 | * Helper function that creates a buffer based on an array or TypedArray
|
45 | * @param {ArrayBufferView | number[]} data - the TypedArray that the buffer will store. If this is a regular Array it will be converted to a Float32Array.
|
46 | * @returns - A new Buffer based on the data provided.
|
47 | */
|
48 | static from(data) {
|
49 | return data instanceof Array && (data = new Float32Array(data)), new Buffer(data);
|
50 | }
|
51 | }
|
52 | exports.Buffer = Buffer;
|
53 | //# sourceMappingURL=Buffer.js.map
|