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
58 virtual void DrawIndices( const VERTEX_ITEM* aItem ) = 0;
59
63 virtual void EndDrawing() = 0;
64
70 virtual void SetShader( SHADER& aShader );
71
75 void EnableDepthTest( bool aEnabled );
76
77protected:
78 GPU_MANAGER( VERTEX_CONTAINER* aContainer );
79
82
85
88
91
94};
95
96
98{
99public:
100
101 struct VRANGE
102 {
103 VRANGE( int aStart, int aEnd, bool aContinuous ) :
104 m_start( aStart ),
105 m_end( aEnd ),
106 m_isContinuous( aContinuous )
107 {
108 }
109
110 unsigned int m_start, m_end;
112 };
113
114
117
119 virtual void BeginDrawing() override;
120
122 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
123
125 virtual void EndDrawing() override;
126
128 void Map();
129
131 void Unmap();
132
133protected:
135 void resizeIndices( unsigned int aNewSize );
136
139
141 boost::scoped_array<GLuint> m_indices;
142
144 unsigned int m_indicesCapacity;
145
147 std::vector<VRANGE> m_vranges;
148
151
154
156 unsigned int m_indexBufSize;
157
159 unsigned int m_indexBufMaxSize;
160
162 unsigned int m_curVrangeSize;
163};
164
165
167{
168public:
170
172 virtual void BeginDrawing() override;
173
175 virtual void DrawIndices( const VERTEX_ITEM* aItem ) override;
176
178 virtual void EndDrawing() override;
179};
180
181} // namespace KIGFX
182
183#endif /* GPU_MANAGER_H_ */
Class to store VERTEX instances with caching.
int m_totalHuge
Number of huge VRANGEs (i.e. large zones) with separate draw calls.
std::vector< VRANGE > m_vranges
Ranges of visible vertex indices to render.
unsigned int m_indexBufMaxSize
Maximum size taken by the index buffer for all frames rendered so far.
unsigned int m_indicesCapacity
Current indices buffer size.
unsigned int m_curVrangeSize
Size of the current VRANGE.
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Make the GPU draw given range of vertices.
virtual void BeginDrawing() override
Prepare the stored data to be drawn.
bool m_buffersInitialized
Buffers initialization flag.
int m_totalNormal
Number of regular VRANGEs (small items) pooled into single draw call.
boost::scoped_array< GLuint > m_indices
Pointer to the current indices buffer.
unsigned int m_indexBufSize
Current size of index buffer.
void Map()
Map vertex buffer stored in GPU memory.
void Unmap()
Unmap vertex buffer.
void resizeIndices(unsigned int aNewSize)
Resizes the indices buffer to aNewSize if necessary.
virtual void EndDrawing() override
Clear the container after drawing routines.
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition gpu_manager.h:90
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
Container that stores vertices data.
Definition gpu_manager.h:84
bool m_enableDepthTest
true: enable Z test when drawing
Definition gpu_manager.h:93
virtual void BeginDrawing()=0
Prepare the stored data to be drawn.
bool m_isDrawing
Drawing status flag.
Definition gpu_manager.h:81
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
SHADER * m_shader
Shader handling.
Definition gpu_manager.h:87
virtual void EndDrawing()=0
Clear the container after drawing routines.
virtual void BeginDrawing() override
Prepare the stored data to be drawn.
GPU_NONCACHED_MANAGER(VERTEX_CONTAINER *aContainer)
virtual void EndDrawing() override
Clear the container after drawing routines.
virtual void DrawIndices(const VERTEX_ITEM *aItem) override
Make the GPU draw given range of vertices.
Provide the access to the OpenGL shaders.
Definition shader.h:73
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
VRANGE(int aStart, int aEnd, bool aContinuous)
Common defines and consts used in vertex related classes.