Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "aos"

Index

Functions

Functions

Const aos

  • aos<K>(num: number, specs: AOSSpecs<K>, buf?: ArrayBuffer, byteOffset?: number): SOA<K>
  • Constructs SOA instance from given attrib specs and optional ArrayBuffer (w/ optional start address / byte offset, which MUST be properly pre-aligned). The resulting layout will be an underlying interleaved AOS buffer with each attrib configured to map that same array buffer relative to the given byteOffset (default: 0). If no array buffer is given, a properly sized one will be created.

    First computes attrib offsets, alignments and the overall struct size, then configures buffer views and strides for each attrib. This is to ensure each attrib is correctly mapped in its buffer view (e.g. float values need to be aligned to 4-byte boundaries). The overall inter-struct packing/stride length is dependent on the largest attrib type used. E.g. the following specs will cause a stride length of 16 bytes between each resulting SOA element, even though the actual struct size is only 13 bytes:

    example
    aos(
      1024,
      {
        a: { type: Type.U16, size: 1 }, // 2 bytes, align 2, offset 0
        b: { type: Type.F32, size: 2 }, // 8 bytes, align 4, offset 4
        c: { type: Type.U8, size: 1 },  // 1 byte,  align 1, offset 12
      }
    );

    Type parameters

    • K: string

    Parameters

    • num: number

      -

    • specs: AOSSpecs<K>

      -

    • Optional buf: ArrayBuffer

      -

    • Default value byteOffset: number = 0

      -

    Returns SOA<K>

Generated using TypeDoc