KiCad PCB EDA Suite
KIGFX::VERTEX_CONTAINER Class Referenceabstract

#include <vertex_container.h>

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

Public Member Functions

virtual ~VERTEX_CONTAINER ()
 
virtual bool IsCached () const =0
 Returns true if the container caches vertex data in RAM or video memory. More...
 
virtual void Map ()
 Function Map() prepares the container for vertices updates. More...
 
virtual void Unmap ()
 Function Unmap() finishes the vertices updates stage. More...
 
virtual void SetItem (VERTEX_ITEM *aItem)=0
 Function SetItem() sets the item in order to modify or finishes its current modifications. More...
 
virtual void FinishItem ()
 Function FinishItem() does the cleaning after adding an item. More...
 
virtual VERTEXAllocate (unsigned int aSize)=0
 Function Allocate() returns allocated space (possibly resizing the used memory chunk or allocating a new chunk if it was not stored before) for the given number of vertices associated with the current item (set by SetItem()). More...
 
virtual void Delete (VERTEX_ITEM *aItem)=0
 Function Delete() erases the selected item. More...
 
virtual void Clear ()=0
 Function Clear() removes all the data stored in the container and restores its original state. More...
 
virtual VERTEXGetAllVertices () const
 Function GetAllVertices() returns all the vertices stored in the container. More...
 
virtual VERTEXGetVertices (unsigned int aOffset) const
 Function GetVertices() returns vertices stored at the specific offset. More...
 
virtual unsigned int GetSize () const
 Function GetSize() returns amount of vertices currently stored in the container. More...
 
bool IsDirty ()
 Function IsDirty() returns information about container cache state. More...
 
void SetDirty ()
 Function SetDirty() sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame. More...
 

Static Public Member Functions

static VERTEX_CONTAINERMakeContainer (bool aCached)
 Function MakeContainer() Returns a pointer to a new container of an appropriate type. More...
 

Protected Member Functions

 VERTEX_CONTAINER (unsigned int aSize=DEFAULT_SIZE)
 How many vertices we can store in the container. More...
 
unsigned int usedSpace () const
 Function usedSpace() returns size of the used memory space. More...
 

Protected Attributes

unsigned int m_freeSpace
 How big is the current container, expressed in vertices. More...
 
unsigned int m_currentSize
 Store the initial size, so it can be resized to this on Clear() More...
 
unsigned int m_initialSize
 Actual storage memory (should be handled using malloc/realloc/free to speed up resizing) More...
 
VERTEXm_vertices
 State flags. More...
 
bool m_failed
 
bool m_dirty
 

Static Protected Attributes

static constexpr unsigned int DEFAULT_SIZE = 1048576
 

Detailed Description

Definition at line 40 of file vertex_container.h.

Constructor & Destructor Documentation

VERTEX_CONTAINER::~VERTEX_CONTAINER ( )
virtual

Definition at line 65 of file vertex_container.cpp.

66 {
67 }
VERTEX_CONTAINER::VERTEX_CONTAINER ( unsigned int  aSize = DEFAULT_SIZE)
protected

How many vertices we can store in the container.

Definition at line 58 of file vertex_container.cpp.

58  :
59  m_freeSpace( aSize ), m_currentSize( aSize ), m_initialSize( aSize ),
60  m_vertices( NULL ), m_failed( false ), m_dirty( true )
61 {
62 }
unsigned int m_initialSize
Actual storage memory (should be handled using malloc/realloc/free to speed up resizing) ...
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
VERTEX * m_vertices
State flags.
unsigned int m_freeSpace
How big is the current container, expressed in vertices.

Member Function Documentation

virtual VERTEX* KIGFX::VERTEX_CONTAINER::Allocate ( unsigned int  aSize)
pure virtual

Function Allocate() returns allocated space (possibly resizing the used memory chunk or allocating a new chunk if it was not stored before) for the given number of vertices associated with the current item (set by SetItem()).

The newly 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 or NULL in case of failure.

Implemented in KIGFX::CACHED_CONTAINER, and KIGFX::NONCACHED_CONTAINER.

virtual void KIGFX::VERTEX_CONTAINER::Clear ( )
pure virtual

Function Clear() removes all the data stored in the container and restores its original state.

Implemented in KIGFX::CACHED_CONTAINER, and KIGFX::NONCACHED_CONTAINER.

virtual void KIGFX::VERTEX_CONTAINER::Delete ( VERTEX_ITEM aItem)
pure virtual

Function Delete() erases the selected item.

Parameters
aItemis the item to be erased.

Implemented in KIGFX::CACHED_CONTAINER, and KIGFX::NONCACHED_CONTAINER.

virtual void KIGFX::VERTEX_CONTAINER::FinishItem ( )
inlinevirtual

Function FinishItem() does the cleaning after adding an item.

Reimplemented in KIGFX::CACHED_CONTAINER.

Definition at line 80 of file vertex_container.h.

80 {};
virtual VERTEX* KIGFX::VERTEX_CONTAINER::GetAllVertices ( ) const
inlinevirtual

Function GetAllVertices() returns all the vertices stored in the container.

It is especially useful for transferring data to the GPU memory.

