Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

clippingShader.h 9 KB
Newer Older
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
28
29
30
31
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, 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: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _CGoGN_CLIPPINGSHADER_H_
#define _CGoGN_CLIPPINGSHADER_H_

#include "Utils/GLSLShader.h"
#include "Geometry/vector_gen.h"
#include "Utils/cgognStream.h"
#include "Utils/shaderMutator.h"
32
#include "Utils/drawer.h"
33
#include <string>
34
35
#include <sstream>
#include <vector>
36
37
38
39
40
41
42
43
44
45

namespace CGoGN
{

namespace Utils
{

class ClippingShader : public GLSLShader
{

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

	/***********************************************
	 *
	 * 		Constructor / Destructor
	 *
	 ***********************************************/

public :

	/// constructor
	ClippingShader();

	/// destructor
	~ClippingShader();


	/***********************************************
	 *
	 * 		Miscellaneous Stuff
	 *
	 ***********************************************/

68
public:
69

70
	/// enum used to choose which type of clip plane grid to display
71
72
	enum clipPlaneDisplayGridType { STRAIGHT_GRID, RADIAL_GRID };

73
74
75
76
77
78

	/***********************************************
	 *
	 * 		Plane Clipping
	 *
	 ***********************************************/
79

80
	/**
81
82
83
84
85
	 * set the clip planes count
	 * - inserts plane clipping instructions into vertex and fragment shader source code
	 * - does not modify the geometry shader source code
	 * @param planesCount the clip planes count to use
	 * @warning this function is designed for shaders which *do not* use a geometry shader
86
	 */
87
88
89
90
	void setClipPlanesCount(int planesCount);

	/// get the clip planes count
	int getClipPlanesCount();
91

92
	/**
93
	 * set all parameters for one clip plane
94
	 * @warning planeIndex starts at 0
95
96
97
98
	 * @param vec1 first basis vector
	 * @param vec2 second basis vector
	 * @param origin point of the plane that will be used as origin to display it
	 * @param planeIndex index of the plane to modify
99
	 */
100
	void setClipPlaneParamsAll(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);
101
102

	/**
103
	 * set first vector for one clip plane
104
105
106
107
	 * @warning planeIndex starts at 0
	 * @param vec1 first basis vector
	 * @param planeIndex index of the plane to modify
	 */
108
	void setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex = 0);
109
110

	/**
111
	 * set second vector for one clip plane
112
113
114
115
	 * @warning planeIndex starts at 0
	 * @param vec2 second basis vector
	 * @param planeIndex index of the plane to modify
	 */
116
	void setClipPlaneParamsSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
117
	
118
	/**
119
	 * set origin for one clip plane
120
	 * @warning planeIndex starts at 0
121
122
	 * @param origin point of the plane that will be used as origin to display it
	 * @param planeIndex index of the plane to modify
123
	 */
124
	void setClipPlaneParamsOrigin(Geom::Vec3f origin, int planeIndex = 0);
125
126

	/**
127
	 * get first vector for one clip plane
128
129
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
130
	 */
131
	Geom::Vec3f getClipPlaneParamsFirstVec(int planeIndex = 0);
132
133

	/**
134
	 * get second vector for one clip plane
135
136
137
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
	 */
138
	Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex = 0);
139
140

	/**
141
	 * get origin for one clip plane
142
143
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
144
	 */
145
	Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex = 0);
146

147
	/// display all clipping planes
148
	void displayClipPlanes();
149
150

	/**
151
152
153
	 * set the planes display color
	 * @param color the new color
	 */
154
	void setPlaneDisplayColor(Geom::Vec3f color) { m_clipPlanesDisplayColor = color; updateAllClippingPlanesVBOs(); }
155

156
	/// get the planes display color
157
158
159
160
161
162
	Geom::Vec3f getPlaneDisplayColor() { return m_clipPlanesDisplayColor; }

	/**
	 * set the planes display grids type
	 * @param gridType the new grid type
	 */
163
	void setPlaneDisplayType(clipPlaneDisplayGridType gridType) { m_clipPlanesDisplayType = gridType; updateAllClippingPlanesVBOs(); }
164

165
	/// get the planes display grids type
166
167
168
169
170
171
	clipPlaneDisplayGridType getPlaneDisplayType() { return m_clipPlanesDisplayType; }

	/**
	 * set the planes display grid x resolution
	 * @param res the new resolution
	 */
