glTF Byte Alignment for Accessors and BufferViews

In glTF 2.0, precise byte alignment constraints govern how binary data is organized within bufferView and accessor structures to ensure efficient GPU memory mapping and prevent CPU memory alignment faults. This article details the specific alignment rules required for bufferView.byteOffset, bufferView.byteStride, and accessor.byteOffset, explaining how these offsets correlate with the underlying component data types.

BufferView Alignment Constraints

A bufferView represents a contiguous segment of a raw binary buffer. glTF enforces two primary alignment restrictions on bufferView properties:

  • byteOffset: The starting point of a bufferView within its parent buffer must be aligned to a multiple of 4 bytes. This requirement guarantees that all nested accessors begin at a memory address that satisfies the basic 4-byte boundaries standard across 32-bit and 64-bit hardware architectures.
  • byteStride: When interleaving vertex attributes within a single bufferView, the byteStride defines the distance in bytes between consecutive vertex elements. The byteStride must be a multiple of 4 and must fall within the range of 4 to 252 bytes inclusive. If defined, it can only be applied to bufferViews referencing vertex attributes, never to index buffers or animation samplers.

Accessor Alignment Constraints

An accessor defines the typed view (data type, component type, count) into a bufferView. The alignment of an accessor is strictly tied to its componentType:

  • byteOffset: The byteOffset of an accessor specifies the offset relative to the start of the bufferView. This value must be an exact multiple of the component type's size in bytes:
    • 1-byte alignment: BYTE (5120) and UNSIGNED_BYTE (5121).
    • 2-byte alignment: SHORT (5122) and UNSIGNED_SHORT (5123).
    • 4-byte alignment: UNSIGNED_INT (5125) and FLOAT (5126).

Because bufferView.byteOffset is guaranteed to be a multiple of 4, aligning accessor.byteOffset to its component type's size ensures that the absolute offset within the binary buffer (bufferView.byteOffset + accessor.byteOffset) is always aligned to the component type's natural boundary.

GLB Container Alignment

When distributing models in the binary container format (.glb), additional padding constraints apply to support overall alignment:

  • The binary chunk (BIN) must be padded with trailing zeroes (0x00) so that its total length is a multiple of 4.
  • The JSON chunk must be padded with trailing space characters (0x20) so that its total length is also a multiple of 4.

These global 4-byte boundaries ensure that the binary data chunk always begins at a 4-byte aligned position relative to the start of the file, allowing direct pointer casting and zero-copy loading in client applications.