vbo_MapRender.h 6.48 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _VBO_MAP_RENDER_
#define _VBO_MAP_RENDER_

28
#include <GL/glew.h>
Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
#include <vector>
#include <list>

32
#include "Topology/generic/dart.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
33
#include "Topology/generic/functor.h"
34
#include "Topology/generic/attributeHandler.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
35
#include "Container/convert.h"
36
#include "Geometry/vector_gen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

namespace CGoGN
{

namespace Algo
{

namespace Render
{

namespace VBO
{

enum drawingType {
	TRIANGLES = 1,
	LINES = 2,
	POINTS = 4,
	EXPLODED = 8,
	FLAT_TRIANGLES = 16,
	ERR = 32
} ;

enum bufferType {
	POSITIONS = 1,
	NORMALS = 2,
	COLORS = 4,
	TEXCOORDS = 8,
	ENDVECTORS = 16
} ;

enum bufferIndex {
	TRIANGLE_INDICES = 0,
	LINE_INDICES = 1,
	POINT_INDICES = 2,
Sylvain Thery's avatar
Sylvain Thery committed
71
72
73
74
75
76
	FLAT_BUFFER = 3,
	POSITIONS_BUFFER = 4,
	NORMALS_BUFFER = 5,
	COLORS_BUFFER = 6


Pierre Kraemer's avatar
Pierre Kraemer committed
77
78
79
80
} ;

const unsigned int NB_BUFFERS = 7 ;

81

Pierre Kraemer's avatar
Pierre Kraemer committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class MapRender_VBO
{

protected:
	/**
	 * vbo buffers
	 */
	GLuint m_VBOBuffers[NB_BUFFERS] ;
	bool m_allocatedBuffers[NB_BUFFERS] ;
	bool m_usedBuffers[NB_BUFFERS] ;

	/**
	 * number of indices of triangles
	 */
	GLuint m_nbIndicesTri ;

	/**
	 * number of indices of lines
	 */
	GLuint m_nbIndicesLines ;

	/**
	 * number of indices of points
	 */
	GLuint m_nbIndicesPoints ;


	GLuint m_nbFlatElts;

public:
	/**
	 * Constructor
	 */
115
	MapRender_VBO() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
116

Sylvain Thery's avatar
Sylvain Thery committed
117
118
119
120
121
	/**
	 * Constructor that share vertices attributes vbo (position/normals/colors...)
	 */
	MapRender_VBO(const MapRender_VBO& mrvbo);

Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
	/**
	 * Destructor
	 */
	~MapRender_VBO() ;

	/**
	 * update the data
	 * @param uptype that have to be updated: POSITIONS, NORMALS, COLORS, TEXCOORDS, ???
	 * @param attribId attribute where data is stored
	 * @param conv Callback of attribute conversion (NULL if direct copy, default value)
	 */
	template <typename ATTR_HANDLER>
	void updateData(int upType, const ATTR_HANDLER& attrib, ConvertAttrib* conv = NULL) ;

	void enableBuffers(int buffersMask) ;
	void disableBuffers(int buffersMask) ;

protected:
	/**
	* fill buffer directly from attribute
	*/
	template <typename ATTR_HANDLER>
	void fillBufferDirect(unsigned int indexVBO, const ATTR_HANDLER& attrib) ;

	/**
	* fill buffer with conversion from attribute
	*/
	template <typename ATTR_HANDLER>
	void fillBufferConvert(unsigned int indexVBO, const ATTR_HANDLER& attrib, ConvertAttrib* conv) ;

	/**
	 * addition of indices table of one triangle
	 * @param d a dart of the triangle
	 * @param tableIndices the indices table
	 */
157
158
	template <typename PFP>
	void addTri(typename PFP::MAP& map, Dart d, std::vector<GLuint>& tableIndices) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
159
160
161
162
163
164

public:
	/**
	 * creation of indices table of triangles (optimized order)
	 * @param tableIndices the table where indices are stored
	 */
165
166
167
168
	template <typename PFP>
	void initTriangles(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices) ;
	template <typename PFP>
	void initTrianglesOptimized(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
172
173

	/**
	 * creation of indices table of lines (optimized order)
	 * @param tableIndices the table where indices are stored
	 */
174
175
176
177
	template <typename PFP>
	void initLines(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices) ;
	template <typename PFP>
	void initLinesOptimized(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
180
181
182

	/**
	 * creation of indices table of points
	 * @param tableIndices the table where indices are stored
	 */
183
184
	template <typename PFP>
	void initPoints(typename PFP::MAP& map, const FunctorSelect& good,std::vector<GLuint>& tableIndices) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
185
186
187
188

	/**
	 * creation of VBO for flat faces rendering
	 */
189
190
	template <typename PFP>
	void initFlatTriangles(typename PFP::MAP& map, const FunctorSelect& good);
Pierre Kraemer's avatar
Pierre Kraemer committed
191
192
193
194
195
196

	/**
	 * initialization of the VBO indices primitives
	 * computed by a traversal of the map
	 * @param prim primitive to draw: VBO_TRIANGLES, VBO_LINES
	 */
197
198
	template <typename PFP>
	void initPrimitives(typename PFP::MAP& map, const FunctorSelect& good, int prim, bool optimized = true) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245

	/**
	 * initialization of the VBO indices primitives
	 * using the given table
	 * @param prim primitive to draw: VBO_TRIANGLES, VBO_LINES
	 */
	void initPrimitives(int prim, std::vector<GLuint>& tableIndices) ;

protected:
	/**
	 * Drawing triangles function
	 */
	void drawTriangles(bool bindColors = true) ;

	/**
	 * Drawing lines function
	 */
	void drawLines(bool bindColors = true) ;

	/**
	 * Drawing points function
	 */
	void drawPoints(bool bindColors = true) ;

	/**
	 * Drawing flat faces function
	 */
	void drawFlat();

public:
	/**
	 * draw the VBO (function to call in the drawing callback)
	 */
	void draw(int prim, bool bindColors = true) ;
} ;

} // namespace VBO

} // namespace Render

} // namespace Algo

} // namespace CGoGN

#include "Algo/Render/vbo_MapRender.hpp"

#endif