JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32645
  • Score
    100M100P100Q152516F
  • License MIT

Vertex array object wrapper/shim for WebGL

Package Exports

  • gl-vao

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gl-vao) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gl-vao

Vertex array object wrapper and shim for WebGL

Example

Try out the demo in your browser

var shell = require("gl-now")()
var createBuffer = require("gl-buffer")
var createVAO = require("gl-vao")
var createSimpleShader = require("simple-2d-shader")

var vao, shader

shell.on("gl-init", function() {
  var gl = shell.gl
  
  shader = createSimpleShader(gl)
  
  //Create vertex array object
  vao = createVAO(gl, null, [
    { "buffer": createBuffer(gl, [-1, 0, 0, -1, 1, 1]),
      "type": gl.FLOAT,
      "size": 2,
      "offset": 0,
      "stride": 0,
      "normalized": false
    },
    [0.8, 1, 0.5]
  ])
})

shell.on("gl-render", function(t) {
  var gl = shell.gl

  shader.bind()
  
  //Bind vertex array object and set locations
  vao.bind()
  shader.attributes.position.location = 0
  shader.attributes.color.location = 1

  //Draw stuff
  gl.drawArrays(gl.TRIANGLES, 0, 3)
  
  //Unbind vertex array when fini
  vao.unbind()
})

Assuming everything worked, here is what it should look like:

Install

Use npm:

npm install gl-vao

To compile demos in for your browser try browserify or beefy.

API

var createVAO = require("gl-vao")

var vao = createVAO(gl[, elements, attributes])

Creates a vertex array object

  • gl is the gl context in which the vertex array object is created

  • elements is a buffer created using gl-buffer encoding the state of the vertex elements

  • attributes is an array of objects that give the attributes bound to particular locations starting at 0. Each of these attributes is either an array-like object of length 4 or less representing a constant attribute value, or else it is an object with the following properties that correspond to the parameters passed to gl.vertexAttribPointer

    • buffer a gl-buffer object encoding a webgl buffer
    • size the size of the attribute (default 4)
    • type the type of the attribute (default gl.FLOAT)
    • normalized a flag that checks whether the attribute should be normalized or not
    • stride the stride of the attribute (default 0)
    • offset offset to the start of the attribute in the buffer (default 0)

vao.bind()

Binds the vertex array object to the active vertex state.

vao.unbind()

Unbinds the vertex array object.

Note You should call this method before switching back to using vertex arrays and buffers as usual. Failing to do so can cause the state of the vertex array object to become corrupted. However, it is acceptable to skip the unbind step if another vertex array object is immediately bound.

vao.update(elements, attributes)

Updates the contents of the vertex array object using the same syntax and conventions as the constructor.

vao.dispose()

Destroys the vertex array object and releases all of its resources.

Credits

(c) 2013 Mikola Lysenko. MIT License