Class GPUBuffer
All-in-one GPU buffer class. This class is able to create index buffers, vertex buffers, structured buffer and argument buffers.
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class GPUBuffer : GPUResource
Constructors
GPUBuffer()
Properties
Description
Gets buffer description structure.
Declaration
[Unmanaged]
public GPUBufferDescription Description { get; }
Property Value
GPUBufferDescription
|
ElementsCount
Gets buffer elements count (size divided by the stride).
Declaration
[Unmanaged]
public uint ElementsCount { get; }
Property Value
System.UInt32
|
Format
Gets buffer data format (if used).
Declaration
[Unmanaged]
public PixelFormat Format { get; }
Property Value
PixelFormat
|
IsAllocated
Gets a value indicating whether this buffer has been allocated.
Declaration
[Unmanaged]
public bool IsAllocated { get; }
Property Value
System.Boolean
|
IsDynamic
Checks if buffer is a staging buffer (supports CPU readback).
Declaration
[Unmanaged]
public bool IsDynamic { get; }
Property Value
System.Boolean
|
IsShaderResource
Gets a value indicating whether this buffer is a shader resource.
Declaration
[Unmanaged]
public bool IsShaderResource { get; }
Property Value
System.Boolean
|
IsStaging
Checks if buffer is a staging buffer (supports CPU readback).
Declaration
[Unmanaged]
public bool IsStaging { get; }
Property Value
System.Boolean
|
IsUnorderedAccess
Gets a value indicating whether this buffer is a unordered access.
Declaration
[Unmanaged]
public bool IsUnorderedAccess { get; }
Property Value
System.Boolean
|
Size
Gets buffer size in bytes.
Declaration
[Unmanaged]
public uint Size { get; }
Property Value
System.UInt32
|
Stride
Gets buffer stride in bytes.
Declaration
[Unmanaged]
public uint Stride { get; }
Property Value
System.UInt32
|
Methods
DownloadData(out Byte[])
Stops current thread execution to gather buffer data from the GPU. Cannot be called from main thread if the buffer is not a dynamic nor staging readback.
Declaration
[Unmanaged]
public bool DownloadData(out byte[] result)
Parameters
System.Byte[]
result
The result data. |
Returns
System.Boolean
True if cannot download data, otherwise false. |
GetData(out Byte[])
Gets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic and staging readback buffers (other types support depends on graphics backend implementation).
Declaration
[Unmanaged]
public bool GetData(out byte[] output)
Parameters
System.Byte[]
output
The output data container. |
Returns
System.Boolean
True if failed, otherwise false. |
Init(ref GPUBufferDescription)
Creates new buffer.
Declaration
[Unmanaged]
public bool Init(ref GPUBufferDescription desc)
Parameters
GPUBufferDescription
desc
The buffer description. |
Returns
System.Boolean
True if cannot create buffer, otherwise false. |
Map(GPUResourceMapMode)
Gets a CPU pointer to the resource by mapping its contents. Denies the GPU access to that resource.
Declaration
[Unmanaged]
public IntPtr Map(GPUResourceMapMode mode)
Parameters
GPUResourceMapMode
mode
The map operation mode. |
Returns
System.IntPtr
The pointer of the mapped CPU buffer with resource data or null if failed. |
Remarks
Always call Unmap if the returned pointer is valid to release resources.
Resize(UInt32)
Tries to resize the buffer (warning: contents will be lost).
Declaration
[Unmanaged]
public bool Resize(uint newSize)
Parameters
System.UInt32
newSize
The new size (in bytes). |
Returns
System.Boolean
True if cannot resize buffer, otherwise false. |
SetData(IntPtr, UInt32)
Sets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic buffers (other types support depends on graphics backend implementation).
Declaration
[Unmanaged]
public void SetData(IntPtr data, uint size)
Parameters
System.IntPtr
data
The source data to upload. |
System.UInt32
size
The size of data (in bytes). |
Unmap()
Invalidates the mapped pointer to a resource and restores the GPU's access to that resource.
Declaration
[Unmanaged]
public void Unmap()
View()
Gets the view for the whole buffer.
Declaration
[Unmanaged]
public GPUBufferView View()
Returns
GPUBufferView
|