UNPKG

@awayjs/stage

Version:
76 lines (75 loc) 2.99 kB
import { Settings } from '../Settings'; import { BufferPool } from './BufferPool'; var IndexBufferWebGL = /** @class */ (function () { function IndexBufferWebGL(_context, numIndices) { this._context = _context; this.canUnload = true; this._lastMemoryUsage = 0; this._gl = _context._gl; this._buffer = this._gl.createBuffer(); this._numIndices = numIndices; _context.stats.counter.index++; } Object.defineProperty(IndexBufferWebGL, "pool", { get: function () { if (!Settings.ENABLE_BUFFER_POOLING) return null; return this._pool || (this._pool = new BufferPool(IndexBufferWebGL)); }, enumerable: false, configurable: true }); IndexBufferWebGL.create = function (context, numIndices) { if (!Settings.ENABLE_BUFFER_POOLING) { return new IndexBufferWebGL(context, numIndices); } return this.pool.create(context, numIndices); }; IndexBufferWebGL.prototype.uploadFromArray = function (array, startOffset, _count) { if (startOffset === void 0) { startOffset = 0; } this.uploadFromByteArray(array.buffer, startOffset, _count); }; IndexBufferWebGL.prototype.uploadFromByteArray = function (data, startOffset, _count) { if (startOffset === void 0) { startOffset = 0; } this._gl.bindBuffer(this._gl.ELEMENT_ARRAY_BUFFER, this._buffer); this._context.stats.memory.index -= this._lastMemoryUsage; this._lastMemoryUsage = data.byteLength - startOffset * 2; this._context.stats.memory.index += this._lastMemoryUsage; if (startOffset) this._gl.bufferSubData(this._gl.ELEMENT_ARRAY_BUFFER, startOffset * 2, data); else this._gl.bufferData(this._gl.ELEMENT_ARRAY_BUFFER, data, this._gl.STATIC_DRAW); }; IndexBufferWebGL.prototype.dispose = function () { if (Settings.ENABLE_BUFFER_POOLING && IndexBufferWebGL.pool.store(this)) { return; } this.unload(); }; IndexBufferWebGL.prototype.apply = function (_gl, numIndices) { this._numIndices = numIndices; }; IndexBufferWebGL.prototype.unload = function () { Settings.ENABLE_BUFFER_POOLING && IndexBufferWebGL.pool.remove(this); this._gl.deleteBuffer(this._buffer); this._buffer = null; this._context.stats.counter.index--; this._context.stats.memory.index -= this._lastMemoryUsage; }; Object.defineProperty(IndexBufferWebGL.prototype, "numIndices", { get: function () { return this._numIndices; }, enumerable: false, configurable: true }); Object.defineProperty(IndexBufferWebGL.prototype, "glBuffer", { get: function () { return this._buffer; }, enumerable: false, configurable: true }); return IndexBufferWebGL; }()); export { IndexBufferWebGL };