172
	void setPlaneDisplayXRes(size_t res) { m_clipPlanesDisplayXRes = res; updateAllClippingPlanesVBOs(); }
173

174
	/// get the planes display grid x resolution
175
176
177
178
179
180
	size_t getPlaneDisplayXRes() { return m_clipPlanesDisplayXRes; }

	/**
	 * set the planes display grid y resolution
	 * @param res the new resolution
	 */
181
	void setPlaneDisplayYRes(size_t res) { m_clipPlanesDisplayYRes = res; updateAllClippingPlanesVBOs(); }
182

183
	/// get the planes display grid y resolution
184
185
186
187
	size_t getPlaneDisplayYRes() { return m_clipPlanesDisplayYRes; }

	/**
	 * set the planes display size
188
189
	 * @param size the new size
	 */
190
	void setPlaneDisplaySize(float size) { m_clipPlanesDisplaySize = size; updateAllClippingPlanesVBOs(); }
191

192
	/// get the planes display size
193
	float getPlaneDisplaySize() { return m_clipPlanesDisplaySize; }
194

195
196
197
198
199
200
201

	/***********************************************
	 *
	 * 		Global Clipping Stuff
	 *
	 ***********************************************/

202
203
204
205
206
207
	/**
	 * set the color attenuation factor for clipping
	 * @param colorAttenuationFactor color attenuation factor
	 */
	void setClipColorAttenuationFactor(float colorAttenuationFactor);

208
209
	/// get the color attenuation factor for clipping
	float getClipColorAttenuationFactor();
210

211
212
213
214
215
216
217
218

	/***********************************************
	 *
	 * 		Clipping Uniforms Handling
	 *
	 ***********************************************/

	/// update uniforms (get their locations and send their values again) for clipping
219
220
	void updateClippingUniforms();

221

222
223
224
225
226
227
	/***********************************************
	 *
	 * 		Private Section
	 *
	 ***********************************************/

228
229
private:

230
	/// clip planes structure
231
232
233
234
235
	struct clipPlane
	{
		Geom::Vec3f firstVec, secondVec, origin;
	};

236
	/// sends the clip planes arrays to shader
237
238
	void sendClippingPlanesUniform();

239
	/// sends the color attenuation factor to shader
240
241
	void sendColorAttenuationFactorUniform();

242
243
244
245
	/**
	 * update clip planes parameters arrays
	 * @param planeIndex index of the plane
	 */
246
	void updateClippingPlaneArray(int planeIndex);
247

248
	/**
249
	 * update VBO for one plane
250
251
252
253
	 * @param planeIndex index of the plane
	 */
	void updateClippingPlaneVBO(int planeIndex);

254
	/// update VBOs for all planes
255
256
	void updateAllClippingPlanesVBOs();

257
	/// original vertex shader source code (without clipping)
258
259
	std::string originalVertShaderSrc;

260
	/// original fragment shader source code (without clipping)
261
262
	std::string originalFragShaderSrc;

263
	/// clip planes array
264
265
	std::vector<clipPlane> m_clipPlanes;

266
	/**
267
	 * clip planes equations array (size = 4*(planes count))
268
	 * - ** only used for sending planes data to shader **
269
	 */
270
	std::vector<float> m_clipPlanesEquations;
271

272
	/// clip planes equations vector uniform id
273
	GLint m_unif_clipPlanesEquations;
274

275
	/// color attenuation factor
276
	float m_colorAttenuationFactor;
277
278

	/// color attenuation factor uniform id
279
280
	GLint m_unif_colorAttenuationFactor;

281
	/// clip planes drawers array
282
283
	std::vector<Drawer*> m_clipPlanesDrawers;

284
	/// clip planes display color
285
286
	Geom::Vec3f m_clipPlanesDisplayColor;

287
	/// clip planes display grid type
288
289
	clipPlaneDisplayGridType m_clipPlanesDisplayType;

290
	/// clip planes x grid display resolution
291
292
	size_t m_clipPlanesDisplayXRes;

293
	/// clip planes y grid display resolution
294
295
	size_t m_clipPlanesDisplayYRes;

296
	/// clip planes display size
297
	float m_clipPlanesDisplaySize;
298

299
300
301
302
303
304
305
306
};


} // namespace Utils

} // namespace CGoGN

#endif