25 #ifndef CACHED_CONTAINER_H_ 26 #define CACHED_CONTAINER_H_ 67 virtual void Clear()
override;
80 virtual void Map()
override = 0;
83 virtual void Unmap()
override = 0;
87 typedef std::pair<unsigned int, unsigned int>
CHUNK;
91 typedef std::set<VERTEX_ITEM*>
ITEMS;
158 return aChunk.second;
164 void addFreeChunk(
unsigned int aOffset,
unsigned int aSize );
void showFreeChunks()
Debug & test functions.
int getChunkSize(const CHUNK &aChunk) const
Returns the size of a chunk.
void addFreeChunk(unsigned int aOffset, unsigned int aSize)
Adds a chunk marked as a free space.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
void defragment(VERTEX *aTarget)
Transfers all stored data to a new buffer, removing empty spaces between the data chunks in the conta...
virtual ~CACHED_CONTAINER()
unsigned int m_chunkSize
Properties of currently modified chunk & item
std::set< VERTEX_ITEM * > ITEMS
List of all the stored items.
virtual void SetItem(VERTEX_ITEM *aItem) override
>
std::multimap< unsigned int, unsigned int > FREE_CHUNK_MAP
virtual unsigned int GetBufferHandle() const =0
Returns handle to the vertex buffer.
ITEMS m_items
Stored VERTEX_ITEMs
VERTEX_ITEM * m_item
Currently modified item
virtual void FinishItem() override
>
Class to store VERTEX instances with caching.
std::pair< unsigned int, unsigned int > CHUNK
Maps size of free memory chunks to their offsets
unsigned int getChunkOffset(const CHUNK &aChunk) const
Returns the offset of a chunk.
bool IsCached() const override
Returns true if the container caches vertex data in RAM or video memory.
static constexpr unsigned int DEFAULT_SIZE
void mergeFreeChunks()
Looks for consecutive free memory chunks and merges them, decreasing fragmentation of memory...
virtual void Clear() override
>
Class to store vertices and handle transfers between system memory and GPU memory.
virtual VERTEX * Allocate(unsigned int aSize) override
>
FREE_CHUNK_MAP m_freeChunks
Stores size & offset of free chunks.
CACHED_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
bool reallocate(unsigned int aSize)
Resizes the chunk that stores the current item to the given size.
virtual void Map() override=0
>
unsigned int m_maxIndex
Maximal vertex index number stored in the container
virtual bool IsMapped() const =0
Returns true if vertex buffer is currently mapped.
unsigned int m_chunkOffset
virtual void Delete(VERTEX_ITEM *aItem) override
>
virtual void Unmap() override=0
>
virtual bool defragmentResize(unsigned int aNewSize)=0
Removes empty spaces between chunks and optionally resizes the container.