Leviathan  0.8.0.0
Leviathan game engine
Leviathan::RotatingBufferHelper< BufferT, MaxBuffers > Class Template Referenceabstract

Helper for having a few BSF buffers for writing in turn. More...

#include <RotatingBufferHelper.h>

Protected Member Functions

BufferT * GetNextDataBuffer ()
 
void ClearDataBuffers ()
 
virtual BufferT _OnNewBufferNeeded ()=0
 

Protected Attributes

std::array< BufferT, MaxBuffers > DataBuffers
 

Detailed Description

template<class BufferT, size_t MaxBuffers>
class Leviathan::RotatingBufferHelper< BufferT, MaxBuffers >

Helper for having a few BSF buffers for writing in turn.

Due to the asynchronous data upload to the GPU multiple buffers may be needed in some places.

Definition at line 17 of file RotatingBufferHelper.h.

Member Function Documentation

◆ _OnNewBufferNeeded()

template<class BufferT, size_t MaxBuffers>
virtual BufferT Leviathan::RotatingBufferHelper< BufferT, MaxBuffers >::_OnNewBufferNeeded ( )
protectedpure virtual

Implemented in Leviathan::GUI::View.

◆ ClearDataBuffers()

template<class BufferT, size_t MaxBuffers>
void Leviathan::RotatingBufferHelper< BufferT, MaxBuffers >::ClearDataBuffers ( )
inlineprotected

Definition at line 41 of file RotatingBufferHelper.h.

42  {
43  for(size_t i = 0; i < _CurrentDataBufferCount; ++i) {
44  DataBuffers[i] = nullptr;
45  }
46 
47  _CurrentDataBufferCount = 0;
48  _BufferReadCount = 0;
49  }
std::array< BufferT, MaxBuffers > DataBuffers

◆ GetNextDataBuffer()

template<class BufferT, size_t MaxBuffers>
BufferT* Leviathan::RotatingBufferHelper< BufferT, MaxBuffers >::GetNextDataBuffer ( )
inlineprotected
Returns
The next available data buffer or nullptr if all up to MaxBuffers are locked

Definition at line 20 of file RotatingBufferHelper.h.

21  {
22  for(size_t attempt = 0; attempt < _CurrentDataBufferCount; ++attempt) {
23 
24  auto* buffer = &DataBuffers[(_BufferReadCount++) % _CurrentDataBufferCount];
25 
26  if(!(*buffer)->isLocked())
27  return buffer;
28  }
29 
30  // No free buffer
31  if(_CurrentDataBufferCount < MaxBuffers) {
32  // Can create new one
33  DataBuffers[_CurrentDataBufferCount++] = _OnNewBufferNeeded();
34  return &DataBuffers[_CurrentDataBufferCount - 1];
35  }
36 
37  // No buffers available
38  return nullptr;
39  }
std::array< BufferT, MaxBuffers > DataBuffers
virtual BufferT _OnNewBufferNeeded()=0

Member Data Documentation

◆ DataBuffers

template<class BufferT, size_t MaxBuffers>
std::array<BufferT, MaxBuffers> Leviathan::RotatingBufferHelper< BufferT, MaxBuffers >::DataBuffers
protected

Definition at line 54 of file RotatingBufferHelper.h.


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