Class: Buffer

rendering.Buffer

A wrapper for a WebGPU/WebGL Buffer. In PixiJS, the Buffer class is used to manage the data that is sent to the GPU rendering pipeline. It abstracts away the underlying GPU buffer and provides an interface for uploading typed arrays or other data to the GPU, They are used in the following places:

.1. Geometry as attribute data or index data for geometry
.2. UniformGroup as an underlying buffer for uniform data
.3. BufferResource as an underlying part of a buffer used directly by the GPU program

It is important to note that you must provide a usage type when creating a buffer. This is because the underlying GPU buffer needs to know how it will be used. For example, if you are creating a buffer to hold vertex data, you would use BufferUsage.VERTEX. This will tell the GPU that this buffer will be used as a vertex buffer. This is important because it will affect how you can use the buffer.

Buffers are updated by calling the Buffer.update method. This immediately updates the buffer on the GPU. Be mindful of calling this more often than you need to. It is recommended to update buffers only when needed.

In WebGPU, a GPU buffer cannot resized. This limitation is abstracted away, but know that resizing a buffer means creating a brand new one and destroying the old, so it is best to limit this if possible.

new rendering.Buffer (options) overrides

Creates a new Buffer with the given options

Name Type Description
options BufferOptions

the options for the buffer

Example

const buffer = new Buffer({
    data: new Float32Array([1, 2, 3, 4]),
    usage: BufferUsage.VERTEX,
});

Extends

Implements

Members

data

TODO

Methods

update (sizeInBytes) void

updates the buffer on the GPU to reflect the data in the buffer. By default it will update the entire buffer. If you only want to update a subset of the buffer, you can pass in the size of the buffer to update.

Name Type Attributes Description
sizeInBytes number <optional>

the new size of the buffer in bytes

Events

change

emits when the underlying buffer has changed shape (i.e. resized) letting the renderer know that it needs to discard the old buffer on the GPU and create a new one

destroy

emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU

update

emits when the underlying buffer data has been updated. letting the renderer know that it needs to update the buffer on the GPU