KiCad PCB EDA Suite
vertex_container.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright 2013-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #ifndef VERTEX_CONTAINER_H_
31 #define VERTEX_CONTAINER_H_
32 
34 
35 namespace KIGFX
36 {
37 class VERTEX_ITEM;
38 class SHADER;
39 
41 {
42 public:
46  static VERTEX_CONTAINER* MakeContainer( bool aCached );
47 
48  virtual ~VERTEX_CONTAINER();
49 
54  virtual bool IsCached() const = 0;
55 
59  virtual void Map() {}
60 
64  virtual void Unmap() {}
65 
70  virtual void SetItem( VERTEX_ITEM* aItem ) = 0;
71 
75  virtual void FinishItem() {};
76 
84  virtual VERTEX* Allocate( unsigned int aSize ) = 0;
85 
90  virtual void Delete( VERTEX_ITEM* aItem ) = 0;
91 
95  virtual void Clear() = 0;
96 
101  {
102  return m_vertices;
103  }
104 
110  virtual VERTEX* GetVertices( unsigned int aOffset ) const
111  {
112  return &m_vertices[aOffset];
113  }
114 
119  virtual unsigned int GetSize() const
120  {
121  return m_currentSize;
122  }
123 
128  bool IsDirty() const
129  {
130  return m_dirty;
131  }
132 
137  void SetDirty()
138  {
139  m_dirty = true;
140  }
141 
145  void ClearDirty()
146  {
147  m_dirty = false;
148  }
149 
150 protected:
151  VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE );
152 
154  unsigned int m_freeSpace;
155 
157  unsigned int m_currentSize;
158 
160  unsigned int m_initialSize;
161 
164 
165  // Status flags
166  bool m_failed;
167  bool m_dirty;
168 
174  unsigned int usedSpace() const
175  {
176  return m_currentSize - m_freeSpace;
177  }
178 
180  static constexpr unsigned int DEFAULT_SIZE = 1048576;
181 };
182 } // namespace KIGFX
183 
184 #endif /* VERTEX_CONTAINER_H_ */
unsigned int usedSpace() const
Function usedSpace() returns size of the used memory space.
unsigned int m_initialSize
Store the initial size, so it can be resized to this on Clear()
static VERTEX_CONTAINER * MakeContainer(bool aCached)
Returns a pointer to a new container of an appropriate type.
virtual void Clear()=0
Removes all data stored in the container and restores its original state.
virtual void Unmap()
Finishes the vertices updates stage.
VERTEX * GetAllVertices() const
Returns pointer to the vertices stored in the container.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
virtual VERTEX * GetVertices(unsigned int aOffset) const
Function GetVertices() returns vertices stored at the specific offset.
Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
Definition: vertex_common.h:50
virtual void Map()
Prepares the container for vertices updates.
virtual bool IsCached() const =0
Returns true if the container caches vertex data in RAM or video memory.
VERTEX_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
unsigned int m_currentSize
Current container size, expressed in vertices
VERTEX * m_vertices
Actual storage memory
virtual void FinishItem()
Clean up after adding an item.
unsigned int m_freeSpace
Free space left in the container, expressed in vertices
bool IsDirty() const
Returns information about the container cache state.
static constexpr unsigned int DEFAULT_SIZE
virtual unsigned int GetSize() const
Function GetSize() returns amount of vertices currently stored in the container.
Common defines and consts used in vertex related classes.
virtual void SetItem(VERTEX_ITEM *aItem)=0
Sets the item for the further actions.
virtual VERTEX * Allocate(unsigned int aSize)=0
Returns allocated space for the requested number of vertices associated with the current item (set wi...
void SetDirty()
Sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next f...
virtual void Delete(VERTEX_ITEM *aItem)=0
Erases the data related to an item.
void ClearDirty()
Clears the dirty flag to prevent reuploading vertices to the GPU memory.