KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KIGFX::CACHED_CONTAINER_RAM Class Reference

Specialization of CACHED_CONTAINER that stores data in RAM. More...

#include <cached_container_ram.h>

Inheritance diagram for KIGFX::CACHED_CONTAINER_RAM:
KIGFX::CACHED_CONTAINER KIGFX::VERTEX_CONTAINER

Public Member Functions

 CACHED_CONTAINER_RAM (unsigned int aSize=DEFAULT_SIZE)
 
 ~CACHED_CONTAINER_RAM ()
 
void Map () override
 Finish the vertices updates stage.
 
void Unmap () override
 Finish the vertices updates stage.
 
bool IsMapped () const override
 Return true if vertex buffer is currently mapped.
 
unsigned int GetBufferHandle () const override
 Return handle to the vertex buffer.
 
bool IsCached () const override
 Return true if the container caches vertex data in RAM or video memory.
 
virtual void SetItem (VERTEX_ITEM *aItem) override
 Set the item for the further actions.
 
virtual void FinishItem () override
 Clean up after adding an item.
 
virtual VERTEX * Allocate (unsigned int aSize) override
 Return allocated space for the requested number of vertices associated with the current item (set with SetItem()).
 
virtual void Delete (VERTEX_ITEM *aItem) override
 Erase the data related to an item.
 
virtual void Clear () override
 Remove all data stored in the container and restores its original state.
 
virtual unsigned int AllItemsSize () const
 
virtual void Abandon ()
 Give up ownership of any GL objects without deleting them.
 
VERTEX * GetAllVertices () const
 Return pointer to the vertices stored in the container.
 
virtual VERTEX * GetVertices (unsigned int aOffset) const
 Return vertices stored at the specific offset.
 
virtual unsigned int GetSize () const
 Return amount of vertices currently stored in the container.
 
bool IsDirty () const
 Return information about the container cache state.
 
void SetDirty ()
 Set the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame.
 
void ClearDirty ()
 Clear the dirty flag to prevent reuploading vertices to the GPU memory.
 

Static Public Member Functions

static VERTEX_CONTAINER * MakeContainer (bool aCached)
 Return a pointer to a new container of an appropriate type.
 

Protected Types

typedef std::pair< unsigned int, unsigned int > CHUNK
 Maps size of free memory chunks to their offsets.
 
typedef std::multimap< unsigned int, unsigned int > FREE_CHUNK_MAP
 

Protected Member Functions

bool defragmentResize (unsigned int aNewSize) override
 Defragment the currently stored data and resizes the buffer.
 
bool reallocate (unsigned int aSize)
 Resize the chunk that stores the current item to the given size.
 
void defragment (VERTEX *aTarget)
 Transfer all stored data to a new buffer, removing empty spaces between the data chunks in the container.
 
void mergeFreeChunks ()
 Look for consecutive free memory chunks and merges them, decreasing fragmentation of memory.
 
int getChunkSize (const CHUNK &aChunk) const
 Return the size of a chunk.
 
unsigned int getChunkOffset (const CHUNK &aChunk) const
 Return the offset of a chunk.
 
void addFreeChunk (unsigned int aOffset, unsigned int aSize)
 Add a chunk marked as a free space.
 
unsigned int usedSpace () const
 Return size of the used memory space.
 

Protected Attributes

GLuint m_verticesBuffer
 Handle to vertices buffer.
 
FREE_CHUNK_MAP m_freeChunks
 Store size & offset of free chunks.
 
std::set< VERTEX_ITEM * > m_items
 Stored VERTEX_ITEMs.
 
VERTEX_ITEM * m_item
 Currently modified item.
 
unsigned int m_chunkSize
 Properties of currently modified chunk & item.
 
unsigned int m_chunkOffset
 
unsigned int m_maxIndex
 Maximal vertex index number stored in the container.
 
unsigned int m_freeSpace
 Free space left in the container, expressed in vertices.
 
unsigned int m_currentSize
 Current container size, expressed in vertices.
 
unsigned int m_initialSize
 Store the initial size, so it can be resized to this on Clear()
 
VERTEX * m_vertices
 Actual storage memory.
 
bool m_failed
 
bool m_dirty
 

Static Protected Attributes

static constexpr unsigned int DEFAULT_SIZE = 1048576
 Default initial size of a container (expressed in vertices)
 

Private Member Functions

void showFreeChunks ()
 Debug & test functions.
 
void showUsedChunks ()
 
void test ()
 

Detailed Description

Specialization of CACHED_CONTAINER that stores data in RAM.

This is mainly for video cards/drivers that do not cope well with video memory mapping.

Definition at line 41 of file cached_container_ram.h.

Member Typedef Documentation

◆ CHUNK

typedef std::pair<unsigned int, unsigned int> KIGFX::CACHED_CONTAINER::CHUNK
protectedinherited

