Engine API Reference - v2.23.0-beta.17
    Preparing search index...

    Class VertexBuffer

    A vertex buffer is the mechanism via which the application specifies vertex data to the graphics hardware.

    Index
    • Create a new VertexBuffer instance.

      Parameters

      • graphicsDevice: GraphicsDevice

        The graphics device used to manage this vertex buffer.

      • format: VertexFormat

        The vertex format of this vertex buffer.

      • numVertices: number

        The number of vertices that this vertex buffer will hold.

      • Optionaloptions: {
            data?: ArrayBuffer | ArrayBufferView<ArrayBufferLike>;
            storage?: boolean;
            usage?: number;
        }

        Object for passing optional arguments.

        • Optionaldata?: ArrayBuffer | ArrayBufferView<ArrayBufferLike>

          Initial data. Can be an ArrayBuffer or a typed array (for example a Float32Array). The data is stored by reference and is not copied, so a typed array that is a view into a larger buffer is kept as-is. If left unspecified, the vertex buffer will be initialized to zeros.

        • Optionalstorage?: boolean

          Defines if the vertex buffer can be used as a storage buffer by a compute shader. Defaults to false. Only supported on WebGPU.

        • Optionalusage?: number

          The usage type of the vertex buffer (see BUFFER_*). Defaults to BUFFER_STATIC.

      • ...args: any[]

      Returns VertexBuffer

    • Returns the number of vertices stored in the specified vertex buffer.

      Returns number

      The number of vertices stored in the vertex buffer.

    • Returns the usage type of the specified vertex buffer. This indicates whether the buffer can be modified once and used many times BUFFER_STATIC, modified repeatedly and used many times BUFFER_DYNAMIC or modified once and used at most a few times BUFFER_STREAM.

      Returns number

      The usage type of the vertex buffer (see BUFFER_*).

    • Sets the data of the vertex buffer and uploads it to the GPU.

      Parameters

      • Optionaldata: ArrayBuffer | ArrayBufferView<ArrayBufferLike>

        Source data. Can be an ArrayBuffer or a typed array. Stored by reference, not copied.

      Returns boolean

      True if function finished successfully, false otherwise.

    • Uploads the client side copy of the vertex buffer to the GPU. When called without arguments, uploads the entire buffer. An explicit range uploads only those bytes at the same GPU offset. The first upload always initializes the entire GPU buffer, regardless of the requested range. A zero byte length does nothing, including before the first upload.

      Partial uploads do not resize the buffer or change its CPU storage. The caller must upload every modified range before expecting those changes on the GPU. Context restoration uploads the entire CPU storage. Invalid ranges are ignored in all builds and report an assertion in debug builds.

      Parameters

      • OptionalbyteOffset: number

        Offset in bytes from the start of the buffer's storage. Defaults to 0. Must be a non-negative integer and a multiple of 4 on all graphics backends.

      • OptionalbyteLength: number

        Number of bytes to upload. Defaults to the remaining bytes after byteOffset. The length must be a non-negative integer and the range must fit within the buffer. Partial ranges require a length that is a multiple of 4. Full-buffer uploads support any byte length, whether the range is explicit or the arguments are omitted.

      Returns void

      // After modifying bytes 16 through 31 of the CPU storage:
      vertexBuffer.unlock(16, 16);