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

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

public :

	/// constructor
	ClippingShader();

	/// destructor
	~ClippingShader();


	/***********************************************
	 *
64
	 * 		Original Shader Sources
65
66
67
	 *
	 ***********************************************/

68
private:
69

70
71
72
73
74
	/// original vertex shader source code (without clipping)
	std::string originalVertShaderSrc;

	/// original fragment shader source code (without clipping)
	std::string originalFragShaderSrc;
75

76
77
78
79
80
81

	/***********************************************
	 *
	 * 		Plane Clipping
	 *
	 ***********************************************/
82

83
84
public:

85
	/**
86
87
88
89
90
	 * 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
91
	 */
92
93
94
95
	void setClipPlanesCount(int planesCount);

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

97
	/**
98
	 * set all parameters for one clip plane
99
	 * @warning planeIndex starts at 0
100
101
102
103
	 * @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
104
	 */
105
	void setClipPlaneParamsAll(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex);
106
107

	/**
108
	 * set first vector for one clip plane
109
110
111
112
	 * @warning planeIndex starts at 0
	 * @param vec1 first basis vector
	 * @param planeIndex index of the plane to modify
	 */
113
	void setClipPlaneParamsFirstVec(Geom::Vec3f vec1, int planeIndex);
114
115

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

	/**
132
	 * get first vector for one clip plane
133
134
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
135
	 */
136
	Geom::Vec3f getClipPlaneParamsFirstVec(int planeIndex);
137
138

	/**
139
	 * get second vector for one clip plane
140
141
142
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
	 */
143
	Geom::Vec3f getClipPlaneParamsSecondVec(int planeIndex);
144
145

	/**
146
	 * get origin for one clip plane
147
148
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
149
	 */
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	Geom::Vec3f getClipPlaneParamsOrigin(int planeIndex);

private:

	/**
	 * update clip plane equation array
	 * @param planeIndex index of the plane
	 */
	void updateClipPlaneArray(int planeIndex);

	/// clip planes structure
	struct clipPlane
	{
		Geom::Vec3f firstVec, secondVec, origin;
	};

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

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

	/// clip planes equations vector uniform id
	GLint m_unif_clipPlanesEquations;


	/***********************************************
	 *
	 * 		Plane Clipping Display
	 *
	 ***********************************************/

public:

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

190
	/// display all clipping planes
191
	void displayClipPlanes();
192
193

	/**
194
195
196
	 * set the planes display color
	 * @param color the new color
	 */
197
	void setClipPlanesDisplayColor(Geom::Vec3f color);
198

199
	/// get the planes display color
200
	Geom::Vec3f getClipPlanesDisplayColor();
201
202
203
204
205

	/**
	 * set the planes display grids type
	 * @param gridType the new grid type
	 */
206
	void setClipPlanesDisplayType(clipPlaneDisplayGridType gridType);
207

208
	/// get the planes display grids type
209
	clipPlaneDisplayGridType getClipPlanesDisplayType();
210
211
212
213
214

	/**
	 * set the planes display grid x resolution
	 * @param res the new resolution
	 */
215
	void setClipPlanesDisplayXRes(size_t res);
216

217
	/// get the planes display grid x resolution
218
	size_t getClipPlanesDisplayXRes();
219
220
221
222
223

	/**
	 * set the planes display grid y resolution
	 * @param res the new resolution
	 */
224
	void setClipPlanesDisplayYRes(size_t res);
225

226
	/// get the planes display grid y resolution
227
	size_t getClipPlanesDisplayYRes();
228
229
230

	/**
	 * set the planes display size
231
232
	 * @param size the new size
	 */
233
	void setClipPlanesDisplaySize(float size);
234

235
	/// get the planes display size
236
	float getClipPlanesDisplaySize();
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265

private:

	/**
	 * update VBO for one plane
	 * @param planeIndex index of the plane
	 */
	void updateClipPlaneVBO(int planeIndex);

	/// update VBOs for all planes
	void updateClipPlanesVBOs();

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

	/// clip planes display color
	Geom::Vec3f m_clipPlanesDisplayColor;

	/// clip planes display grid type
	clipPlaneDisplayGridType m_clipPlanesDisplayType;

	/// clip planes x grid display resolution
	size_t m_clipPlanesDisplayXRes;

	/// clip planes y grid display resolution
	size_t m_clipPlanesDisplayYRes;

	/// clip planes display size
	float m_clipPlanesDisplaySize;
266

267
268
269
270
271
272
273

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

274
275
public:

276
277
278
279
280
281
	/**
	 * set the color attenuation factor for clipping
	 * @param colorAttenuationFactor color attenuation factor
	 */
	void setClipColorAttenuationFactor(float colorAttenuationFactor);

282
283
	/// get the color attenuation factor for clipping
	float getClipColorAttenuationFactor();
284

285
286
287
288
289
290
291
292
private:

	/// color attenuation factor
	float m_clipColorAttenuationFactor;

	/// color attenuation factor uniform id
	GLint m_unif_clipColorAttenuationFactor;

293
294
295
296
297
298
299

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

300
301
public:

302
	/// update uniforms (get their locations and send their values again) for clipping
303
304
	void updateClippingUniforms();

305
306
private:

307
308
	/// sends the clip planes equations array to shader
	void sendClipPlanesEquationsUniform();
309

310
	/// sends the color attenuation factor to shader
311
	void sendClipColorAttenuationFactorUniform();
312

313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

	/***********************************************
	 *
	 * 		Error Raising
	 *
	 ***********************************************/

private:

	/**
	 * Output a "parameter not positive" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 * @param paramName name of the parameter
	 */
	bool errorRaiseParameterIsNotPositive(bool condition, const std::string& location, const std::string& paramName);

	/**
	 * Output a "shader has not been well created" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 */
	bool errorRaiseShaderHasNotBeenWellCreated(bool condition, const std::string& location);

	/**
	 * Output a "shader uses a geometry shader" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 */
	bool errorRaiseShaderUsesGeometryShader(bool condition, const std::string& location);

	/**
	 * Output a ".. not found in shader" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 * @param shaderType type of the shader
	 * @param varName name of the variable that may not be found
	 */
	bool errorRaiseVariableNotFoundInShader(bool condition, const std::string& location, ShaderMutator::shaderSrcType shaderType, const std::string& varName);

	/**
	 * Output a "parameter is out of range" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 * @param paramName name of the parameter
	 */
	bool errorRaiseParameterIsOutOfRange(bool condition, const std::string& location, const std::string& paramName);

	/**
	 * Output a "uniform .. not found in shader" error if the condition is satisfied
	 * @param condition condition to satisfy
	 * @param location name of the function where the error raising is done
	 * @param uniformName name of the uniform that may not be found
	 */
	bool errorRaiseUniformNotFoundInShader(bool condition, const std::string& location, const std::string& uniformName);

369
370
371
372
373
374
375
376
};


} // namespace Utils

} // namespace CGoGN

#endif