参考 createStorage()

createStorage()

This feature requires the p5.webgpu.js addon.
此 API 是实验性的

其行为可能在 p5.js 的未来版本中发生变化。

Creates a p5.StorageBuffer, which is a block of data that shaders can read from, and compute shaders can also write to. This is only available in WebGPU mode.

To read or write the data inside a shader, use uniformStorage(). To update its contents from JavaScript, call .update() on the result with new data.

Pass an array of objects to store a list of items, each with named properties. The properties can be numbers, arrays of numbers, vectors created with createVector(), or colors created with color(). Inside the shader, each item is accessed by index, and its properties are available by name.

You can also store a plain list of numbers by passing an array of numbers. Inside the shader, each number is accessed by index directly. To create an empty list to be filled in by a compute shader, pass a count instead.

示例

语法

createStorage(dataOrCount)

参数

dataOrCount
Number|Array|Float32Array|Object[]: Either a number specifying the count of floats, an array/Float32Array of floats, or an array of objects describing struct elements.

返回值

p5.StorageBuffer: A storage buffer.
Notice any errors or typos? Please let us know. Please feel free to edit src/core/p5.Renderer3D.js and open a pull request!

相关参考