Class GPUBuffer
All-in-one GPU buffer class. This class is able to create index buffers, vertex buffers, structured buffer and argument buffers.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Graphics/GPUBuffer.h
Syntax
public class GPUBuffer : public GPUResource
Constructors
GPUBuffer()
Declaration
protected GPUBuffer()
Fields
_desc
_isLocked
Declaration
protected bool _isLocked = false
Field Value
bool
|
Methods
DownloadData(BytesContainer& result)
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
public bool DownloadData(BytesContainer& result)
Parameters
BytesContainer
result
The result data. |
Returns
bool
True if cannot download data, otherwise false. |
DownloadDataAsync(BytesContainer& result)
Creates GPU async task that will gather buffer data from the GPU.
Declaration
public Task* DownloadDataAsync(BytesContainer& result)
Parameters
BytesContainer
result
The result data. |
Returns
Task
Download data task (not started yet). |
GetData(BytesContainer& output)
Gets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic and staging buffers (other types support depends on graphics backend implementation).
Declaration
public bool GetData(BytesContainer& output)
Parameters
BytesContainer
output
The output data container. |
Returns
bool
True if failed, otherwise false. |
GetDescription()
Gets buffer description structure.
Declaration
public GPUBufferDescription GetDescription() const
Returns
GPUBufferDescription
|
GetElementsCount()
Gets buffer elements count (size divided by the stride).
Declaration
public uint32 GetElementsCount() const
Returns
uint32
|
GetFlags()
GetFormat()
Gets buffer data format (if used).
Declaration
public PixelFormat GetFormat() const
Returns
PixelFormat
|
GetResourceType()
Gets the GPU resource type.
Declaration
public virtual GPUResourceType GetResourceType() const final override
Returns
GPUResourceType
|
Overrides
GetSize()
Gets buffer size in bytes.
Declaration
public uint32 GetSize() const
Returns
uint32
|
GetStride()
Gets buffer stride in bytes.
Declaration
public uint32 GetStride() const
Returns
uint32
|
GetVertexLayout()
Gets vertex elements layout used by vertex buffers only.
Declaration
public GPUVertexLayout* GetVertexLayout() const
Returns
GPUVertexLayout
|
Init(const GPUBufferDescription& desc)
Creates new buffer.
Declaration
public bool Init(const GPUBufferDescription& desc)
Parameters
GPUBufferDescription
desc
The buffer description. |
Returns
bool
True if cannot create buffer, otherwise false. |
IsAllocated()
Gets a value indicating whether this buffer has been allocated.
Declaration
public bool IsAllocated() const
Returns
bool
|
IsDynamic()
Checks if buffer is a dynamic buffer.
Declaration
public bool IsDynamic() const
Returns
bool
|
IsShaderResource()
Gets a value indicating whether this buffer is a shader resource.
Declaration
public bool IsShaderResource() const
Returns
bool
|
IsStaging()
Checks if buffer is a staging buffer (supports CPU access).
Declaration
public bool IsStaging() const
Returns
bool
|
IsUnorderedAccess()
Gets a value indicating whether this buffer is a unordered access.
Declaration
public bool IsUnorderedAccess() const
Returns
bool
|
Map(GPUResourceMapMode mode)
Gets a CPU pointer to the resource by mapping its contents. Denies the GPU access to that resource.
Always call Unmap if the returned pointer is valid to release resources.
Declaration
public virtual void* Map(GPUResourceMapMode mode) = 0
Parameters
GPUResourceMapMode
mode
The map operation mode. |
Returns
void
The pointer of the mapped CPU buffer with resource data or null if failed. |
OnInit()
Declaration
protected virtual bool OnInit() = 0
Returns
bool
|
OnReleaseGPU()
Releases GPU resource data (implementation).
Declaration
protected virtual void OnReleaseGPU() override
Overrides
Resize(uint32 newSize)
Tries to resize the buffer (warning: contents will be lost).
Declaration
public bool Resize(uint32 newSize)
Parameters
uint32
newSize
The new size (in bytes). |
Returns
bool
True if cannot resize buffer, otherwise false. |
SetData(const void* data, uint32 size)
Sets the buffer data via map/memcpy/unmap sequence. Always supported for dynamic buffers (other types support depends on graphics backend implementation).
Declaration
public void SetData(const void* data, uint32 size)
Parameters
void
data
The source data to upload. |
uint32
size
The size of data (in bytes). |
ToStagingReadback()
Creates new staging readback buffer with the same dimensions and properties as a source buffer (but without a data transferred; warning: caller must delete object).
Declaration
public GPUBuffer* ToStagingReadback() const
Returns
GPUBuffer
Staging readback buffer. |
ToStagingUpload()
Creates new staging upload buffer with the same dimensions and properties as a source buffer (but without a data transferred; warning: caller must delete object).
Declaration
public GPUBuffer* ToStagingUpload() const
Returns
GPUBuffer
Staging upload buffer. |
ToString()
Gets the string representation of this object.
Declaration
public virtual String ToString() const override
Returns
String
|
Overrides
Unmap()
Invalidates the mapped pointer to a resource and restores the GPU's access to that resource.
Declaration
public virtual void Unmap() = 0
View()
Gets the view for the whole buffer.
Declaration
public virtual GPUBufferView* View() const = 0
Returns
GPUBufferView
|