Maps size of free memory chunks to their offsets.

Definition at line 97 of file cached_container.h.

◆ FREE_CHUNK_MAP

typedef std::multimap<unsigned int, unsigned int> KIGFX::CACHED_CONTAINER::FREE_CHUNK_MAP
protectedinherited

Definition at line 98 of file cached_container.h.

Constructor & Destructor Documentation

◆ CACHED_CONTAINER_RAM()

CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM ( unsigned int aSize = DEFAULT_SIZE)

◆ ~CACHED_CONTAINER_RAM()

CACHED_CONTAINER_RAM::~CACHED_CONTAINER_RAM ( )

Member Function Documentation

◆ Abandon()

virtual void KIGFX::VERTEX_CONTAINER::Abandon ( )
inlinevirtualinherited

Give up ownership of any GL objects without deleting them.

Used when the owning context can no longer be made current, so a delete would be executed against whichever context is, possibly one from another share group. The names are released when the owning context is destroyed.

Reimplemented in KIGFX::CACHED_CONTAINER_GPU.

Definition at line 61 of file vertex_container.h.

◆ addFreeChunk()

void CACHED_CONTAINER::addFreeChunk ( unsigned int aOffset,
unsigned int aSize )
protectedinherited

Add a chunk marked as a free space.

Definition at line 403 of file cached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_currentSize, m_freeChunks, and KIGFX::VERTEX_CONTAINER::m_freeSpace.

Referenced by Delete(), FinishItem(), and reallocate().

◆ AllItemsSize()

virtual unsigned int KIGFX::CACHED_CONTAINER::AllItemsSize ( ) const
inlinevirtualinherited

Reimplemented in KIGFX::CACHED_CONTAINER_GPU.

Definition at line 93 of file cached_container.h.

Referenced by KIGFX::GPU_CACHED_MANAGER::EndDrawing().

◆ Allocate()

VERTEX * CACHED_CONTAINER::Allocate ( unsigned int aSize)
overridevirtualinherited

Return allocated space for the requested number of vertices associated with the current item (set with SetItem()).

The allocated space is added at the end of the chunk used by the current item and may serve to store new vertices.

Parameters
aSizeis the number of vertices to be allocated.
Returns
Pointer to the allocated space.
Exceptions
bad_allocexception if allocation fails.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 108 of file cached_container.cpp.

References IsMapped(), m_chunkOffset, m_chunkSize, KIGFX::VERTEX_CONTAINER::m_dirty, KIGFX::VERTEX_CONTAINER::m_failed, m_item, KIGFX::VERTEX_CONTAINER::m_vertices, reallocate(), showFreeChunks(), showUsedChunks(), and test().

◆ Clear()

void CACHED_CONTAINER::Clear ( )
overridevirtualinherited

Remove all data stored in the container and restores its original state.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 198 of file cached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_currentSize, KIGFX::VERTEX_CONTAINER::m_failed, m_freeChunks, KIGFX::VERTEX_CONTAINER::m_freeSpace, m_items, and m_maxIndex.

◆ ClearDirty()

void KIGFX::VERTEX_CONTAINER::ClearDirty ( )
inlineinherited

Clear the dirty flag to prevent reuploading vertices to the GPU memory.

Definition at line 157 of file vertex_container.h.

References m_dirty.

Referenced by KIGFX::GPU_CACHED_MANAGER::EndDrawing().

◆ defragment()

void CACHED_CONTAINER::defragment ( VERTEX * aTarget)
protectedinherited

Transfer all stored data to a new buffer, removing empty spaces between the data chunks in the container.

Parameters
aTargetis the destination for the defragmented data.

Definition at line 288 of file cached_container.cpp.

References m_chunkOffset, m_item, m_items, m_maxIndex, KIGFX::VERTEX_CONTAINER::m_vertices, KIGFX::VERTEX_CONTAINER::usedSpace(), and KIGFX::VERTEX_SIZE.

Referenced by KIGFX::CACHED_CONTAINER_RAM::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), and KIGFX::CACHED_CONTAINER_GPU::defragmentResizeStaged().

◆ defragmentResize()

bool CACHED_CONTAINER_RAM::defragmentResize ( unsigned int aNewSize)
overrideprotectedvirtual

Defragment the currently stored data and resizes the buffer.

Parameters
aNewSizeis the new buffer vertex buffer size, expressed as the number of vertices.
Returns
true on success.

Implements KIGFX::CACHED_CONTAINER.

Definition at line 89 of file cached_container_ram.cpp.

