Skip to content

setAttribute() ​

ts
function setAttribute(
  gl: WebGL2RenderingContext,
  program: WebGLProgram,
  name: string,
  attribute: Attribute,
): {
  location: number;
  vertexCount: number;
  buffer?: WebGLBuffer | null;
};

Sets up a vertex attribute for a given shader program.

This function handles buffer creation, binding, and attribute pointer configuration. It also supports special handling for the "index" attribute (ELEMENT_ARRAY_BUFFER).

Parameters ​

gl ​

WebGL2RenderingContext

The WebGL2 context.

program ​

WebGLProgram

The WebGL program containing the attribute.

name ​

string

The name of the attribute in the shader.

attribute ​

Attribute

The attribute data and configuration.

Returns ​

NameTypeDescription
locationnumberThe location of the attribute in the shader program.
vertexCountnumberThe computed vertex count based on the attribute data and configuration.
buffer?WebGLBuffer | nullThe WebGL buffer associated with the attribute, if any.

Released under the MIT License.