getVertexAttrib method

Returns data for a particular characteristic of a vertex attribute at an index in a vertex attribute array.




var retVal = WebGLRenderingContext.getVertexAttrib(index, pname);


index [in]

Type: Number

The index of the vertex attribute to query.

pname [in]

Type: Number

The symbolic name for the attribute parameter to look up. See remarks for acceptable values.

Return value

Type: any

The data specified by pname for the vertex attribute at index. See the table below. Returns null if an error condition occurs, such as an invalid pname.


The following table shows the return value for a given pname.

gl.VERTEX_ATTRIB_ARRAY_BUFFER_BINDINGWebGLBufferThe name of the currently bound buffer object. Returns 0 if no buffer is bound.
gl.VERTEX_ATTRIB_ARRAY_ENABLEDBooleanReturns true if the vertex attribute at index is enabled, otherwise false. Initial value is false.
gl.VERTEX_ATTRIB_ARRAY_SIZENumberReturns the size (1,2,3,or 4) for an element of the vertex array. Initial value is 4.
gl.VERTEX_ATTRIB_ARRAY_STRIDENumberReturns the number of bytes between successive elements in the array. The value 0 means the elements are sequential in memory. Initial value is 0.
gl.VERTEX_ATTRIB_ARRAY_TYPEGLenumReturns a constant representing the array type. Possible values are:
  • gl.BYTE
  • gl.SHORT
  • gl.FIXED
  • gl.FLOAT
The initial value is gl.FLOAT.
gl.VERTEX_ATTRIB_ARRAY_NORMALIZEDBooleanReturns true if fixed-point data types for the vertex attribute array at index are normalized when converted to floating point. Otherwise false is returned. Initial value is false.
gl.CURRENT_VERTEX_ATTRIBFloat32Array (with 4 elements)Returns four values that currently represent the value of the vertex attribute at index. Initial value is 0,0,0,1.


WebGL ErrorDescription
gl.INVALID_ENUMIf pname isn't an accepted value.
gl.INVALID_VALUEIf index is greater than or equal to gl.MAX_VERTEX_ATTRIBS.


See also