References KIGFX::CACHED_CONTAINER::defragment(), KIGFX::VERTEX_CONTAINER::m_currentSize, KIGFX::VERTEX_CONTAINER::m_dirty, KIGFX::CACHED_CONTAINER::m_freeChunks, KIGFX::VERTEX_CONTAINER::m_freeSpace, KIGFX::VERTEX_CONTAINER::m_vertices, PROF_TIMER::msecs(), PROF_TIMER::Stop(), traceGalCachedContainer, KIGFX::VERTEX_CONTAINER::usedSpace(), and KIGFX::VERTEX_SIZE.

◆ Delete()

void CACHED_CONTAINER::Delete ( VERTEX_ITEM * aItem)
overridevirtualinherited

◆ FinishItem()

void CACHED_CONTAINER::FinishItem ( )
overridevirtualinherited

Clean up after adding an item.

Reimplemented from KIGFX::VERTEX_CONTAINER.

Definition at line 75 of file cached_container.cpp.

References addFreeChunk(), m_chunkOffset, m_chunkSize, m_item, m_items, m_maxIndex, and test().

◆ GetAllVertices()

VERTEX * KIGFX::VERTEX_CONTAINER::GetAllVertices ( ) const
inlineinherited

Return pointer to the vertices stored in the container.

Definition at line 112 of file vertex_container.h.

References m_vertices.

◆ GetBufferHandle()

unsigned int KIGFX::CACHED_CONTAINER_RAM::GetBufferHandle ( ) const
inlineoverridevirtual

Return handle to the vertex buffer.

It might be negative if the buffer is not initialized.

Implements KIGFX::CACHED_CONTAINER.

Definition at line 63 of file cached_container_ram.h.

References m_verticesBuffer.

◆ getChunkOffset()

unsigned int KIGFX::CACHED_CONTAINER::getChunkOffset ( const CHUNK & aChunk) const
inlineprotectedinherited

Return the offset of a chunk.

Parameters
aChunkis the chunk.

Definition at line 150 of file cached_container.h.

Referenced by reallocate().

◆ getChunkSize()

int KIGFX::CACHED_CONTAINER::getChunkSize ( const CHUNK & aChunk) const
inlineprotectedinherited

Return the size of a chunk.

Parameters
aChunkis the chunk.

Definition at line 140 of file cached_container.h.

Referenced by reallocate(), and test().

◆ GetSize()

virtual unsigned int KIGFX::VERTEX_CONTAINER::GetSize ( ) const
inlinevirtualinherited

Return amount of vertices currently stored in the container.

Reimplemented in KIGFX::NONCACHED_CONTAINER.

Definition at line 130 of file vertex_container.h.

References m_currentSize.

◆ GetVertices()

virtual VERTEX * KIGFX::VERTEX_CONTAINER::GetVertices ( unsigned int aOffset) const
inlinevirtualinherited

Return vertices stored at the specific offset.

Parameters
aOffsetis the offset.

Definition at line 122 of file vertex_container.h.

References m_vertices.

◆ IsCached()

bool KIGFX::CACHED_CONTAINER::IsCached ( ) const
inlineoverridevirtualinherited

Return true if the container caches vertex data in RAM or video memory.

Otherwise it is a single batch draw which is later discarded.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 48 of file cached_container.h.

◆ IsDirty()

bool KIGFX::VERTEX_CONTAINER::IsDirty ( ) const
inlineinherited

Return information about the container cache state.

Returns
True in case the vertices have to be reuploaded.

Definition at line 140 of file vertex_container.h.

References m_dirty.

◆ IsMapped()

bool KIGFX::CACHED_CONTAINER_RAM::IsMapped ( ) const
inlineoverridevirtual

Return true if vertex buffer is currently mapped.

Implements KIGFX::CACHED_CONTAINER.

Definition at line 53 of file cached_container_ram.h.

◆ MakeContainer()

VERTEX_CONTAINER * VERTEX_CONTAINER::MakeContainer ( bool aCached)
staticinherited

Return a pointer to a new container of an appropriate type.

Definition at line 38 of file vertex_container.cpp.

References VERTEX_CONTAINER().

Referenced by KIGFX::VERTEX_MANAGER::VERTEX_MANAGER().

◆ Map()

void KIGFX::CACHED_CONTAINER_RAM::Map ( )
inlineoverridevirtual

Finish the vertices updates stage.

Implements KIGFX::CACHED_CONTAINER.

Definition at line 48 of file cached_container_ram.h.

◆ mergeFreeChunks()

void CACHED_CONTAINER::mergeFreeChunks ( )
protectedinherited

Look for consecutive free memory chunks and merges them, decreasing fragmentation of memory.

Definition at line 348 of file cached_container.cpp.

References m_freeChunks, and test().

◆ reallocate()

bool CACHED_CONTAINER::reallocate ( unsigned int aSize)
protectedinherited

Resize the chunk that stores the current item to the given size.

The current item has its offset adjusted after the call, and the new chunk parameters are stored in m_chunkOffset and m_chunkSize.

