# VertexLayout.Builder

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/VertexLayout.kt+class:androidx.xr.scenecore.VertexLayout.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
public final class VertexLayout.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout`.

This builder is capable of building a layout where vertex attributes are spread across multiple vertex buffers. Attributes added with `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#addAttribute(androidx.xr.scenecore.VertexAttribute,androidx.xr.scenecore.VertexAttributeType,kotlin.Int)` belong to the current buffer. To start adding attributes to a new buffer, call `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#startNextBuffer()`.

An `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` will be thrown by `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#addAttribute(androidx.xr.scenecore.VertexAttribute,androidx.xr.scenecore.VertexAttributeType,kotlin.Int)` if duplicate attributes are added, and by `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#build()` if the layout does not contain a `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#POSITION()` attribute, or if only one of `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#BONE_INDICES()` or `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#BONE_WEIGHTS()` is present.

Basic example of creating a layout with a single vertex buffer:

```
val layout = VertexLayout.Builder()
    .addAttribute(VertexAttribute.POSITION, VertexAttributeType.FLOAT3)
    .addAttribute(VertexAttribute.NORMAL, VertexAttributeType.FLOAT3)
    .addAttribute(VertexAttribute.UV0, VertexAttributeType.FLOAT2)
    .build()
```

Example of creating a layout with multiple vertex buffers, explicit offsets, and strides:

```
val layout = VertexLayout.Builder()
    // First buffer layout (e.g. position and normal interleaved)
    .addAttribute(VertexAttribute.POSITION, VertexAttributeType.FLOAT3, offset = 0)
    .addAttribute(VertexAttribute.NORMAL, VertexAttributeType.FLOAT3, offset = 12)
    .setStride(24)
    .startNextBuffer()
    // Second buffer layout (e.g. UV and color interleaved)
    .addAttribute(VertexAttribute.UV0, VertexAttributeType.FLOAT2, offset = 0)
    .addAttribute(VertexAttribute.COLOR, VertexAttributeType.UBYTE4_NORM, offset = 8)
    .setStride(12)
    .build()
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder` | `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#addAttribute(androidx.xr.scenecore.VertexAttributeDescriptor)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeDescriptor descriptor)` Adds a vertex attribute to the current buffer. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder` | `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#addAttribute(androidx.xr.scenecore.VertexAttribute,androidx.xr.scenecore.VertexAttributeType,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute attribute, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeType type, @https://developer.android.com/reference/androidx/annotation/IntRange(from = -1, to = 32767) int offset )` Adds a vertex attribute to the current buffer. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout` | `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#build()()` Builds the `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder` | `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#setStride(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = -1, to = 32767) int stride)` Sets the stride for the current buffer. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder` | `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#startNextBuffer()()` Commits the current buffer and prepares for the next buffer. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public Builder()
```

## Public methods

### addAttribute

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull VertexLayout.Builder addAttribute(@NonNull VertexAttributeDescriptor descriptor)
```

Adds a vertex attribute to the current buffer.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeDescriptor descriptor` | The `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeDescriptor` defining the attribute to add. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the attribute has already been added to the layout. |

### addAttribute

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull VertexLayout.Builder addAttribute(
    @NonNull VertexAttribute attribute,
    @NonNull VertexAttributeType type,
    @IntRange(from = -1, to = 32767) int offset
)
```

Adds a vertex attribute to the current buffer.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute attribute` | The `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute` semantic of the attribute. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeType type` | The `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeType` data type of the attribute. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = -1, to = 32767) int offset` | The byte offset of the attribute from the start of the vertex data. If set to `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttributeDescriptor#AUTO_OFFSET()`, the attribute will be placed immediately after the previous attribute in the same buffer, or at the beginning of the vertex data if this is the first attribute. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the attribute has already been added to the layout. |

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull VertexLayout build()
```

Builds the `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout`.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if no attributes were added, if the layout does not contain a `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#POSITION()` attribute, if only one of `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#BONE_INDICES()` or `https://developer.android.com/reference/androidx/xr/scenecore/VertexAttribute#BONE_WEIGHTS()` is present, if any attributes in the current buffer overlap, or if an explicitly provided stride is smaller than the minimum byte stride required to encompass all attributes. |

### setStride

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull VertexLayout.Builder setStride(@IntRange(from = -1, to = 32767) int stride)
```

Sets the stride for the current buffer.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = -1, to = 32767) int stride` | The byte stride of the buffer. If set to `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout#AUTO_STRIDE()`, the stride will be computed automatically to be the minimum byte stride required to encompass all attributes in the buffer. Otherwise, it must be a positive value up to `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout#MAX_STRIDE()`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#setStride(kotlin.Int)` is not `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout#AUTO_STRIDE()` and not between 1 and `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout#MAX_STRIDE()`. |

### startNextBuffer

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
public final @NonNull VertexLayout.Builder startNextBuffer()
```

Commits the current buffer and prepares for the next buffer.

This method will add the previously set attributes and stride to the layout as a new `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout`, and then reset the buffer layout state. The stride will be reset to `https://developer.android.com/reference/androidx/xr/scenecore/VertexBufferLayout#AUTO_STRIDE()`. Subsequent calls to `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#addAttribute(androidx.xr.scenecore.VertexAttribute,androidx.xr.scenecore.VertexAttributeType,kotlin.Int)` and `https://developer.android.com/reference/androidx/xr/scenecore/VertexLayout.Builder#setStride(kotlin.Int)` will apply to a new buffer.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if no attributes were added to the current buffer. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if any attributes in the current buffer overlap, or if an explicitly provided stride is smaller than the minimum byte stride required to encompass all attributes in the buffer. |