gl-aliased-vao
Version:
like vao, but only for simple vertex arrays
41 lines (34 loc) • 1.04 kB
JavaScript
var bindAttribs = require("./do-bind.js")
function VAOEmulated(gl) {
this.gl = gl
this._elements = null
this._attributes = null
this._elementsType = gl.UNSIGNED_SHORT
}
VAOEmulated.prototype.bind = function(shader) {
if (!shader)
throw new Error('must associate shader with vertex array')
bindAttribs(this.gl, this._elements, this._attributes, shader)
}
VAOEmulated.prototype.update = function(attributes, elements, elementsType) {
this._elements = elements
this._attributes = attributes
this._elementsType = elementsType || this.gl.UNSIGNED_SHORT
}
VAOEmulated.prototype.dispose = function() { }
VAOEmulated.prototype.unbind = function() {
bindAttribs(this.gl)
}
VAOEmulated.prototype.draw = function(mode, count, offset) {
offset = offset || 0
var gl = this.gl
if(this._elements) {
gl.drawElements(mode, count, this._elementsType, offset)
} else {
gl.drawArrays(mode, offset, count)
}
}
function createVAOEmulated(gl) {
return new VAOEmulated(gl)
}
module.exports = createVAOEmulated