Parameters
aSizeis the requested chunk size.
Returns
true in case of success, false otherwise.

Definition at line 217 of file cached_container.cpp.

References addFreeChunk(), defragmentResize(), getChunkOffset(), getChunkSize(), IsMapped(), m_chunkOffset, m_chunkSize, KIGFX::VERTEX_CONTAINER::m_currentSize, m_freeChunks, KIGFX::VERTEX_CONTAINER::m_freeSpace, m_item, KIGFX::VERTEX_CONTAINER::m_vertices, result, and KIGFX::VERTEX_SIZE.

Referenced by Allocate().

◆ SetDirty()

void KIGFX::VERTEX_CONTAINER::SetDirty ( )
inlineinherited

Set the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame.

Definition at line 149 of file vertex_container.h.

References m_dirty.

◆ SetItem()

void CACHED_CONTAINER::SetItem ( VERTEX_ITEM * aItem)
overridevirtualinherited

Set the item for the further actions.

Parameters
aItemis the item or NULL in case of finishing the item.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 62 of file cached_container.cpp.

References KIGFX::VERTEX_ITEM::GetOffset(), KIGFX::VERTEX_ITEM::GetSize(), m_chunkOffset, m_chunkSize, and m_item.

◆ showFreeChunks()

void CACHED_CONTAINER::showFreeChunks ( )
privateinherited

Debug & test functions.

Definition at line 413 of file cached_container.cpp.

Referenced by Allocate().

◆ showUsedChunks()

void CACHED_CONTAINER::showUsedChunks ( )
privateinherited

Definition at line 418 of file cached_container.cpp.

Referenced by Allocate().

◆ test()

void CACHED_CONTAINER::test ( )
privateinherited

◆ Unmap()

void CACHED_CONTAINER_RAM::Unmap ( )
overridevirtual

◆ usedSpace()

unsigned int KIGFX::VERTEX_CONTAINER::usedSpace ( ) const
inlineprotectedinherited

Return size of the used memory space.

Returns
Size of the used memory space (expressed as a number of vertices).

Definition at line 170 of file vertex_container.h.

References m_currentSize, and m_freeSpace.

Referenced by KIGFX::CACHED_CONTAINER::defragment(), KIGFX::CACHED_CONTAINER_GPU::defragmentResize(), KIGFX::CACHED_CONTAINER_RAM::defragmentResize(), KIGFX::CACHED_CONTAINER_GPU::defragmentResizeMemcpy(), and KIGFX::CACHED_CONTAINER_GPU::defragmentResizeStaged().

Member Data Documentation

◆ DEFAULT_SIZE

unsigned int KIGFX::VERTEX_CONTAINER::DEFAULT_SIZE = 1048576
staticconstexprprotectedinherited

Default initial size of a container (expressed in vertices)

Definition at line 192 of file vertex_container.h.

◆ m_chunkOffset

unsigned int KIGFX::CACHED_CONTAINER::m_chunkOffset
protectedinherited

◆ m_chunkSize

unsigned int KIGFX::CACHED_CONTAINER::m_chunkSize
protectedinherited

Properties of currently modified chunk & item.

Definition at line 166 of file cached_container.h.

Referenced by Allocate(), CACHED_CONTAINER(), FinishItem(), reallocate(), SetItem(), and test().

◆ m_currentSize

◆ m_dirty

◆ m_failed

bool KIGFX::VERTEX_CONTAINER::m_failed
protectedinherited

◆ m_freeChunks

◆ m_freeSpace

◆ m_initialSize

unsigned int KIGFX::VERTEX_CONTAINER::m_initialSize
protectedinherited

Store the initial size, so it can be resized to this on Clear()

Definition at line 182 of file vertex_container.h.

Referenced by KIGFX::CACHED_CONTAINER::Delete(), and VERTEX_CONTAINER().

◆ m_item

VERTEX_ITEM* KIGFX::CACHED_CONTAINER::m_item
protectedinherited

◆ m_items

std::set<VERTEX_ITEM*> KIGFX::CACHED_CONTAINER::m_items
protectedinherited

◆ m_maxIndex

unsigned int KIGFX::CACHED_CONTAINER::m_maxIndex
protectedinherited

Maximal vertex index number stored in the container.

Definition at line 170 of file cached_container.h.

Referenced by CACHED_CONTAINER(), Clear(), defragment(), FinishItem(), and KIGFX::CACHED_CONTAINER_RAM::Unmap().

◆ m_vertices

◆ m_verticesBuffer

GLuint KIGFX::CACHED_CONTAINER_RAM::m_verticesBuffer
protected

Handle to vertices buffer.

Definition at line 78 of file cached_container_ram.h.

Referenced by CACHED_CONTAINER_RAM(), GetBufferHandle(), Unmap(), and ~CACHED_CONTAINER_RAM().


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