# VertexFormat

Class · category: Graphics

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/platform/graphics/vertex-format.js#L69

A vertex format is a descriptor that defines the layout of vertex data inside a
[VertexBuffer](https://api.playcanvas.com/engine/classes/VertexBuffer.md).

## Constructors

### constructor

```ts
new VertexFormat(graphicsDevice: GraphicsDevice, description: AttributeDescription[], vertexCount?: number)
```

Create a new VertexFormat instance.

**Parameters**

- `graphicsDevice` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device used to manage this vertex
  format.
- `description` ([`AttributeDescription`](https://api.playcanvas.com/engine/interfaces/AttributeDescription.md)`[]`): An array of vertex attribute descriptions.
- `vertexCount` (`number`, optional): When specified, vertex format will be set up for
  non-interleaved format with a specified number of vertices. (example: PPPPNNNNCCCC), where
  arrays of individual attributes will be stored one right after the other (subject to
  alignment requirements). Note that in this case, the format depends on the number of
  vertices, and needs to change when the number of vertices changes. When not specified,
  vertex format will be interleaved. (example: PNCPNCPNCPNC).

**Example**

```ts
// Specify 3-component positions (x, y, z)
const vertexFormat = new VertexFormat(graphicsDevice, [
    { semantic: SEMANTIC_POSITION, components: 3, type: TYPE_FLOAT32 }
]);
```

**Example**

```ts
// Specify 2-component positions (x, y), a texture coordinate (u, v) and a vertex color (r, g, b, a)
const vertexFormat = new VertexFormat(graphicsDevice, [
    { semantic: SEMANTIC_POSITION, components: 2, type: TYPE_FLOAT32 },
    { semantic: SEMANTIC_TEXCOORD0, components: 2, type: TYPE_FLOAT32 },
    { semantic: SEMANTIC_COLOR, components: 4, type: TYPE_UINT8, normalize: true }
]);
```

## Methods

### hasUv

```ts
hasUv(index: number): boolean
```

Returns true if the format contains the texture coordinate set with the specified index.

**Parameters**

- `index` (`number`): The index of the texture coordinate set, from 0 for
  [SEMANTIC_TEXCOORD0](https://api.playcanvas.com/engine/variables/SEMANTIC_TEXCOORD0.md) to 7 for [SEMANTIC_TEXCOORD7](https://api.playcanvas.com/engine/variables/SEMANTIC_TEXCOORD7.md).

**Returns** `boolean`: True if the format contains the texture coordinate set.

### getDefaultInstancingFormat

```ts
static getDefaultInstancingFormat(graphicsDevice: GraphicsDevice): VertexFormat
```

The [VertexFormat](https://api.playcanvas.com/engine/classes/VertexFormat.md) used to store matrices of type [Mat4](https://api.playcanvas.com/engine/classes/Mat4.md) for hardware instancing.
The matrix rows use [SEMANTIC_ATTR11](https://api.playcanvas.com/engine/variables/SEMANTIC_ATTR11.md), [SEMANTIC_ATTR12](https://api.playcanvas.com/engine/variables/SEMANTIC_ATTR12.md), [SEMANTIC_ATTR14](https://api.playcanvas.com/engine/variables/SEMANTIC_ATTR14.md)
and [SEMANTIC_ATTR15](https://api.playcanvas.com/engine/variables/SEMANTIC_ATTR15.md). The first two share their attribute locations with
[SEMANTIC_TEXCOORD6](https://api.playcanvas.com/engine/variables/SEMANTIC_TEXCOORD6.md) and [SEMANTIC_TEXCOORD7](https://api.playcanvas.com/engine/variables/SEMANTIC_TEXCOORD7.md), so a shader reading those texture
coordinate sets needs a custom instancing format on other attributes.

**Parameters**

- `graphicsDevice` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device used to create this vertex
  format.

**Returns** [`VertexFormat`](https://api.playcanvas.com/engine/classes/VertexFormat.md): The default instancing vertex format.
