Skip to content

setAttribute()

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

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.

Released under the MIT License.