KiCad PCB EDA Suite
KIGFX::NONCACHED_CONTAINER Class Reference

#include <noncached_container.h>

Inheritance diagram for KIGFX::NONCACHED_CONTAINER:
KIGFX::VERTEX_CONTAINER

Public Member Functions

 NONCACHED_CONTAINER (unsigned int aSize=DEFAULT_SIZE)
 
virtual ~NONCACHED_CONTAINER ()
 
bool IsCached () const override
 Returns true if the container caches vertex data in RAM or video memory. More...
 
virtual void SetItem (VERTEX_ITEM *aItem) override
 Sets the item for the further actions. More...
 
virtual VERTEXAllocate (unsigned int aSize) override
 Returns allocated space for the requested number of vertices associated with the current item (set with SetItem()). More...
 
void Delete (VERTEX_ITEM *aItem) override
 Erases the data related to an item. More...
 
virtual void Clear () override
 Removes all data stored in the container and restores its original state. More...
 
virtual unsigned int GetSize () const override
 Function GetSize() returns amount of vertices currently stored in the container. More...
 
virtual void Map ()
 Prepares the container for vertices updates. More...
 
virtual void Unmap ()
 Finishes the vertices updates stage. More...
 
virtual void FinishItem ()
 Clean up after adding an item. More...
 
VERTEXGetAllVertices () const
 Returns pointer to the vertices stored in the container. More...
 
virtual VERTEXGetVertices (unsigned int aOffset) const
 Function GetVertices() returns vertices stored at the specific offset. More...
 
bool IsDirty () const
 Returns information about the container cache state. More...
 
void SetDirty ()
 Sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next frame. More...
 
void ClearDirty ()
 Clears the dirty flag to prevent reuploading vertices to the GPU memory. More...
 

Static Public Member Functions

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

Protected Member Functions

unsigned int usedSpace () const
 Function usedSpace() returns size of the used memory space. More...
 

Protected Attributes

unsigned int m_freePtr
 < Index of the free first space where a vertex can be stored More...
 
unsigned int m_freeSpace
 

Free space left in the container, expressed in vertices

More...
 
unsigned int m_currentSize
 

Current container size, expressed in vertices

More...
 
unsigned int m_initialSize
 

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

More...
 
VERTEXm_vertices
 

Actual storage memory

More...
 
bool m_failed
 
bool m_dirty
 

Static Protected Attributes

static constexpr unsigned int DEFAULT_SIZE = 1048576
 

Detailed Description

Definition at line 41 of file noncached_container.h.

Constructor & Destructor Documentation

NONCACHED_CONTAINER::NONCACHED_CONTAINER ( unsigned int  aSize = DEFAULT_SIZE)

Definition at line 37 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_vertices.

37  :
38  VERTEX_CONTAINER( aSize ), m_freePtr( 0 )
39 {
40  m_vertices = static_cast<VERTEX*>( malloc( aSize * sizeof( VERTEX ) ) );
41  memset( m_vertices, 0x00, aSize * sizeof( VERTEX ) );
42 }
Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
Definition: vertex_common.h:50
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
VERTEX_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
VERTEX * m_vertices
Actual storage memory
NONCACHED_CONTAINER::~NONCACHED_CONTAINER ( )
virtual

Definition at line 45 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_vertices.

46 {
47  free( m_vertices );
48 }
VERTEX * m_vertices
Actual storage memory

Member Function Documentation

VERTEX * NONCACHED_CONTAINER::Allocate ( unsigned int  aSize)
overridevirtual

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

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 58 of file noncached_container.cpp.

References KIGFX::VERTEX_CONTAINER::m_currentSize, m_freePtr, KIGFX::VERTEX_CONTAINER::m_freeSpace, and KIGFX::VERTEX_CONTAINER::m_vertices.

59 {
60  if( m_freeSpace < aSize )
61  {
62  // Double the space
63  VERTEX* newVertices = static_cast<VERTEX*>( realloc( m_vertices,
64  m_currentSize * 2 *
65  sizeof(VERTEX) ) );
66 
67  if( newVertices != NULL )
68  {
69  m_vertices = newVertices;
71  m_currentSize *= 2;
72  }
73  else
74  {
75  return NULL;
76  }
77  }
78 
79  VERTEX* freeVertex = &m_vertices[m_freePtr];
80 
81  // Move to the next free chunk
82  m_freePtr += aSize;
83  m_freeSpace -= aSize;
84 
85  return freeVertex;
86 }
Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
Definition: vertex_common.h:50
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
unsigned int m_currentSize
Current container size, expressed in vertices
VERTEX * m_vertices
Actual storage memory
unsigned int m_freeSpace
Free space left in the container, expressed in vertices
void NONCACHED_CONTAINER::Clear ( )
overridevirtual

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

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 89 of file noncached_container.cpp.

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

