KiCad PCB EDA Suite
gpu_manager.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 (C) 2013 CERN
5 * Copyright (C) 2020-2021 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, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef GPU_MANAGER_H_
28#define GPU_MANAGER_H_
29
30#include <vector>
32#include <boost/scoped_array.hpp>
33
34namespace KIGFX
35{
36class SHADER;
37class VERTEX_CONTAINER;
38class VERTEX_ITEM;
39class CACHED_CONTAINER;
40class NONCACHED_CONTAINER;
41
46{
47public:
48 static GPU_MANAGER* MakeManager( VERTEX_CONTAINER* aContainer );
49
50 virtual ~GPU_MANAGER();
51
55 virtual void BeginDrawing() = 0;
56
63 virtual void DrawIndices( const VERTEX_ITEM* aItem ) = 0;
64
68 virtual void EndDrawing() = 0;
69
75 virtual void SetShader( SHADER& aShader );
76
80 void EnableDepthTest( bool aEnabled );
81
82protected:
83 GPU_MANAGER( VERTEX_CONTAINER* aContainer );
84
87
90
93
96
99};
100
101
103{
104public:
105
106 struct VRANGE
107 {
108 VRANGE( int aStart, int aEnd, bool aContinuous ) :
109 m_start( aStart ),
110 m_end( aEnd ),
111 m_isContinuous ( aContinuous )
112 {}
113 unsigned int m_start, m_end;
115 };
116
117
120
122 virtual void BeginDrawing() override;
123
125 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
126
128 virtual void EndDrawing() override;
129
131 void Map();
132
134 void Unmap();
135
136protected:
138 void resizeIndices( unsigned int aNewSize );
139
142
144 boost::scoped_array<GLuint> m_indices;
145
147 unsigned int m_indicesCapacity;
148
150 std::vector<VRANGE> m_vranges;
151
154
157
159 unsigned int m_indexBufSize;
160
162 unsigned int m_indexBufMaxSize;
163
165 unsigned int m_curVrangeSize;
166};
167
168
170{
171public:
173
175 virtual void BeginDrawing() override;
176
178 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
179
181 virtual void EndDrawing() override;
182};
183} // namespace KIGFX
184#endif /* GPU_MANAGER_H_ */
int m_totalHuge
Number of regular VRANGEs (small items) pooled into single draw call.
Definition: gpu_manager.h:153
std::vector< VRANGE > m_vranges
Number of huge VRANGEs (i.e. large zones) with separate draw calls.
Definition: gpu_manager.h:150
unsigned int m_indexBufMaxSize
Size of the current VRANGE.
Definition: gpu_manager.h:162
unsigned int m_indicesCapacity
Ranges of visible vertex indices to render.
Definition: gpu_manager.h:147
~GPU_CACHED_MANAGER()
Prepare the stored data to be drawn.
Definition: gpu_manager.cpp:98
unsigned int m_curVrangeSize
Definition: gpu_manager.h:165
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:85
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Clear the container after drawing routines.
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
bool m_buffersInitialized
Pointer to the current indices buffer.
Definition: gpu_manager.h:141
int m_totalNormal
Current size of index buffer.
Definition: gpu_manager.h:156
boost::scoped_array< GLuint > m_indices
Current indices buffer size.
Definition: gpu_manager.h:144
unsigned int m_indexBufSize
Maximum size taken by the index buffer for all frames rendered so far.
Definition: gpu_manager.h:159
void Map()
Unmap vertex buffer.
void resizeIndices(unsigned int aNewSize)
< Resizes the indices buffer to aNewSize if necessary
virtual void EndDrawing() override
Map vertex buffer stored in GPU memory.
Class to handle uploading vertices and indices to GPU in drawing purposes.
Definition: gpu_manager.h:46
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
Definition: gpu_manager.cpp:57
int m_shaderAttrib
true: enable Z test when drawing
Definition: gpu_manager.h:95
virtual void SetShader(SHADER &aShader)
Allow using shaders with the stored data.
Definition: gpu_manager.cpp:72
virtual void DrawIndices(const VERTEX_ITEM *aItem)=0
Make the GPU draw given range of vertices.
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
VERTEX_CONTAINER * m_container
Shader handling.
Definition: gpu_manager.h:89
virtual void BeginDrawing()=0
Prepare the stored data to be drawn.
bool m_isDrawing
Container that stores vertices data.
Definition: gpu_manager.h:86
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:48
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:92
virtual void EndDrawing()=0
Clear the container after drawing routines.
virtual ~GPU_MANAGER()
Definition: gpu_manager.cpp:67
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
GPU_NONCACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Prepare the stored data to be drawn.
virtual void EndDrawing() override
Clear the container after drawing routines.
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Clear the container after drawing routines.
Provide the access to the OpenGL shaders.
Definition: shader.h:77
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:243
VRANGE(int aStart, int aEnd, bool aContinuous)
Definition: gpu_manager.h:108
Common defines and consts used in vertex related classes.