Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

drawer.h 5.05 KB
Newer Older
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
21
22
23
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
24

25
26
27
28
#ifndef _CGOGN_DRAWER_H_
#define _CGOGN_DRAWER_H_

#include <vector>
Thery Sylvain's avatar
Thery Sylvain committed
29
#include "Utils/gl_def.h"
30
#include "Geometry/vector_gen.h"
31
#include "Utils/Shaders/shaderColorPerVertex.h"
32
33

namespace CGoGN { namespace Utils { class VBO; } }
Sylvain Thery's avatar
Sylvain Thery committed
34
namespace CGoGN { namespace Utils { namespace SVG { class SVGOut ; } } }
35
36
37

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
38

39
40
namespace Utils
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
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
/**
 * A class that allow easy drawing, allmost as easy as
 * display lists in old school OpenGL 1.1
 * Allow only position and color
 * Drawing (callList) efficient after data has been finalized (endList)
 *
 */
class Drawer
{
	struct PrimParam
	{
		unsigned int begin;
		GLenum mode;
		float width;
		unsigned int nb;
		PrimParam(unsigned int b, GLenum m, float w): begin(b),mode(m),width(w),nb(0) {}
	};

protected:
	Utils::VBO* m_vboPos;
	Utils::VBO* m_vboCol;
	std::vector<Geom::Vec3f> m_dataPos;
	std::vector<Geom::Vec3f> m_dataCol;
	std::vector<PrimParam> m_begins;
	float m_currentWidth;
67
	float m_currentSize;
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	GLenum m_compile;
	Utils::ShaderColorPerVertex* m_shader;

public:

	/**
	 * constructor, init all buffers (data and OpenGL) and shader
	 * @Warning need OpenGL context
	 */
	Drawer();

	/**
	 * release buffers and shader
	 */
	~Drawer();

84
85
	Utils::ShaderColorPerVertex* getShader();

86
87
	/**
	 * init the data structure
88
	 * @param comp say if compile only, or compile and execute (GL_COMPILE / GL_COMPILE_AND_EXECUTE)
89
	 */
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
90
	void newList(GLenum comp = GL_COMPILE);
91
92
93
94

	/**
	 * as glBegin, but need a newList call before
	 * @param mode: POINTS, LINES, LINE_LOOP, TRIANGLES, QUADS, POLYGON, etc..
95
	 * @return index of subdrawing possible call
96
	 */
97
	int begin(GLenum mode);
98
99
100
101
102
103
104
105
106
107
108
109
110
111

	/**
	 * as glEnd
	 */
	void end();

	/**
	 * finalize the data initialization
	 * drawn is done if newList called with GL_COMPILE_AND_EXECUTE
	 */
	void endList();

	/**
	 * use as glVertex
Sylvain Thery's avatar
Sylvain Thery committed
112
	 * @return index of position for update
113
	 */
Sylvain Thery's avatar
Sylvain Thery committed
114
	unsigned int vertex(const Geom::Vec3f& v);
115
116
117

	/**
	 * use as glVertex
Sylvain Thery's avatar
Sylvain Thery committed
118
	 * @return index of position for update
119
	 */
Sylvain Thery's avatar
Sylvain Thery committed
120
	unsigned int vertex3f(float x, float y, float z);
121
122
123
124
125
126
127
128
129
130
131
132
133
134

	/**
	 * use as glColor
	 */
	void color(const Geom::Vec3f& col);

	/**
	 * use as glColor3f
	 */
	void color3f(float r, float g, float b);

	/**
	 * use as a glCallList
	 */
Sylvain Thery's avatar
Sylvain Thery committed
135
	void callList(float opacity = 1.0f);
136

137
138
139
140
141
142
143
144
145
146
	/**
	 * call a sub-list (index return by begin (0,1,...)
	 */
	void callSubList(int index, float opacity = 1.0f);

	/**
	 * call a set of sub-lists
	 */
	void callSubLists(std::vector<int> indices, float opacity);

147
148
149
150
151
152
	/**
	 * call a set of sub-lists
	 */
	void callSubLists(int first, int nb, float opacity);


153
154
155
156
157
158
159
160
161
	/**
	 * use as glLineWidth
	 */
	void lineWidth(float lw);

	/**
	 * usr as glPointSize
	 */
	void pointSize(float ps);
Sylvain Thery's avatar
Sylvain Thery committed
162

Sylvain Thery's avatar
Sylvain Thery committed
163
164
165
	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
166
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
167
168
169
170
171
172
173
	 * @param P ptr to table of vertices
	 */
	void updatePositions(unsigned int first, unsigned int nb, const Geom::Vec3f* P);

	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
174
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
175
176
177
178
	 * @param P ptr to table of vertices
	 */
	void updatePositions(unsigned int first, unsigned int nb, const float* P);

Sylvain Thery's avatar
Sylvain Thery committed
179
180
181
182
	/**
	 * rendering in svg struct
	 */
	void toSVG(Utils::SVG::SVGOut& svg);
183
184
};

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
185
} // namespace Utils
186

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
187
} // namespace CGoGN
188

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
189
#endif