90 {
91  m_freePtr = 0;
93 }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
unsigned int m_currentSize
Current container size, expressed in vertices
unsigned int m_freeSpace
Free space left in the container, expressed in vertices
void KIGFX::VERTEX_CONTAINER::ClearDirty ( )
inlineinherited

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

Definition at line 145 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_dirty.

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

146  {
147  m_dirty = false;
148  }
void KIGFX::NONCACHED_CONTAINER::Delete ( VERTEX_ITEM aItem)
inlineoverridevirtual

Erases the data related to an item.

Parameters
aItemis the item to be erased.

Implements KIGFX::VERTEX_CONTAINER.

Definition at line 59 of file noncached_container.h.

59 {}
virtual void KIGFX::VERTEX_CONTAINER::FinishItem ( )
inlinevirtualinherited

Clean up after adding an item.

Reimplemented in KIGFX::CACHED_CONTAINER.

Definition at line 75 of file vertex_container.h.

75 {};
VERTEX* KIGFX::VERTEX_CONTAINER::GetAllVertices ( ) const
inlineinherited

Returns pointer to the vertices stored in the container.

Definition at line 100 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_vertices.

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

101  {
102  return m_vertices;
103  }
VERTEX * m_vertices
Actual storage memory
virtual unsigned int KIGFX::NONCACHED_CONTAINER::GetSize ( ) const
inlineoverridevirtual

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

Reimplemented from KIGFX::VERTEX_CONTAINER.

Definition at line 65 of file noncached_container.h.

References m_freePtr.

66  {
67  // As the m_freePtr points to the first free space, we can safely assume
68  // that this is the number of vertices stored inside
69  return m_freePtr;
70  }
unsigned int m_freePtr
< Index of the free first space where a vertex can be stored
virtual VERTEX* KIGFX::VERTEX_CONTAINER::GetVertices ( unsigned int  aOffset) const
inlinevirtualinherited

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

Parameters
aOffsetis the offset.

Definition at line 110 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_vertices.

111  {
112  return &m_vertices[aOffset];
113  }
VERTEX * m_vertices
Actual storage memory
bool KIGFX::NONCACHED_CONTAINER::IsCached ( ) const
inlineoverridevirtual

Returns 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 47 of file noncached_container.h.

48  {
49  return false;
50  }
bool KIGFX::VERTEX_CONTAINER::IsDirty ( ) const
inlineinherited

Returns information about the container cache state.

Returns
True in case the vertices have to be reuploaded.

Definition at line 128 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_dirty.

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

129  {
130  return m_dirty;
131  }
VERTEX_CONTAINER * VERTEX_CONTAINER::MakeContainer ( bool  aCached)
staticinherited

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 char* vendor = (const char*) glGetString( GL_VENDOR );
45 
46  // Open source drivers do not cope well with GPU memory mapping,
47  // so the vertex data has to be kept in RAM
48  if( strstr( vendor, "X.Org" ) || strstr( vendor, "nouveau" ) )
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 ( )
inlinevirtualinherited

Prepares the container for vertices updates.

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

Definition at line 59 of file vertex_container.h.

59 {}
void KIGFX::VERTEX_CONTAINER::SetDirty ( )
inlineinherited

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

Definition at line 137 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_dirty.

138  {
139  m_dirty = true;
140  }
void NONCACHED_CONTAINER::SetItem ( VERTEX_ITEM aItem)
overridevirtual

Sets 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 51 of file noncached_container.cpp.

52 {
53  // Nothing has to be done, as the noncached container
54  // does not care about VERTEX_ITEMs ownership
55 }
virtual void KIGFX::VERTEX_CONTAINER::Unmap ( )
inlinevirtualinherited

Finishes the vertices updates stage.

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

Definition at line 64 of file vertex_container.h.

64 {}
unsigned int KIGFX::VERTEX_CONTAINER::usedSpace ( ) const
inlineprotectedinherited

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 174 of file vertex_container.h.

References KIGFX::VERTEX_CONTAINER::m_freeSpace.

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

Member Data Documentation

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

Definition at line 180 of file vertex_container.h.

bool KIGFX::VERTEX_CONTAINER::m_failed
protectedinherited
unsigned int KIGFX::NONCACHED_CONTAINER::m_freePtr
protected

< Index of the free first space where a vertex can be stored

Definition at line 74 of file noncached_container.h.

Referenced by Allocate(), Clear(), and GetSize().

unsigned int KIGFX::VERTEX_CONTAINER::m_initialSize
protectedinherited

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

Definition at line 160 of file vertex_container.h.

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


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