Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ var geom = createGeometry(gl)

You can specify `opt.size` for the cell size, defaults to 3.

You can specify `opt.elementsBytes` for the element byte size, defaults to 2.
Can be 1 or 2. If the context is a WebGL 2 context or the extension
`OES_element_index_uint` is enabled in a WebGL 1 context, opt.elementsBytes
may additionally be 4.

### geom.bind([shader]) ###

Binds the underlying [VAO](https://github.com/stackgl/gl-vao) – this must
Expand Down
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ GLGeometry.prototype.dispose = function () {

GLGeometry.prototype.faces = function faces (attr, opts) {
var size = opts && opts.size || 3
var elementsBytes = opts && opts.elementsBytes || 2
attr = attr.cells ? attr.cells : attr

this._dirty = true
Expand All @@ -54,13 +55,27 @@ GLGeometry.prototype.faces = function faces (attr, opts) {
this._index.dispose()
}

if ( elementsBytes == 1 )
{
this._elementsType = this.gl.UNSIGNED_BYTE
}
else if ( elementsBytes == 2 )
{
this._elementsType = this.gl.UNSIGNED_SHORT
}
else if ( elementsBytes == 4 )
{
this._elementsType = this.gl.UNSIGNED_INT
}

this._index = normalize.create(this.gl
, attr
, size
, this.gl.ELEMENT_ARRAY_BUFFER
, 'uint16'
, glType(this._elementsType)
)

this._elementsBytes = elementsBytes;
this._facesLength = this._index.length * size
this._index = this._index.buffer

Expand Down Expand Up @@ -155,7 +170,7 @@ GLGeometry.prototype.update = function update () {
this._dirty = false
if (this._vao) this._vao.dispose()

this._vao = createVAO(this.gl, this._attributes, this._index)
this._vao = createVAO(this.gl, this._attributes, this._index, this._elementsType)
this._elementsType = this._vao._elementsType
this._elementsBytes = dtype(
glType(this._elementsType) || 'array'
Expand Down