---
url: /api/core/attribute/functions/setAttribute.md
---
# 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`](../../../types/types/interfaces/Attribute.md)

The attribute data and configuration.

## Returns

| Name          | Type                    | Description                                                              |
| ------------- | ----------------------- | ------------------------------------------------------------------------ |
| `location`    | `number`                | The location of the attribute in the shader program.                     |
| `vertexCount` | `number`                | The computed vertex count based on the attribute data and configuration. |
| `buffer?`     | `WebGLBuffer` | `null` | The WebGL buffer associated with the attribute, if any.                  |
