UNPKG

@pixi/core

Version:
45 lines (42 loc) 1.04 kB
import { BUFFER_TYPE } from '@pixi/constants'; import { Runner } from '@pixi/runner'; let UID = 0; class Buffer { constructor(data, _static = true, index = false) { this.data = data || new Float32Array(1); this._glBuffers = {}; this._updateID = 0; this.index = index; this.static = _static; this.id = UID++; this.disposeRunner = new Runner("disposeBuffer"); } update(data) { if (data instanceof Array) { data = new Float32Array(data); } this.data = data || this.data; this._updateID++; } dispose() { this.disposeRunner.emit(this, false); } destroy() { this.dispose(); this.data = null; } set index(value) { this.type = value ? BUFFER_TYPE.ELEMENT_ARRAY_BUFFER : BUFFER_TYPE.ARRAY_BUFFER; } get index() { return this.type === BUFFER_TYPE.ELEMENT_ARRAY_BUFFER; } static from(data) { if (data instanceof Array) { data = new Float32Array(data); } return new Buffer(data); } } export { Buffer }; //# sourceMappingURL=Buffer.mjs.map