KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
27
28#ifndef VERTEX_CONTAINER_H_
29#define VERTEX_CONTAINER_H_
30
31#include <gal/gal.h>
33
34namespace KIGFX
35{
36class VERTEX_ITEM;
37class SHADER;
38
40{
41public:
45 static VERTEX_CONTAINER* MakeContainer( bool aCached );
46
47 virtual ~VERTEX_CONTAINER();
48
53 virtual bool IsCached() const = 0;
54
62 virtual void Abandon() {}
63
67 virtual void Map() {}
68
72 virtual void Unmap() {}
73
79 virtual void SetItem( VERTEX_ITEM* aItem ) = 0;
80
84 virtual void FinishItem() {};
85
96 virtual VERTEX* Allocate( unsigned int aSize ) = 0;
97
103 virtual void Delete( VERTEX_ITEM* aItem ) = 0;
104
108 virtual void Clear() = 0;
109
114 {
115 return m_vertices;
116 }
117
123 virtual VERTEX* GetVertices( unsigned int aOffset ) const
124 {
125 return &m_vertices[aOffset];
126 }
127
131 virtual unsigned int GetSize() const
132 {
133 return m_currentSize;
134 }
135
141 bool IsDirty() const
142 {
143 return m_dirty;
144 }
145
150 void SetDirty()
151 {
152 m_dirty = true;
153 }
154
159 {
160 m_dirty = false;
161 }
162
163protected:
164 VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE );
165
171 unsigned int usedSpace() const
172 {
173 return m_currentSize - m_freeSpace;
174 }
175
177 unsigned int m_freeSpace;
178
180 unsigned int m_currentSize;
181
183 unsigned int m_initialSize;
184
187
188 // Status flags
191
193 static constexpr unsigned int DEFAULT_SIZE = 1048576;
194};
195} // namespace KIGFX
196
197#endif /* VERTEX_CONTAINER_H_ */
Provide the access to the OpenGL shaders.
Definition shader.h:73
unsigned int m_initialSize
Store the initial size, so it can be resized to this on Clear()
VERTEX * m_vertices
Actual storage memory.
static constexpr unsigned int DEFAULT_SIZE
Default initial size of a container (expressed in vertices)
virtual VERTEX * Allocate(unsigned int aSize)=0
Return allocated space for the requested number of vertices associated with the current item (set wit...
unsigned int m_currentSize
Current container size, expressed in vertices.
unsigned int m_freeSpace
Free space left in the container, expressed in vertices.
unsigned int usedSpace() const
Return size of the used memory space.
VERTEX_CONTAINER(unsigned int aSize=DEFAULT_SIZE)
void SetDirty()
Set the dirty flag, so vertices in the container are going to be reuploaded to the GPU on the next fr...
virtual void SetItem(VERTEX_ITEM *aItem)=0
Set the item for the further actions.
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.
virtual void FinishItem()
Clean up after adding an item.
virtual void Clear()=0
Remove all data stored in the container and restores its original state.
VERTEX * GetAllVertices() const
Return pointer to the vertices stored in the container.
virtual void Delete(VERTEX_ITEM *aItem)=0
Erase the data related to an item.
virtual void Unmap()
Finish the vertices updates stage.
virtual bool IsCached() const =0
Return true if the container caches vertex data in RAM or video memory.
virtual void Abandon()
Give up ownership of any GL objects without deleting them.
static VERTEX_CONTAINER * MakeContainer(bool aCached)
Return a pointer to a new container of an appropriate type.
void ClearDirty()
Clear the dirty flag to prevent reuploading vertices to the GPU memory.
bool IsDirty() const
Return information about the container cache state.
virtual void Map()
Prepare the container for vertices updates.
#define GAL_API
Definition gal.h:27
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
Common defines and consts used in vertex related classes.