Nameless Engine
Loading...
Searching...
No Matches
ne::UploadBuffer Class Reference

#include <UploadBuffer.h>

Public Member Functions

 UploadBuffer (std::unique_ptr< GpuResource > pGpuResourceToUse, size_t iElementSizeInBytes, size_t iElementCount)
 
 UploadBuffer (UploadBuffer &)=delete
 
UploadBufferoperator= (UploadBuffer &)=delete
 
void copyDataToElement (size_t iElementIndex, const void *pData, size_t iDataSize)
 
size_t getElementCount () const
 
size_t getElementSizeInBytes () const
 
GpuResourcegetInternalResource () const
 

Private Attributes

std::unique_ptr< GpuResourcepGpuResource
 
unsigned char * pMappedResourceData = nullptr
 
size_t iElementSizeInBytes = 0
 
size_t iElementCount = 0
 

Detailed Description

Wrapper class with handy functions that takes ownership of a GPU resource with available CPU write access, typically used when a buffer needs to be frequently updated from the CPU side.

Constructor & Destructor Documentation

◆ UploadBuffer()

ne::UploadBuffer::UploadBuffer ( std::unique_ptr< GpuResource pGpuResourceToUse,
size_t  iElementSizeInBytes,
size_t  iElementCount 
)

Initializes the wrapper with data to use.

Parameters
pGpuResourceToUseGPU resource with available CPU access.
iElementSizeInBytesSize of one buffer element in bytes (already padded if needed).
iElementCountAmount of elements in the resource.

Member Function Documentation

◆ copyDataToElement()

void ne::UploadBuffer::copyDataToElement ( size_t  iElementIndex,
const void *  pData,
size_t  iDataSize 
)
inline

Copies the specified data to the element in the resource.

Parameters
iElementIndexIndex of the element to copy the data to (see getElementCount).
pDataData to copy.
iDataSizeSize in bytes of data to copy.

◆ getElementCount()

size_t ne::UploadBuffer::getElementCount ( ) const

Returns the number of elements stored in the buffer.

Returns
Number of elements stored in the buffer.

◆ getElementSizeInBytes()

size_t ne::UploadBuffer::getElementSizeInBytes ( ) const

Returns the size of one element (includes padding if it was needed) stored in the buffer.

Returns
Element size in bytes.

◆ getInternalResource()

GpuResource * ne::UploadBuffer::getInternalResource ( ) const

Returns GPU resource that this object wraps.

Warning
Do not delete (free) returned pointer.
Returns
GPU resource.

Member Data Documentation

◆ iElementCount

size_t ne::UploadBuffer::iElementCount = 0
private

Amount of elements in pGpuResource.

◆ iElementSizeInBytes

size_t ne::UploadBuffer::iElementSizeInBytes = 0
private

Size of one buffer element in bytes (see iElementCount).

◆ pGpuResource

std::unique_ptr<GpuResource> ne::UploadBuffer::pGpuResource
private

GPU resource with available CPU access.

Warning
In DirectX, before releasing this resource we should Unmap it.

◆ pMappedResourceData

unsigned char* ne::UploadBuffer::pMappedResourceData = nullptr
private

CPU pointer to the data located in pGpuResource.

Remarks
CPU reads should be avoided, they will work, but are prohibitively slow on many common GPU architectures.

The documentation for this class was generated from the following files: