Version: 2022.1
LanguageEnglish
  • C#

GraphicsBuffer

class in UnityEngine

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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.RenderPrimitivesIndexed, Graphics.RenderPrimitivesIndexedIndirect, Graphics.CopyBuffer, ComputeShader, Shader.SetGlobalBuffer, Material.SetBuffer.

Properties

bufferHandleThe internal handle of this GraphicsBuffer. Only valid until the buffer is disposed of. (Read Only)
countNumber of elements in the buffer (Read Only).
nameThe debug label for the graphics buffer (setter only).
strideSize of one element in the buffer (Read Only).
targetTarget, which specifies the intended target(s) of this GraphicsBuffer (Read Only).
usageFlagsThe flags that specify how this GraphicsBuffer can be used or updated (Read Only).

Constructors

GraphicsBufferCreate a Graphics Buffer.

Public Methods

GetDataRead data values from the buffer into an array. The array can only use blittable types.
GetNativeBufferPtrRetrieve a native (underlying graphics API) pointer to the buffer.
IsValidReturns true if this graphics buffer is valid, or false otherwise.
LockBufferForWriteBegins a write operation to the buffer
ReleaseRelease a Graphics Buffer.
SetCounterValueSets counter value of append/consume buffer.
SetDataSet the buffer with values from an array.
UnlockBufferAfterWriteEnds a write operation to the buffer

Static Methods

CopyCountCopy the counter value of a GraphicsBuffer into another buffer.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961