23#ifndef CACHED_CONTAINER_H_
24#define CACHED_CONTAINER_H_
54 virtual void SetItem(
VERTEX_ITEM* aItem )
override;
57 virtual void FinishItem()
override;
70 virtual VERTEX* Allocate(
unsigned int aSize )
override;
76 virtual void Clear()
override;
89 virtual void Map()
override = 0;
92 virtual void Unmap()
override = 0;
98 typedef std::pair<unsigned int, unsigned int>
CHUNK;
153 return aChunk.second;
159 void addFreeChunk(
unsigned int aOffset,
unsigned int aSize );
unsigned int m_chunkOffset
int getChunkSize(const CHUNK &aChunk) const
Return the size of a chunk.
std::set< VERTEX_ITEM * > m_items
Stored VERTEX_ITEMs.
void mergeFreeChunks()
Look for consecutive free memory chunks and merges them, decreasing fragmentation of memory.
void showFreeChunks()
Debug & test functions.
VERTEX_ITEM * m_item
Currently modified item.
FREE_CHUNK_MAP m_freeChunks
Store size & offset of free chunks.
std::multimap< unsigned int, unsigned int > FREE_CHUNK_MAP
void defragment(VERTEX *aTarget)
Transfer all stored data to a new buffer, removing empty spaces between the data chunks in the contai...
unsigned int m_maxIndex
Maximal vertex index number stored in the container.
virtual unsigned int GetBufferHandle() const =0
Return handle to the vertex buffer.
std::pair< unsigned int, unsigned int > CHUNK
Maps size of free memory chunks to their offsets.
unsigned int getChunkOffset(const CHUNK &aChunk) const
Return the offset of a chunk.
virtual unsigned int AllItemsSize() const
unsigned int m_chunkSize
Properties of currently modified chunk & item.
virtual bool defragmentResize(unsigned int aNewSize)=0
Remove empty spaces between chunks and optionally resizes the container.
bool IsCached() const override
Return true if the container caches vertex data in RAM or video memory.
CACHED_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
virtual bool IsMapped() const =0
Return true if vertex buffer is currently mapped.
virtual ~CACHED_CONTAINER()
virtual void Unmap() override=0
Finish the vertices updates stage.
virtual void Map() override=0
Prepare the container for vertices updates.
bool reallocate(unsigned int aSize)
Resize the chunk that stores the current item to the given size.
Provide the access to the OpenGL shaders.
static constexpr unsigned int DEFAULT_SIZE
Default initial size of a container (expressed in vertices)
VERTEX_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
The Cairo implementation of the graphics abstraction layer.
Class to store vertices and handle transfers between system memory and GPU memory.