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 
82 protected:
83  GPU_MANAGER( VERTEX_CONTAINER* aContainer );
84 
87 
90 
93 
96 };
97 
98 
100 {
101 public:
102  GPU_CACHED_MANAGER( VERTEX_CONTAINER* aContainer );
104 
106  virtual void BeginDrawing() override;
107 
109  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
110 
112  virtual void DrawAll() override;
113 
115  virtual void EndDrawing() override;
116 
118  void Map();
119 
121  void Unmap();
122 
123 protected:
125  void resizeIndices( unsigned int aNewSize );
126 
129 
131  boost::scoped_array<GLuint> m_indices;
132 
134  GLuint* m_indicesPtr;
135 
138 
140  unsigned int m_indicesSize;
141 
143  unsigned int m_indicesCapacity;
144 };
145 
146 
148 {
149 public:
151 
153  virtual void BeginDrawing() override;
154 
156  virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) override;
157 
159  virtual void DrawAll() override;
160 
162  virtual void EndDrawing() override;
163 };
164 } // namespace KIGFX
165 #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:143
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:95
bool m_buffersInitialized
Buffers initialization flag
Definition: gpu_manager.h:128
VERTEX_CONTAINER * m_container
Container that stores vertices data.
Definition: gpu_manager.h:89
virtual void EndDrawing() override
>
unsigned int m_indicesSize
Number of indices stored in the indices buffer
Definition: gpu_manager.h:140
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize) override
>
GLuint m_indicesBuffer
Handle to indices buffer
Definition: gpu_manager.h:137
GLuint * m_indicesPtr
Pointer to the first free cell in the indices buffer
Definition: gpu_manager.h:134
GPU_NONCACHED_MANAGER(VERTEX_CONTAINER *aContainer)
void Map()
Maps vertex buffer stored in GPU memory.
Class to handle uploading vertices and indices to GPU in drawing purposes.
Definition: gpu_manager.h:42
virtual void DrawAll() override
>
virtual void BeginDrawing() override
>
Definition: gpu_manager.cpp:94
static GPU_MANAGER * MakeManager(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:42
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.
GPU_CACHED_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:75
Common defines and consts used in vertex related classes.
virtual void DrawAll() override
>
virtual void EndDrawing() override
>
bool m_isDrawing
Drawing status flag.
Definition: gpu_manager.h:86
virtual void BeginDrawing()=0
Function BeginDrawing() Prepares the stored data to be drawn.
virtual void DrawIndices(unsigned int aOffset, unsigned int aSize) override
>
SHADER * m_shader
Shader handling
Definition: gpu_manager.h:92
void resizeIndices(unsigned int aNewSize)
Resizes the indices buffer to aNewSize if necessary
GPU_MANAGER(VERTEX_CONTAINER *aContainer)
Definition: gpu_manager.cpp:51
virtual void BeginDrawing() override
>
boost::scoped_array< GLuint > m_indices
Pointer to the current indices buffer
Definition: gpu_manager.h:131
void Unmap()
Unmaps vertex buffer.