KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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
23#ifndef GPU_MANAGER_H_
24#define GPU_MANAGER_H_
25
26#include <vector>
28#include <boost/scoped_array.hpp>
29
30namespace KIGFX
31{
32class SHADER;
34class VERTEX_ITEM;
37
42{
43public:
44 static GPU_MANAGER* MakeManager( VERTEX_CONTAINER* aContainer );
45
46 virtual ~GPU_MANAGER();
47
51 virtual void BeginDrawing() = 0;
52
59 virtual void DrawIndices( const VERTEX_ITEM* aItem ) = 0;
60
64 virtual void EndDrawing() = 0;
65
71 virtual void SetShader( SHADER& aShader );
72
76 void EnableDepthTest( bool aEnabled );
77
78protected:
79 GPU_MANAGER( VERTEX_CONTAINER* aContainer );
80
83
86
89
92
95};
96
97
99{
100public:
101
102 struct VRANGE
103 {
104 VRANGE( int aStart, int aEnd, bool aContinuous ) :
105 m_start( aStart ),
106 m_end( aEnd ),
107 m_isContinuous( aContinuous )
108 {
109 }
110
111 unsigned int m_start, m_end;
113 };
114
115
118
120 virtual void BeginDrawing() override;
121
123 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
124
126 virtual void EndDrawing() override;
127
129 void Map();
130
132 void Unmap();
133
134protected:
136 void resizeIndices( unsigned int aNewSize );
137
140
142 boost::scoped_array<GLuint> m_indices;
143
145 unsigned int m_indicesCapacity;
146
148 std::vector<VRANGE> m_vranges;
149
152
155
157 unsigned int m_indexBufSize;
158
160 unsigned int m_indexBufMaxSize;
161
163 unsigned int m_curVrangeSize;
164};
165
166
168{
169public:
171
173 virtual void BeginDrawing() override;
174
176 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
177
179 virtual void EndDrawing() override;
180};
181
182} // namespace KIGFX
183
184#endif /* GPU_MANAGER_H_ */
Class to store VERTEX instances with caching.
int m_totalHuge
Number of regular VRANGEs (small items) pooled into single draw call.
std::vector< VRANGE > m_vranges
Number of huge VRANGEs (i.e. large zones) with separate draw calls.
unsigned int m_indexBufMaxSize
Size of the current VRANGE.
unsigned int m_indicesCapacity
Ranges of visible vertex indices to render.
~GPU_CACHED_MANAGER()
Prepare the stored data to be drawn.
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
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.
int m_totalNormal
Current size of index buffer.
boost::scoped_array< GLuint > m_indices
Current indices buffer size.
unsigned int m_indexBufSize
Maximum size taken by the index buffer for all frames rendered so far.
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.
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
int m_shaderAttrib
true: enable Z test when drawing
Definition gpu_manager.h:91
virtual void SetShader(SHADER &aShader)
Allow using shaders with the stored data.
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:85
virtual void BeginDrawing()=0
Prepare the stored data to be drawn.
bool m_isDrawing
Container that stores vertices data.
Definition gpu_manager.h:82
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition gpu_manager.h:88
virtual void EndDrawing()=0
Clear the container after drawing routines.
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:73
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
VRANGE(int aStart, int aEnd, bool aContinuous)
Common defines and consts used in vertex related classes.