Definition at line 112 of file vertex_container.h.

References m_vertices.

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

113  {
114  return m_vertices;
115  }
VERTEX * m_vertices
State flags.
virtual unsigned int KIGFX::VERTEX_CONTAINER::GetSize ( ) const
inlinevirtual

Function GetSize() returns amount of vertices currently stored in the container.

Reimplemented in KIGFX::NONCACHED_CONTAINER.

Definition at line 131 of file vertex_container.h.

References m_currentSize.

Referenced by KIGFX::GPU_CACHED_MANAGER::BeginDrawing(), KIGFX::GPU_CACHED_MANAGER::DrawAll(), KIGFX::GPU_NONCACHED_MANAGER::EndDrawing(), and KIGFX::GPU_CACHED_MANAGER::GPU_CACHED_MANAGER().

132  {
133  return m_currentSize;
134  }
unsigned int m_currentSize
Store the initial size, so it can be resized to this on Clear()
virtual VERTEX* KIGFX::VERTEX_CONTAINER::GetVertices ( unsigned int  aOffset) const
inlinevirtual

Function GetVertices() returns vertices stored at the specific offset.

Parameters
aOffsetis the offset.

Definition at line 122 of file vertex_container.h.

References m_vertices.

123  {
124  return &m_vertices[aOffset];
125  }
VERTEX * m_vertices
State flags.
virtual bool KIGFX::VERTEX_CONTAINER::IsCached ( ) const
pure virtual

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

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

Implemented in KIGFX::CACHED_CONTAINER, and KIGFX::NONCACHED_CONTAINER.

Referenced by KIGFX::GPU_MANAGER::MakeManager().

bool KIGFX::VERTEX_CONTAINER::IsDirty ( )
inline

Function IsDirty() returns information about container cache state.

Clears the flag after calling the function.

Returns
true in case the vertices have to be reuploaded.

Definition at line 141 of file vertex_container.h.

References m_dirty.

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

142  {
143  bool state = m_dirty;
144 
145  m_dirty = false;
146 
147  return state;
148  }
VERTEX_CONTAINER * VERTEX_CONTAINER::MakeContainer ( bool  aCached)
static

Function MakeContainer() Returns a pointer to a new container of an appropriate type.

Definition at line 40 of file vertex_container.cpp.

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

41 {
42  if( aCached )
43  {
44  const unsigned char* vendor = glGetString( GL_VENDOR );
45 
46  // AMD/ATI cards do not cope well with GPU memory mapping,
47  // so the vertex data has to be kept in RAM
48  if( strstr( (const char*) vendor, "AMD" ) )
49  return new CACHED_CONTAINER_RAM;
50  else
51  return new CACHED_CONTAINER_GPU;
52  }
53 
54  return new NONCACHED_CONTAINER;
55 }
Specialization of CACHED_CONTAINER that stores data in RAM.
Specialization of CACHED_CONTAINER that stores data in video memory via memory mapping.
virtual void KIGFX::VERTEX_CONTAINER::Map ( )
inlinevirtual

Function Map() prepares the container for vertices updates.

Reimplemented in KIGFX::CACHED_CONTAINER, KIGFX::CACHED_CONTAINER_GPU, and KIGFX::CACHED_CONTAINER_RAM.

Definition at line 61 of file vertex_container.h.

61 {}
void KIGFX::VERTEX_CONTAINER::SetDirty ( )
inline

Function SetDirty() sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame.

Definition at line 155 of file vertex_container.h.

References m_dirty.

156  {
157  m_dirty = true;
158  }
virtual void KIGFX::VERTEX_CONTAINER::SetItem ( VERTEX_ITEM aItem)
pure virtual

Function SetItem() sets the item in order to modify or finishes its current modifications.

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

Implemented in KIGFX::CACHED_CONTAINER, and KIGFX::NONCACHED_CONTAINER.

virtual void KIGFX::VERTEX_CONTAINER::Unmap ( )
inlinevirtual

Function Unmap() finishes the vertices updates stage.

Reimplemented in KIGFX::CACHED_CONTAINER, KIGFX::CACHED_CONTAINER_GPU, and KIGFX::CACHED_CONTAINER_RAM.

Definition at line 67 of file vertex_container.h.

67 {}
unsigned int KIGFX::VERTEX_CONTAINER::usedSpace ( ) const
inlineprotected

Function usedSpace() returns size of the used memory space.

Returns
Size of the used memory space (expressed as a number of vertices).Default initial size of a container (expressed in vertices)

Definition at line 184 of file vertex_container.h.

References m_freeSpace.

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

Member Data Documentation

constexpr unsigned int KIGFX::VERTEX_CONTAINER::DEFAULT_SIZE = 1048576
staticprotected

Definition at line 190 of file vertex_container.h.

bool KIGFX::VERTEX_CONTAINER::m_dirty
protected
bool KIGFX::VERTEX_CONTAINER::m_failed
protected
unsigned int KIGFX::VERTEX_CONTAINER::m_initialSize
protected

Actual storage memory (should be handled using malloc/realloc/free to speed up resizing)

Definition at line 170 of file vertex_container.h.

Referenced by KIGFX::CACHED_CONTAINER::Delete().


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