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  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef GPU_MANAGER_H_
26 #define GPU_MANAGER_H_
27 
29 #include <boost/scoped_array.hpp>
30 
31 namespace KIGFX
32 {
33 class SHADER;
34 class VERTEX_CONTAINER;
35 class CACHED_CONTAINER;
36 class NONCACHED_CONTAINER;
37 
43 {
44 public:
45  static GPU_MANAGER* MakeManager( VERTEX_CONTAINER* aContainer );
46 
47  virtual ~GPU_MANAGER();
48 
53  virtual void BeginDrawing() = 0;
54 
61  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) = 0;
62 
67  virtual void DrawAll() = 0;
68 
73  virtual void EndDrawing() = 0;
74 
80  virtual void SetShader( SHADER& aShader );
81 
86  void EnableDepthTest( bool aEnabled );
87 
88 protected:
89  GPU_MANAGER( VERTEX_CONTAINER* aContainer );
90 
93 
96 
99 
102 
105 };
106 
107 
109 {
110 public:
111  GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer );
113 
115  virtual void BeginDrawing() override;
116 
118  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
119 
121  virtual void DrawAll() override;
122 
124  virtual void EndDrawing() override;
125 
127  void Map();
128 
130  void Unmap();
131 
132 protected:
134  void resizeIndices( unsigned int aNewSize );
135 
138 
140  boost::scoped_array<GLuint> m_indices;
141 
143  GLuint* m_indicesPtr;
144 
147 
149  unsigned int m_indicesSize;
150 
152  unsigned int m_indicesCapacity;
153 };
154 
155 
157 {
158 public:
160 
162  virtual void BeginDrawing() override;
163 
165  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
166 
168  virtual void DrawAll() override;
169 
171  virtual void EndDrawing() override;
172 };
173 } // namespace KIGFX
174 #endif /* GPU_MANAGER_H_ */
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize)=0
Function DrawIndices() Makes the GPU draw given range of vertices.
virtual ~GPU_MANAGER()
Definition: gpu_manager.cpp:57
virtual void SetShader(SHADER &aShader)
Function SetShader() Allows using shaders with the stored data.
Definition: gpu_manager.cpp:62
unsigned int m_indicesCapacity
Current indices buffer size
Definition: gpu_manager.h:152
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
int m_shaderAttrib
Location of shader attributes (for glVertexAttribPointer)
Definition: gpu_manager.h:101
bool m_buffersInitialized
Buffers initialization flag
Definition: gpu_manager.h:137
VERTEX_CONTAINER * m_container
Container that stores vertices data.
Definition: gpu_manager.h:95
unsigned int m_indicesSize
Number of indices stored in the indices buffer
Definition: gpu_manager.h:149
GLuint m_indicesBuffer
Handle to indices buffer
Definition: gpu_manager.h:146
GLuint * m_indicesPtr
Pointer to the first free cell in the indices buffer
Definition: gpu_manager.h:143
Class to handle uploading vertices and indices to GPU in drawing purposes.
Definition: gpu_manager.h:42
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:42
void EnableDepthTest(bool aEnabled)
Function EnableDepthTest() Enables/disables Z buffer depth test.
Class SHADER provides the access to the OpenGL shaders.
Definition: shader.h:74
virtual void DrawAll()=0
Function DrawIndices() Makes the GPU draw all the vertices stored in the container.
virtual void EndDrawing()=0
Function EndDrawing() Clears the container after drawing routines.
Common defines and consts used in vertex related classes.
bool m_isDrawing
Drawing status flag.
Definition: gpu_manager.h:92
virtual void BeginDrawing()=0
Function BeginDrawing() Prepares the stored data to be drawn.
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:98
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:51
bool m_enableDepthTest
true: enable Z test when drawing
Definition: gpu_manager.h:104
boost::scoped_array< GLuint > m_indices
Pointer to the current indices buffer
Definition: gpu_manager.h:140