UNPKG

vislite

Version:

灵活、快速、简单的数据可视化交互式跨端前端库

42 lines (40 loc) 1.67 kB
/*! * Buffer of VISLite JavaScript Library v1.3.0 * git+https://github.com/oi-contrib/VISLite.git */ var newBuffer = function (painter) { return painter.createBuffer(); }; var writeBuffer = function (painter, data, isElement, usage) { var TYPE = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER; painter.bufferData(TYPE, data, usage); }; var useBuffer = function (painter, location, size, type, stride, offset, normalized) { painter.vertexAttribPointer(location, size, type, normalized, stride, offset); painter.enableVertexAttribArray(location); }; var BufferObject = (function () { function BufferObject(painter, isElement) { if (isElement === void 0) { isElement = false; } this.__painter = painter; this.__isElement = isElement; this.__buffer = newBuffer(painter); this.__type = isElement ? painter.ELEMENT_ARRAY_BUFFER : painter.ARRAY_BUFFER; } BufferObject.prototype.use = function () { this.__painter.bindBuffer(this.__type, this.__buffer); return this; }; BufferObject.prototype.write = function (data) { writeBuffer(this.__painter, data, this.__isElement, this.__painter.STATIC_DRAW); this.__fsize = data.BYTES_PER_ELEMENT; return this; }; BufferObject.prototype.divide = function (location, size, stride, offset) { if (offset === void 0) { offset = 0; } useBuffer(this.__painter, location, size, this.__painter.FLOAT, stride * this.__fsize, offset * this.__fsize, false); return this; }; return BufferObject; }()); export { BufferObject as default };