gl-vao
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -7,13 +7,13 @@ "use strict" | ||
this.gl = gl | ||
this.elements = null | ||
this.attributes = null | ||
this._elements = null | ||
this._attributes = null | ||
} | ||
VAOEmulated.prototype.bind = function() { | ||
bindAttribs(this.gl, this.elements, this.attributes) | ||
bindAttribs(this.gl, this._elements, this._attributes) | ||
} | ||
VAOEmulated.prototype.update = function(attributes, elements) { | ||
this.elements = elements | ||
this.attributes = attributes | ||
this._elements = elements | ||
this._attributes = attributes | ||
} | ||
@@ -24,2 +24,12 @@ | ||
VAOEmulated.prototype.draw = function(mode, count, offset) { | ||
offset = offset || 0 | ||
var gl = this.gl | ||
if(this._elements) { | ||
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) | ||
} else { | ||
gl.drawArrays(mode, offset, count) | ||
} | ||
} | ||
function createVAOEmulated(gl) { | ||
@@ -26,0 +36,0 @@ return new VAOEmulated(gl) |
@@ -33,9 +33,10 @@ "use strict" | ||
this.gl = gl | ||
this.ext = ext | ||
this._ext = ext | ||
this.handle = handle | ||
this._attribs = [] | ||
this._useElements = false | ||
} | ||
VAONative.prototype.bind = function() { | ||
this.ext.bindVertexArrayOES(this.handle) | ||
this._ext.bindVertexArrayOES(this.handle) | ||
for(var i=0; i<this._attribs.length; ++i) { | ||
@@ -47,7 +48,7 @@ this._attribs[i].bind(this.gl) | ||
VAONative.prototype.unbind = function() { | ||
this.ext.bindVertexArrayOES(null) | ||
this._ext.bindVertexArrayOES(null) | ||
} | ||
VAONative.prototype.dispose = function() { | ||
this.ext.deleteVertexArrayOES(this.handle) | ||
this._ext.deleteVertexArrayOES(this.handle) | ||
} | ||
@@ -69,4 +70,15 @@ | ||
} | ||
this._useElements = !!elements | ||
} | ||
VAONative.prototype.draw = function(mode, count, offset) { | ||
offset = offset || 0 | ||
var gl = this.gl | ||
if(this._useElements) { | ||
gl.drawElements(mode, count, gl.UNSIGNED_SHORT, offset) | ||
} else { | ||
gl.drawArrays(mode, offset, count) | ||
} | ||
} | ||
function createVAONative(gl, ext) { | ||
@@ -73,0 +85,0 @@ return new VAONative(gl, ext, ext.createVertexArrayOES()) |
{ | ||
"name": "gl-vao", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Vertex array object wrapper/shim for WebGL", | ||
@@ -5,0 +5,0 @@ "main": "vao.js", |
@@ -46,3 +46,3 @@ gl-vao | ||
//Draw stuff | ||
gl.drawArrays(gl.TRIANGLES, 0, 3) | ||
vao.draw(gl.TRIANGLES, 3) | ||
@@ -96,2 +96,9 @@ //Unbind vertex array when fini | ||
### `vao.draw(mode, count[, offset])` | ||
Draws the vertex array object. | ||
* `mode` is the mode to use when drawing the buffer, for example `gl.TRIANGLES`, `gl.LINES`, etc. | ||
* `count` is the number of vertices to draw. | ||
* `offset` is the offset to start drawing from. Default `0` | ||
### `vao.update(attributes[, elements])` | ||
@@ -103,3 +110,4 @@ Updates the contents of the vertex array object using the same syntax and conventions as the constructor. | ||
## Credits | ||
(c) 2013 Mikola Lysenko. MIT License |
10687
167
111