MAGE  v0.171.0
Matthias Advanced Game Engine
mage::rendering::StructuredBuffer< T > Class Template Reference

#include <structured_buffer.hpp>

Public Member Functions

 StructuredBuffer (ID3D11Device &device, std::size_t capacity)
 
 StructuredBuffer (const StructuredBuffer &buffer)=delete
 
 StructuredBuffer (StructuredBuffer &&buffer) noexcept=default
 
 ~StructuredBuffer ()=default
 
StructuredBufferoperator= (const StructuredBuffer &buffer)=delete
 
StructuredBufferoperator= (StructuredBuffer &&buffer) noexcept=default
 
std::size_t size () const noexcept
 
std::size_t capacity () const noexcept
 
void UpdateData (ID3D11DeviceContext &device_context, const AlignedVector< T > &data)
 
ID3D11ShaderResourceView & Get () const noexcept
 
template<typename PipelineStageT >
void Bind (ID3D11DeviceContext &device_context, U32 slot) const noexcept
 

Private Member Functions

void SetupStructuredBuffer (ID3D11Device &device, std::size_t capacity)
 

Private Attributes

ComPtr< ID3D11Buffer > m_buffer
 
ComPtr< ID3D11ShaderResourceView > m_buffer_srv
 
std::size_t m_capacity
 
std::size_t m_size
 

Detailed Description

template<typename T>
class mage::rendering::StructuredBuffer< T >

A class of structured buffers.

Template Parameters
TThe data type.

Constructor & Destructor Documentation

◆ StructuredBuffer() [1/3]

template<typename T>
mage::rendering::StructuredBuffer< T >::StructuredBuffer ( ID3D11Device &  device,
std::size_t  capacity 
)
explicit

Constructs a structured buffer.

Parameters
[in,out]deviceA reference to the device.
[in]capacityThe initial capacity.
Exceptions
ExceptionFailed to setup this structured buffer.

◆ StructuredBuffer() [2/3]

template<typename T>
mage::rendering::StructuredBuffer< T >::StructuredBuffer ( const StructuredBuffer< T > &  buffer)
delete

Constructs a structured buffer from the given structured buffer.

Parameters
[in]bufferA reference to the structured buffer to copy.

◆ StructuredBuffer() [3/3]

template<typename T>
mage::rendering::StructuredBuffer< T >::StructuredBuffer ( StructuredBuffer< T > &&  buffer)
defaultnoexcept

Constructs a structured buffer by moving the given structured buffer.

Parameters
[in]bufferA reference to the structured buffer to move.

◆ ~StructuredBuffer()

template<typename T>
mage::rendering::StructuredBuffer< T >::~StructuredBuffer ( )
default

Destructs this structured buffer.

Member Function Documentation

◆ Bind()

template<typename T>
template<typename PipelineStageT >
void mage::rendering::StructuredBuffer< T >::Bind ( ID3D11DeviceContext &  device_context,
U32  slot 
) const
noexcept

Binds this structured buffer.

Precondition
slot < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT.
Template Parameters
PipelineStageTThe pipeline stage type.
Parameters
[in,out]device_contextA reference to the device context.
[in]slotThe index into the device's zero-based array to set the shader resource view to (ranges from 0 to D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT - 1).

◆ capacity()

template<typename T>
std::size_t mage::rendering::StructuredBuffer< T >::capacity ( ) const
noexcept

Returns the capacity of this structured buffer.

Returns
The capacity of this structured buffer.

◆ Get()

template<typename T>
ID3D11ShaderResourceView& mage::rendering::StructuredBuffer< T >::Get ( ) const
noexcept

Returns the shader resource view of this structured buffer.

Returns
A reference to the shader resource view of this structured buffer.

◆ operator=() [1/2]

template<typename T>
StructuredBuffer& mage::rendering::StructuredBuffer< T >::operator= ( const StructuredBuffer< T > &  buffer)
delete

Copies the given structured buffer to this structured buffer.

Parameters
[in]bufferA reference to the structured buffer to copy.
Returns
A reference to the copy of the given structured buffer (i.e. this structured buffer).

◆ operator=() [2/2]

template<typename T>
StructuredBuffer& mage::rendering::StructuredBuffer< T >::operator= ( StructuredBuffer< T > &&  buffer)
defaultnoexcept

Moves the given structured buffer to this structured buffer.

Parameters
[in]bufferA reference to the structured buffer to move.
Returns
A reference to the moved structured buffer (i.e. this structured buffer).

◆ SetupStructuredBuffer()

template<typename T>
void mage::rendering::StructuredBuffer< T >::SetupStructuredBuffer ( ID3D11Device &  device,
std::size_t  capacity 
)
private

Sets up the resource buffer and shader resource view of this structured buffer.

Parameters
[in,out]deviceA reference to the device.
[in]capacityThe capacity.
Exceptions
ExceptionFailed to setup this structured buffer.

◆ size()

template<typename T>
std::size_t mage::rendering::StructuredBuffer< T >::size ( ) const
noexcept

Returns the size of this structured buffer.

Returns
The size of this structured buffer.

◆ UpdateData()

template<typename T>
void mage::rendering::StructuredBuffer< T >::UpdateData ( ID3D11DeviceContext &  device_context,
const AlignedVector< T > &  data 
)

Updates the data of this structured buffer with the given data.

Parameters
[in,out]device_contextA reference to the device context.
[in]dataA reference to a vector containing the data elements.
Exceptions
ExceptionFailed to update the data.

Member Data Documentation

◆ m_buffer

template<typename T>
ComPtr< ID3D11Buffer > mage::rendering::StructuredBuffer< T >::m_buffer
private

A pointer to the buffer resource of this structured buffer.

◆ m_buffer_srv

template<typename T>
ComPtr< ID3D11ShaderResourceView > mage::rendering::StructuredBuffer< T >::m_buffer_srv
private

A pointer to the shader resource view of this structured buffer.

◆ m_capacity

template<typename T>
std::size_t mage::rendering::StructuredBuffer< T >::m_capacity
private

The number of available slots for storing data elements in the current buffer resource of this structured buffer (i.e. the capacity).

◆ m_size

template<typename T>
std::size_t mage::rendering::StructuredBuffer< T >::m_size
private

The number of used slots for storing data elements in the current buffer resource of this structured buffer (i.e. the size).