Cogs.Rendering
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Cogs::MappedBuffer< MappedDataType > Struct Template Reference

Provides RAII style mapping of a buffer resource. More...

#include <IBuffers.h>

Public Member Functions

 MappedBuffer (struct IContext *context, BufferHandle bufferHandle, MapMode::EMapMode mapMode=MapMode::Read, size_t size=0)
 Constructs a mapped buffer, initializing the mapped contents from the context and buffer handle given.
 
 MappedBuffer (const MappedBuffer &other)=delete
 Deleted copy constructor.
 
 ~MappedBuffer ()
 Destructs the mapped buffer.
 
MappedDataType * get ()
 Get the raw pointer to the mapped data.
 
MappedDataType * operator-> ()
 Pointer operator to allow using the mapped structure as if it was a raw pointer to the data.
 
const MappedDataType * operator-> () const
 Const overload of pointer operator.
 
 operator MappedDataType * ()
 Implicit cast to mapped data type to allow passing the mapped structure to methods expecting a raw pointer.
 
 operator bool () const
 Boolean conversion operator provided to allow pointer-like semantics when checking the validity of the mapped data.
 
MappedDataType & operator[] (size_t index)
 Indexing operator provided to perform optional boundary checks on the mapped data.
 
const MappedDataType & operator[] (size_t index) const
 Indexing operator provided to perform optional boundary checks on the mapped data.
 
uint32_t getStride () const
 Get the stride of the mapped resource in bytes.
 

Private Attributes

struct IContextcontext = nullptr
 
BufferHandle bufferHandle
 
MappedDataType * data = nullptr
 
size_t size = 0
 
uint32_t stride = 0
 

Detailed Description

template<typename MappedDataType>
struct Cogs::MappedBuffer< MappedDataType >

Provides RAII style mapping of a buffer resource.

Constructor & Destructor Documentation

◆ MappedBuffer() [1/2]

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::MappedBuffer ( struct IContext context,
BufferHandle  bufferHandle,
MapMode::EMapMode  mapMode = MapMode::Read,
size_t  size = 0 
)
inline

Constructs a mapped buffer, initializing the mapped contents from the context and buffer handle given.

Parameters
contextPointer to the current graphics context.
bufferHandleHandle to the buffer to map data from.
mapModeMode to map the buffer in.

References Cogs::MappedBuffer< MappedDataType >::bufferHandle, Cogs::MappedBuffer< MappedDataType >::context, Cogs::MappedBuffer< MappedDataType >::data, Cogs::IContext::map(), and Cogs::MappedBuffer< MappedDataType >::stride.

◆ MappedBuffer() [2/2]

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::MappedBuffer ( const MappedBuffer< MappedDataType > &  other)
delete

Deleted copy constructor.

◆ ~MappedBuffer()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::~MappedBuffer ( )
inline

Destructs the mapped buffer.

If the buffer was successfully mapped, it will be unmapped.

References Cogs::MappedBuffer< MappedDataType >::bufferHandle, Cogs::MappedBuffer< MappedDataType >::context, Cogs::MappedBuffer< MappedDataType >::data, and Cogs::IContext::unmap().

Member Function Documentation

◆ get()

template<typename MappedDataType >
MappedDataType * Cogs::MappedBuffer< MappedDataType >::get ( )
inline

Get the raw pointer to the mapped data.

Returns
Pointer to mapped data, nullptr if the mapping was not successful.

References Cogs::MappedBuffer< MappedDataType >::data.

◆ getStride()

template<typename MappedDataType >
uint32_t Cogs::MappedBuffer< MappedDataType >::getStride ( ) const
inline

Get the stride of the mapped resource in bytes.

References Cogs::MappedBuffer< MappedDataType >::stride.

◆ operator bool()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::operator bool ( ) const
inlineexplicit

Boolean conversion operator provided to allow pointer-like semantics when checking the validity of the mapped data.

if (data) {
// Mapped data is valid and can worked with.
*data = 1.0f;
}
Provides RAII style mapping of a buffer resource.
Definition: IBuffers.h:160
BufferHandle bufferHandle
Definition: IBuffers.h:261
MappedDataType * data
Definition: IBuffers.h:262
struct IContext * context
Definition: IBuffers.h:260

References Cogs::MappedBuffer< MappedDataType >::data.

◆ operator MappedDataType *()

template<typename MappedDataType >
Cogs::MappedBuffer< MappedDataType >::operator MappedDataType * ( )
inline

Implicit cast to mapped data type to allow passing the mapped structure to methods expecting a raw pointer.

References Cogs::MappedBuffer< MappedDataType >::data.

◆ operator->() [1/2]

template<typename MappedDataType >
MappedDataType * Cogs::MappedBuffer< MappedDataType >::operator-> ( )
inline

Pointer operator to allow using the mapped structure as if it was a raw pointer to the data.

References Cogs::MappedBuffer< MappedDataType >::data.

◆ operator->() [2/2]

template<typename MappedDataType >
const MappedDataType * Cogs::MappedBuffer< MappedDataType >::operator-> ( ) const
inline

Const overload of pointer operator.

References Cogs::MappedBuffer< MappedDataType >::data.

◆ operator[]() [1/2]

template<typename MappedDataType >
MappedDataType & Cogs::MappedBuffer< MappedDataType >::operator[] ( size_t  index)
inline

Indexing operator provided to perform optional boundary checks on the mapped data.

Parameters
indexIndex of the element in the array to access.
Returns
Reference to the mapped element.

References Cogs::MappedBuffer< MappedDataType >::data, and Cogs::MappedBuffer< MappedDataType >::size.

◆ operator[]() [2/2]

template<typename MappedDataType >
const MappedDataType & Cogs::MappedBuffer< MappedDataType >::operator[] ( size_t  index) const
inline

Indexing operator provided to perform optional boundary checks on the mapped data.

Parameters
indexIndex of the element in the array to access.
Returns
Const reference to the mapped element.

References Cogs::MappedBuffer< MappedDataType >::data, and Cogs::MappedBuffer< MappedDataType >::size.

Member Data Documentation

◆ bufferHandle

template<typename MappedDataType >
BufferHandle Cogs::MappedBuffer< MappedDataType >::bufferHandle
private

◆ context

template<typename MappedDataType >
struct IContext* Cogs::MappedBuffer< MappedDataType >::context = nullptr
private

◆ data

template<typename MappedDataType >
MappedDataType* Cogs::MappedBuffer< MappedDataType >::data = nullptr
private

◆ size

template<typename MappedDataType >
size_t Cogs::MappedBuffer< MappedDataType >::size = 0
private

◆ stride

template<typename MappedDataType >
uint32_t Cogs::MappedBuffer< MappedDataType >::stride = 0
private

The documentation for this struct was generated from the following file: