Reference createStorageList()

createStorageList()

This feature requires the p5.webgpu.js addon.
This API is experimental

Its behavior may change in a future version of p5.js.

Creates a p5.StorageList, which is a variable-length block of data that compute shaders can push elements into, and regular shaders can read from. This is only available in WebGPU mode.

It takes the maximum number of items that can be in the list, and then an optional example object of what you will push into the list. If you do not provide an example object, the list will be of numbers rather than objects.

p5.StorageLists are similar to p5.StorageBuffers, created with createStorage(), which can also be read from and written to by shaders. Those are fixed-length, so the number of items never changes. p5.StorageLists have a push() method that can be called from compute shaders, making this helpful for cases when the number of items might change.

For example, you may want create particle systems where the number of particles visible is not fixed. Pass the p5.StorageList into instances() to draw one instance per item in the list:

Another thing you might want to do is draw a different number of instances of a shape every frame, but where you calculate the instances in a compute shader for speed, where it can happen in parallel:

Examples

Syntax

createStorageList(maxCapacity, [schemaOrData])

Parameters

maxCapacity
Number: Maximum number of elements the list can hold.
schemaOrData
Object|Object[]: A schema template object or initial array of struct objects. Omit for a float list.

Returns

p5.StorageList:

Related References