twgl/vertexArrays

vertex array object related functions

You should generally not need to use these functions. They are provided
for those cases where you're doing something out of the ordinary
and you need lower level access.

For backward compatibility they are available at both twgl.attributes and twgl
itself

See module:twgl for core functions

Methods

(static) createVAOAndSetAttributes(gl, setters, attribs, indicesopt) → {WebGLVertexArrayObject|null}

Creates a vertex array object and then sets the attributes on it

Parameters:
Name Type Attributes Description
gl WebGLRenderingContext

The WebGLRenderingContext to use.

setters Object.<string, function()>

Attribute setters as returned from createAttributeSetters

attribs Object.<string, module:twgl.AttribInfo>

AttribInfos mapped by attribute name.

indices WebGLBuffer <optional>

an optional ELEMENT_ARRAY_BUFFER of indices

Returns:
Type:
WebGLVertexArrayObject | null

The created WebGLVertexArrayObject

(static) createVAOFromBufferInfo(gl, programInfo, bufferInfo, indicesopt) → {WebGLVertexArrayObject|null}

Creates a vertex array object and then sets the attributes
on it

Parameters:
Name Type Attributes Description
gl WebGLRenderingContext

The WebGLRenderingContext
to use.

programInfo Object.<string, function()> | module:twgl.ProgramInfo

as returned from createProgramInfo or Attribute setters as returned from createAttributeSetters

bufferInfo module:twgl.BufferInfo

BufferInfo as returned from createBufferInfoFromArrays etc...

indices WebGLBuffer <optional>

an optional ELEMENT_ARRAY_BUFFER of indices

Returns:
Type:
WebGLVertexArrayObject | null

The created WebGLVertexArrayObject

(static) createVertexArrayInfo(gl, programInfo, bufferInfo) → {module:twgl.VertexArrayInfo}

Creates a VertexArrayInfo from a BufferInfo and one or more ProgramInfos

This can be passed to module:twgl.setBuffersAndAttributes and to
module:twgl:drawBufferInfo.

IMPORTANT: Vertex Array Objects are not a direct analog for a BufferInfo. Vertex Array Objects
assign buffers to specific attributes at creation time. That means they can only be used with programs
who's attributes use the same attribute locations for the same purposes.

Bind your attribute locations by passing an array of attribute names to module:twgl.createProgramInfo
or use WebGL 2's GLSL ES 3's layout(location = <num>) to make sure locations match.

also

IMPORTANT: After calling twgl.setBuffersAndAttribute with a BufferInfo that uses a Vertex Array Object
that Vertex Array Object will be bound. That means ANY MANIPULATION OF ELEMENT_ARRAY_BUFFER or ATTRIBUTES
will affect the Vertex Array Object state.

Call gl.bindVertexArray(null) to get back manipulating the global attributes and ELEMENT_ARRAY_BUFFER.

Parameters:
Name Type Description
gl WebGLRenderingContext

A WebGLRenderingContext

programInfo module:twgl.ProgramInfo | Array.<module:twgl.ProgramInfo>

a programInfo or array of programInfos

bufferInfo module:twgl.BufferInfo

BufferInfo as returned from createBufferInfoFromArrays etc...

You need to make sure every attribute that will be used is bound. So for example assume shader 1
uses attributes A, B, C and shader 2 uses attributes A, B, D. If you only pass in the programInfo
for shader 1 then only attributes A, B, and C will have their attributes set because TWGL doesn't
now attribute D's location.

So, you can pass in both shader 1 and shader 2's programInfo

Returns:
Type:
module:twgl.VertexArrayInfo

The created VertexArrayInfo