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.09 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

Sylvain Thery's avatar
Sylvain Thery committed
36
37
#include "Utils/dll.h"

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

41
42
namespace Utils
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
43

44
45
46
47
48
49
50
/**
 * 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)
 *
 */
Sylvain Thery's avatar
Sylvain Thery committed
51
class CGoGN_UTILS_API Drawer
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
	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;
69
	float m_currentSize;
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
	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();

86
87
	Utils::ShaderColorPerVertex* getShader();

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

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

	/**
	 * 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
114
	 * @return index of position for update
115
	 */
Sylvain Thery's avatar
Sylvain Thery committed
116
	unsigned int vertex(const Geom::Vec3f& v);
117
118
119

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

	/**
	 * 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
137
	void callList(float opacity = 1.0f);
138

139
140
141
142
143
144
145
146
147
148
	/**
	 * 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);

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


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

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

Sylvain Thery's avatar
Sylvain Thery committed
165
166
167
	/**
	 * update position of VBO of drawer
	 * @param first index of vertex to update
168
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
169
170
171
172
173
174
175
	 * @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
176
	 * @param nb number of vertices to update
Sylvain Thery's avatar
Sylvain Thery committed
177
178
179
180
	 * @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
181
182
183
184
	/**
	 * rendering in svg struct
	 */
	void toSVG(Utils::SVG::SVGOut& svg);
185
186
};

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

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
189
} // namespace CGoGN
190

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