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 <maciej.suminski@cern.ch>
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 
31 #include <boost/scoped_array.hpp>
32 
33 namespace KIGFX
34 {
35 class SHADER;
36 class VERTEX_CONTAINER;
37 class CACHED_CONTAINER;
38 class NONCACHED_CONTAINER;
39 
44 {
45 public:
46  static GPU_MANAGER* MakeManager( VERTEX_CONTAINER* aContainer );
47 
48  virtual ~GPU_MANAGER();
49 
53  virtual void BeginDrawing() = 0;
54 
61  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) = 0;
62 
66  virtual void DrawAll() = 0;
67 
71  virtual void EndDrawing() = 0;
72 
78  virtual void SetShader( SHADER& aShader );
79 
83  void EnableDepthTest( bool aEnabled );
84 
85 protected:
86  GPU_MANAGER( VERTEX_CONTAINER* aContainer );
87 
90 
93 
96 
99 
102 };
103 
104 
106 {
107 public:
108  GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer );
110 
112  virtual void BeginDrawing() override;
113 
115  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
116 
118  virtual void DrawAll() override;
119 
121  virtual void EndDrawing() override;
122 
124  void Map();
125 
127  void Unmap();
128 
129 protected:
131  void resizeIndices( unsigned int aNewSize );
132 
135 
137  boost::scoped_array<GLuint> m_indices;
138 
140  GLuint* m_indicesPtr;
141 
144 
146  unsigned int m_indicesSize;
147 
149  unsigned int m_indicesCapacity;
150 };
151 
152 
154 {
155 public:
157 
159  virtual void BeginDrawing() override;
160 
162  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
163 
165  virtual void DrawAll() override;
166 
168  virtual void EndDrawing() override;
169 };
170 } // namespace KIGFX
171 #endif /* GPU_MANAGER_H_ */
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize)=0
Make the GPU draw given range of vertices.
virtual ~GPU_MANAGER()
Definition: gpu_manager.cpp:64
virtual void SetShader(SHADER &aShader)
Allow using shaders with the stored data.
Definition: gpu_manager.cpp:69
unsigned int m_indicesCapacity
Definition: gpu_manager.h:149
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
int m_shaderAttrib
true: enable Z test when drawing
Definition: gpu_manager.h:98
bool m_buffersInitialized
Pointer to the current indices buffer.
Definition: gpu_manager.h:134
VERTEX_CONTAINER * m_container
Shader handling.
Definition: gpu_manager.h:92
virtual void EndDrawing() override
Clear the container after drawing routines.
unsigned int m_indicesSize
Current indices buffer size.
Definition: gpu_manager.h:146
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize) override
Make the GPU draw all the vertices stored in the container.
GLuint m_indicesBuffer
Number of indices stored in the indices buffer.
Definition: gpu_manager.h:143
GLuint * m_indicesPtr
Handle to indices buffer.
Definition: gpu_manager.h:140
GPU_NONCACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Prepare the stored data to be drawn.
void Map()
Unmap vertex buffer.
Class to handle uploading vertices and indices to GPU in drawing purposes.
Definition: gpu_manager.h:43
virtual void DrawAll() override
Clear the container after drawing routines.
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:45
void EnableDepthTest(bool aEnabled)
Enable/disable Z buffer depth test.
Provide the access to the OpenGL shaders.
Definition: shader.h:76
virtual void DrawAll()=0
Make the GPU draw all the vertices stored in the container.
virtual void EndDrawing()=0
Clear the container after drawing routines.
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:82
Common defines and consts used in vertex related classes.
virtual void DrawAll() override
Clear the container after drawing routines.
virtual void EndDrawing() override
Map vertex buffer stored in GPU memory.
bool m_isDrawing
Container that stores vertices data.
Definition: gpu_manager.h:89
virtual void BeginDrawing()=0
Prepare the stored data to be drawn.
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize) override
Make the GPU draw all the vertices stored in the container.
SHADER * m_shader
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:95
void resizeIndices(unsigned int aNewSize)
< Resizes the indices buffer to aNewSize if necessary
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Drawing status flag.
Definition: gpu_manager.cpp:54
virtual void BeginDrawing() override
Make the GPU draw given range of vertices.
~GPU_CACHED_MANAGER()
Prepare the stored data to be drawn.
Definition: gpu_manager.cpp:95
boost::scoped_array< GLuint > m_indices
Pointer to the first free cell in the indices buffer.
Definition: gpu_manager.h:137