Version: 2021.3

GraphicsBuffer

class in UnityEngine

切换到手册

描述

GPU graphics data buffer, for working with geometry or compute shader data.

ComputeShader programs often need to read or write arbitrary data from or to memory buffers, and some rendering algorithms need a lower level access or control over geometry data than what is provided by the Mesh class. You can use GraphicsBuffer for these cases. You create the buffers from C# scripts, and then fill them with data using either C# scripts or compute shader programs.

A graphics buffer is similar to an array in C#, in that it has a number of elements (count) of the same size (stride). You must supply the intended buffer usage (target) when you create a GraphicsBuffer; for example, you must pass GraphicsBuffer.Target.Index for the buffer to be usable as a geometry index buffer.

When you have finished working with the buffer, you must manually release the GPU memory should be released. You can do this using C# dispose pattern, or by calling Release.

See Also: Graphics.DrawProcedural, Graphics.CopyBuffer, ComputeShader, Shader.SetGlobalBuffer, Material.SetBuffer.

变量

count缓冲区中元素的数量(只读)。
nameThe debug label for the graphics buffer (setter only).
stride缓冲区中一个元素的大小(只读)。
targetUsage target, which specifies the intended usage of this GraphicsBuffer (Read Only).

构造函数

GraphicsBuffer创建图形缓冲区。

公共函数

GetData将该缓冲区中的数据值读取到数组中。该数组只能使用 blittable 类型。
GetNativeBufferPtr获取指向该缓冲区的原生(底层图形 API)指针。
IsValid如果图形缓冲区有效,则返回 true,否则返回 false。
Release释放图形缓冲区。
SetCounterValue设置附加/使用缓冲区的计数器值。
SetData使用数组中的值设置该缓冲区。

静态函数

CopyCountCopy the counter value of a GraphicsBuffer into another buffer.