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, 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;
38class VERTEX_ITEM;
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 }
114
115 unsigned int m_start, m_end;
117 };
118
119
122
124 virtual void BeginDrawing() override;
125
127 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
128
130 virtual void EndDrawing() override;
131
133 void Map();
134
136 void Unmap();
137
138protected:
140 void resizeIndices( unsigned int aNewSize );
141
144
146 boost::scoped_array<GLuint> m_indices;
147
149 unsigned int m_indicesCapacity;
150
152 std::vector<VRANGE> m_vranges;
153
156
159
161 unsigned int m_indexBufSize;
162
164 unsigned int m_indexBufMaxSize;
165
167 unsigned int m_curVrangeSize;
168};
169
170
172{
173public:
175
177 virtual void BeginDrawing() override;
178
180 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
181
183 virtual void EndDrawing() override;
184};
185
186} // namespace KIGFX
187
188#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:95
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: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)
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 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 eda_group.h:33
VRANGE(int aStart, int aEnd, bool aContinuous)
Common defines and consts used in vertex related classes.