clippingShader.cpp 36 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 32
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#include "Utils/clippingShader.h"

namespace CGoGN
{

namespace Utils
{

33

34 35
/***********************************************
 *
36
 * 		Constructor / Destructor
37 38 39
 *
 ***********************************************/

40

41 42 43 44 45 46 47 48 49 50
ClippingShader::ClippingShader():
		// Initialize clipping shapes variables
		m_unif_clipPlanesEquations (0),
		m_unif_clipSpheresCentersAndRadiuses (0),

		// Initialize default global clipping variables
		m_hasClippingCodeBeenInserted (false),
		m_clipColorAttenuationFactor (1.0),
		m_unif_clipColorAttenuationFactor (0),
		m_clipMode (CLIPPING_MODE_AND)
51
{
52

53 54
}

55

56 57 58 59 60
/***********************************************
 *
 * 		Plane Clipping
 *
 ***********************************************/
61

62

63
int ClippingShader::addClipPlane()
64
{
65 66 67
	// Check if the clipping code has been inserted into shader
	if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::addClipPlane"))
		return -1;
68

69 70
	// Shader name string
	std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
71

72 73
	// Use a shader mutator
	ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());
74

75 76
	// Previous planes count
	int previousPlanesCount = getClipPlanesCount();
77

78 79 80 81 82 83
	// Modify the clip planes count constant in both shader
	if (errorRaiseShaderMutatorFailure(
			   (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount + 1))
			|| (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount + 1)),
			"ClippingShader::addClipPlane"))
		return -1;
84

85 86 87
	// Reload both shaders
	reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
	reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
88

89 90
	// Get new plane id
	unsigned int newPlaneId = getFreeClipPlaneId();
91

92 93 94 95
	// Resize planes arrays to the right size
	m_clipPlanes.resize((size_t)(previousPlanesCount + 1));
	m_clipPlanesIds.resize((size_t)newPlaneId);
	m_clipPlanesEquations.resize(4*(size_t)(previousPlanesCount + 1), 0.0);
96

97 98 99
	// Set new plane id
	m_clipPlanesIds[newPlaneId].used = true;
	m_clipPlanesIds[newPlaneId].index = previousPlanesCount;
100

101 102 103 104 105
	// Set default parameters values for the new plane
	Geom::Vec3f defaultFirstVec (1.0, 0.0, 0.0);
	Geom::Vec3f defaultSecondVec (0.0, 1.0, 0.0);
	Geom::Vec3f defaultOrigin (0.0, 0.0, 0.0);
	setClipPlaneParamsAll(newPlaneId, defaultFirstVec, defaultSecondVec, defaultOrigin);
106

107 108
	// Recompile shaders (automatically calls updateClippingUniforms)
	recompile();
109

110 111 112 113 114 115 116 117 118 119 120 121 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
	return newPlaneId;
}

void ClippingShader::deleteClipPlane(unsigned int id)
{
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::deleteClipPlane"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::deleteClipPlane"))
		return;

	// Check if the clipping code has been inserted into shader
	if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::deleteClipPlane"))
		return;

	// Shader name string
	std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

	// Use a shader mutator
	ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());

	// Previous planes count
	int previousPlanesCount = getClipPlanesCount();

	// Modify the clip planes count constant in both shader
	if (errorRaiseShaderMutatorFailure(
			   (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount - 1))
			|| (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_PLANES_COUNT", previousPlanesCount - 1)),
			"ClippingShader::deleteClipPlane"))
		return;

	// Reload both shaders
	reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
	reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());

	// Rearrange planes arrays
	m_clipPlanes.erase(m_clipPlanes.begin() + m_clipPlanesIds[id].index);
	for (size_t i; i < m_clipPlanesIds.size(); i++)
	{
		if (m_clipPlanesIds[i].index > m_clipPlanesIds[id].index)
			m_clipPlanesIds[i].index -= 1;
151
	}
152 153 154 155 156 157 158
	m_clipPlanesIds[id].used = false;
	m_clipPlanesEquations.erase(
			m_clipPlanesEquations.begin() + 4*m_clipPlanesIds[id].index,
			m_clipPlanesEquations.begin() + 4*m_clipPlanesIds[id].index + 4);

	// Recompile shaders (automatically calls updateClippingUniforms)
	recompile();
159 160
}

161 162 163 164 165
int ClippingShader::getClipPlanesCount()
{
	return (int)m_clipPlanes.size();
}

166
void ClippingShader::setClipPlaneParamsAll(unsigned int id, Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin)
167
{
168 169 170 171 172 173 174 175
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsAll"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsAll"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
176

177 178 179 180 181 182 183 184 185 186 187 188 189 190
	// Normalize
	Geom::Vec3f vec1Normalized = vec1;
	vec1Normalized.normalize();
	Geom::Vec3f vec2Normalized = vec2;
	vec2Normalized.normalize();

	if ((vec1Normalized != m_clipPlanes[planeIndex].firstVec)
			|| (vec2Normalized != m_clipPlanes[planeIndex].secondVec)
			|| (origin != m_clipPlanes[planeIndex].origin))
	{
		// Copy the given clipping plane parameters
		m_clipPlanes[planeIndex].firstVec = vec1Normalized;
		m_clipPlanes[planeIndex].secondVec = vec2Normalized;
		m_clipPlanes[planeIndex].origin = origin;
191

192
		// Update the plane arrays
193
		updateClipPlaneUniformsArray(id);
194

195 196 197
		// Send again the whole planes equations array to shader
		sendClipPlanesEquationsUniform();
	}
198 199
}

200
void ClippingShader::setClipPlaneParamsFirstVec(unsigned int id, Geom::Vec3f vec1)
201
{
202 203 204 205 206 207 208 209
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsFirstVec"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsFirstVec"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
210

211 212 213 214 215 216 217 218
	// Normalize
	Geom::Vec3f vec1Normalized = vec1;
	vec1Normalized.normalize();

	if (vec1Normalized != m_clipPlanes[planeIndex].firstVec)
	{
		// Copy the given clipping plane parameter
		m_clipPlanes[planeIndex].firstVec = vec1Normalized;
219

220
		// Update the plane arrays
221
		updateClipPlaneUniformsArray(id);
222

223 224 225
		// Send again the whole planes equations array to shader
		sendClipPlanesEquationsUniform();
	}
226 227
}

228
void ClippingShader::setClipPlaneParamsSecondVec(unsigned int id, Geom::Vec3f vec2)
229
{
230 231 232 233 234 235 236 237
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsSecondVec"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsSecondVec"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
238

239 240 241 242 243 244 245 246
	// Normalize
	Geom::Vec3f vec2Normalized = vec2;
	vec2Normalized.normalize();

	if (vec2Normalized != m_clipPlanes[planeIndex].secondVec)
	{
		// Copy the given clipping plane parameter
		m_clipPlanes[planeIndex].secondVec = vec2Normalized;
247

248
		// Update the plane arrays
249
		updateClipPlaneUniformsArray(id);
250

251 252 253
		// Send again the whole planes equations array to shader
		sendClipPlanesEquationsUniform();
	}
254 255
}

256
void ClippingShader::setClipPlaneParamsOrigin(unsigned int id, Geom::Vec3f origin)
257
{
258 259 260 261 262 263 264 265
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::setClipPlaneParamsOrigin"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::setClipPlaneParamsOrigin"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
266

267 268 269 270
	if (origin != m_clipPlanes[planeIndex].origin)
	{
		// Copy the given clipping plane parameter
		m_clipPlanes[planeIndex].origin = origin;
271

272
		// Update the plane arrays
273
		updateClipPlaneUniformsArray(id);
274

275 276 277
		// Send again the whole planes equations array to shader
		sendClipPlanesEquationsUniform();
	}
278 279
}

280
Geom::Vec3f ClippingShader::getClipPlaneParamsFirstVec(unsigned int id)
281
{
282 283 284 285 286 287 288 289
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsFirstVec"))
		return Geom::Vec3f(0.0, 0.0, 0.0);
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsFirstVec"))
		return Geom::Vec3f(0.0, 0.0, 0.0);

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
290 291 292 293 294

	// Return the parameter
	return m_clipPlanes[planeIndex].firstVec;
}

295
Geom::Vec3f ClippingShader::getClipPlaneParamsSecondVec(unsigned int id)
296
{
297 298 299 300 301 302 303 304
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsSecondVec"))
		return Geom::Vec3f(0.0, 0.0, 0.0);
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsSecondVec"))
		return Geom::Vec3f(0.0, 0.0, 0.0);

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
305 306 307 308 309

	// Return the parameter
	return m_clipPlanes[planeIndex].secondVec;
}

310
Geom::Vec3f ClippingShader::getClipPlaneParamsOrigin(unsigned int id)
311
{
312 313 314 315 316 317 318 319
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::getClipPlaneParamsOrigin"))
		return Geom::Vec3f(0.0, 0.0, 0.0);
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::getClipPlaneParamsOrigin"))
		return Geom::Vec3f(0.0, 0.0, 0.0);

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
320 321 322 323 324

	// Return the parameter
	return m_clipPlanes[planeIndex].origin;
}

325
unsigned int ClippingShader::getFreeClipPlaneId()
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
	unsigned int freeId = 0;

	// Free id = either out of current ids vector size or no more used
	while (freeId < m_clipPlanesIds.size())
	{
		if (!m_clipPlanesIds[freeId].used)
			return freeId;
		else
			freeId++;
	}

	return freeId;
}

void ClippingShader::updateClipPlaneUniformsArray(unsigned int id)
{
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipPlanesIds.size()), "ClippingShader::updateClipPlaneUniformsArray"))
		return;
	if (errorRaiseWrongId(m_clipPlanesIds[id].used, "ClippingShader::updateClipPlaneUniformsArray"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;
351

352
	// Update the planes equations array
353 354 355 356 357 358 359 360 361
	Geom::Vec3f planeNormal = m_clipPlanes[planeIndex].firstVec ^ m_clipPlanes[planeIndex].secondVec;
	float d = -(planeNormal * m_clipPlanes[planeIndex].origin);
	m_clipPlanesEquations[4*planeIndex + 0] = planeNormal[0];
	m_clipPlanesEquations[4*planeIndex + 1] = planeNormal[1];
	m_clipPlanesEquations[4*planeIndex + 2] = planeNormal[2];
	m_clipPlanesEquations[4*planeIndex + 3] = d;

}

362

363 364 365 366 367 368 369
/***********************************************
 *
 * 		Sphere Clipping
 *
 ***********************************************/


370
int ClippingShader::addClipSphere()
371
{
372 373 374
	// Check if the clipping code has been inserted into shader
	if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::addClipSphere"))
		return -1;
375

376 377
	// Shader name string
	std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;
378

379 380
	// Use a shader mutator
	ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());
381

382 383
	// Previous spheres count
	int previousSpheresCount = getClipSpheresCount();
384

385 386 387 388 389 390
	// Modify the clip spheres count constant in both shader
	if (errorRaiseShaderMutatorFailure(
			   (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount + 1))
			|| (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount + 1)),
			"ClippingShader::addClipSphere"))
		return -1;
391

392 393 394
	// Reload both shaders
	reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
	reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());
395

396 397
	// Get new sphere id
	unsigned int newSphereId = getFreeClipSphereId();
398

399 400 401 402
	// Resize spheres arrays to the right size
	m_clipSpheres.resize((size_t)(previousSpheresCount + 1));
	m_clipSpheresIds.resize((size_t)newSphereId);
	m_clipSpheresCentersAndRadiuses.resize(4*(size_t)(previousSpheresCount + 1), 0.0);
403

404 405 406
	// Set new sphere id
	m_clipSpheresIds[newSphereId].used = true;
	m_clipSpheresIds[newSphereId].index = previousSpheresCount;
407

408 409 410 411
	// Set default parameters values for the new sphere
	Geom::Vec3f defaultCenter (0.0, 0.0, 0.0);
	float defaultRadius = 10.0;
	setClipSphereParamsAll(newSphereId, defaultCenter, defaultRadius);
412

413 414
	// Recompile shaders (automatically calls updateClippingUniforms)
	recompile();
415

416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
	return newSphereId;
}

void ClippingShader::deleteClipSphere(unsigned int id)
{
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::deleteClipSphere"))
		return;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::deleteClipSphere"))
		return;

	// Check if the clipping code has been inserted into shader
	if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::deleteClipSphere"))
		return;

	// Shader name string
	std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

	// Use a shader mutator
	ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());

	// Previous spheres count
	int previousSpheresCount = getClipSpheresCount();

	// Modify the clip spheres count constant in both shader
	if (errorRaiseShaderMutatorFailure(
			   (!SM.changeIntConstantValue(ShaderMutator::VERTEX_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount - 1))
			|| (!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIP_SPHERES_COUNT", previousSpheresCount - 1)),
			"ClippingShader::deleteClipSphere"))
		return;

	// Reload both shaders
	reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
	reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());

	// Rearrange spheres arrays
	m_clipSpheres.erase(m_clipSpheres.begin() + m_clipSpheresIds[id].index);
	for (size_t i; i < m_clipSpheresIds.size(); i++)
	{
		if (m_clipSpheresIds[i].index > m_clipSpheresIds[id].index)
			m_clipSpheresIds[i].index -= 1;
457
	}
458 459 460 461 462 463 464
	m_clipSpheresIds[id].used = false;
	m_clipSpheresCentersAndRadiuses.erase(
			m_clipSpheresCentersAndRadiuses.begin() + 4*m_clipSpheresIds[id].index,
			m_clipSpheresCentersAndRadiuses.begin() + 4*m_clipSpheresIds[id].index + 4);

	// Recompile shaders (automatically calls updateClippingUniforms)
	recompile();
465 466 467 468 469 470 471
}

int ClippingShader::getClipSpheresCount()
{
	return (int)m_clipSpheres.size();
}

472
void ClippingShader::setClipSphereParamsAll(unsigned int id, Geom::Vec3f center, float radius)
473
{
474 475 476 477 478 479 480 481
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsAll"))
		return;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsAll"))
		return;

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
482 483 484 485 486 487 488 489 490

	if ((center != m_clipSpheres[sphereIndex].center)
			|| (radius != m_clipSpheres[sphereIndex].radius))
	{
		// Copy the given clipping sphere parameters
		m_clipSpheres[sphereIndex].center = center;
		m_clipSpheres[sphereIndex].radius = radius;

		// Update the sphere array
491
		updateClipSphereUniformsArray(id);
492 493 494 495 496 497

		// Send again the whole spheres centers and radiuses array to shader
		sendClipSpheresCentersAndRadiusesUniform();
	}
}

498
void ClippingShader::setClipSphereParamsCenter(unsigned int id, Geom::Vec3f center)
499
{
500 501 502 503 504 505 506 507
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsCenter"))
		return;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsCenter"))
		return;

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
508 509 510 511 512 513 514

	if (center != m_clipSpheres[sphereIndex].center)
	{
		// Copy the given clipping sphere parameter
		m_clipSpheres[sphereIndex].center = center;

		// Update the sphere array
515
		updateClipSphereUniformsArray(id);
516 517 518 519 520 521

		// Send again the whole spheres centers and radiuses array to shader
		sendClipSpheresCentersAndRadiusesUniform();
	}
}

522
void ClippingShader::setClipSphereParamsRadius(unsigned int id, float radius)
523
{
524 525 526 527 528 529 530 531
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::setClipSphereParamsRadius"))
		return;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::setClipSphereParamsRadius"))
		return;

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
532 533 534 535 536 537 538

	if (radius != m_clipSpheres[sphereIndex].radius)
	{
		// Copy the given clipping sphere parameter
		m_clipSpheres[sphereIndex].radius = radius;

		// Update the sphere array
539
		updateClipSphereUniformsArray(id);
540 541 542 543 544 545

		// Send again the whole spheres centers and radiuses array to shader
		sendClipSpheresCentersAndRadiusesUniform();
	}
}

546
Geom::Vec3f ClippingShader::getClipSphereParamsCenter(unsigned int id)
547
{
548 549 550 551 552 553 554 555
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::getClipSphereParamsCenter"))
		return Geom::Vec3f(0.0, 0.0, 0.0);
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::getClipSphereParamsCenter"))
		return Geom::Vec3f(0.0, 0.0, 0.0);

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
556 557 558 559 560

	// Return the parameter
	return m_clipSpheres[sphereIndex].center;
}

561
float ClippingShader::getClipSphereParamsRadius(unsigned int id)
562
{
563 564 565 566 567 568 569 570
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::getClipSphereParamsRadius"))
		return 0.0;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::getClipSphereParamsRadius"))
		return 0.0;

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
571 572 573 574 575

	// Return the parameter
	return m_clipSpheres[sphereIndex].radius;
}

576
unsigned int ClippingShader::getFreeClipSphereId()
577
{
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
	unsigned int freeId = 0;

	// Free id = either out of current ids vector size or no more used
	while (freeId < m_clipSpheresIds.size())
	{
		if (!m_clipSpheresIds[freeId].used)
			return freeId;
		else
			freeId++;
	}

	return freeId;
}

void ClippingShader::updateClipSphereUniformsArray(unsigned int id)
{
	// Check if the given id is valid
	if (errorRaiseWrongId(id > (m_clipSpheresIds.size()), "ClippingShader::updateClipSphereUniformsArray"))
		return;
	if (errorRaiseWrongId(m_clipSpheresIds[id].used, "ClippingShader::updateClipSphereUniformsArray"))
		return;

	// Get the corresponding sphere index
	int sphereIndex = m_clipSpheresIds[id].index;
602 603 604 605 606 607 608 609 610 611

	// Update the spheres centers and radiuses array
	m_clipSpheresCentersAndRadiuses[4*sphereIndex + 0] = m_clipSpheres[sphereIndex].center[0];
	m_clipSpheresCentersAndRadiuses[4*sphereIndex + 1] = m_clipSpheres[sphereIndex].center[1];
	m_clipSpheresCentersAndRadiuses[4*sphereIndex + 2] = m_clipSpheres[sphereIndex].center[2];
	m_clipSpheresCentersAndRadiuses[4*sphereIndex + 3] = m_clipSpheres[sphereIndex].radius;

}


612 613 614 615 616 617 618
/***********************************************
 *
 * 		Global Clipping Stuff
 *
 ***********************************************/


619 620
bool ClippingShader::insertClippingCode()
{
621
	// Check if the code has not already been inserted
622 623 624 625 626 627 628
	if (errorRaiseClippingCodeAlreadyInserted(m_hasClippingCodeBeenInserted, "ClippingShader::insertClippingCode"))
		return false;

	// Check if the vertex and fragment sources are not empty
	if (errorRaiseShaderSourceIsEmpty((getVertexShaderSrc() == NULL), "ClippingShader::insertClippingCode", ShaderMutator::VERTEX_SHADER))
		return false;
	if (errorRaiseShaderSourceIsEmpty((getFragmentShaderSrc() == NULL), "ClippingShader::insertClippingCode", ShaderMutator::FRAGMENT_SHADER))
629
		return false;
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669

	// Check if the shader does not use a geometry shader
	if (errorRaiseShaderUsesGeometryShader((getGeometryShaderSrc() != NULL), "ClippingShader::insertClippingCode"))
		return false;


	// Strings to insert in shader sources

	std::string VS_headInsertion =
	"\n"
	"#define CLIP_PLANES_COUNT 0\n"
	"#define CLIP_SPHERES_COUNT 0\n"
	"\n"
	"#define PLANE_CLIPPING_ENABLED (CLIP_PLANES_COUNT > 0)\n"
	"#define SPHERE_CLIPPING_ENABLED (CLIP_SPHERES_COUNT > 0)\n"
	"\n"
	"#define CLIPPING_ENABLED (PLANE_CLIPPING_ENABLED || SPHERE_CLIPPING_ENABLED)\n"
	"\n"
	"#if CLIPPING_ENABLED\n"
	"	VARYING_VERT vec3 clip_nonTransformedPos;\n"
	"#endif\n"
	"\n";

	std::string VS_mainEndInsertion =
	"\n"
	"	#if CLIPPING_ENABLED\n"
	"		// Pass the non transformed vertex position to the fragment shader for clipping\n"
	"		clip_nonTransformedPos = VertexPosition;\n"
	"	#endif\n";

	std::string FS_headInsertion =
	"\n"
	"#define CLIP_PLANES_COUNT 0\n"
	"#define CLIP_SPHERES_COUNT 0\n"
	"\n"
	"#define PLANE_CLIPPING_ENABLED (CLIP_PLANES_COUNT > 0)\n"
	"#define SPHERE_CLIPPING_ENABLED (CLIP_SPHERES_COUNT > 0)\n"
	"\n"
	"#define CLIPPING_ENABLED (PLANE_CLIPPING_ENABLED || SPHERE_CLIPPING_ENABLED)\n"
	"\n"
670 671 672 673 674 675 676
	"// In following clipping modes, pixels may be deleted :\n"
	"//  - OR : only after being matched with every object\n"
	"//  - AND : on the fly as soon as one object does not match\n"
	"#define CLIPPING_MODE_AND 0\n"
	"#define CLIPPING_MODE_OR 1\n"
	"#define CLIPPING_MODE 0\n"
	"\n"
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
	"#if CLIPPING_ENABLED\n"
	"\n"
	"	#if PLANE_CLIPPING_ENABLED\n"
	"		uniform vec4 clip_clipPlanesEquations[CLIP_PLANES_COUNT];\n"
	"	#endif\n"
	"\n"
	"	#if SPHERE_CLIPPING_ENABLED\n"
	"		uniform vec4 clip_clipSpheresCentersAndRadiuses[CLIP_SPHERES_COUNT];\n"
	"	#endif\n"
	"\n"
	"	uniform float clip_clipColorAttenuationFactor;\n"
	"\n"
	"	VARYING_FRAG vec3 clip_nonTransformedPos;\n"
	"\n"
	"#endif\n"
	"\n"
	"#if CLIPPING_ENABLED\n"

	"	float clip_doClippingAndGetClippingDistance()\n"
	"	{\n"
	"		// Distance to the nearest clipping object\n"
	"		float minDistanceToClipping = -1.0;\n"
	"\n"
700 701 702 703 704 705
	"		// OR clipping mode needs a boolean to know if the pixel must be clipped or not\n"
	"		// By default set to true : one clipping object matched sets it to false\n"
	"		#if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
	"			bool discardPixel = true;\n"
	"		#endif\n"
	"\n"
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
	"		#if PLANE_CLIPPING_ENABLED\n"
	"\n"
	"			// Do clipping for each plane\n"
	"			for (int i = 0; i < CLIP_PLANES_COUNT; i++)\n"
	"			{\n"
	"				// Get the current plane equation\n"
	"				vec4 currClipPlane = clip_clipPlanesEquations[i];\n"
	"\n"
	"				// If the plane normal is zero, use a default normal vector (0.0, 0.0, 1.0)\n"
	"				float clipPlaneNormalLength = length(currClipPlane.xyz);\n"
	"				if (clipPlaneNormalLength == 0.0)\n"
	"				{\n"
	"					currClipPlane.z = 1.0;\n"
	"					clipPlaneNormalLength = 1.0;\n"
	"				}\n"
	"\n"
	"				// Signed distance between the point and the plane\n"
	"				float distanceToPlane = dot(clip_nonTransformedPos, currClipPlane.xyz);\n"
	"				distanceToPlane += currClipPlane.w;\n"
	"				distanceToPlane /= clipPlaneNormalLength;\n"
	"\n"
	"				// Keep the fragment only if it is 'above' the plane\n"
728 729 730 731 732 733 734
	"				if (distanceToPlane > 0.0)\n"
	"				{\n"
	"					// AND clipping mode discards at first unmatched clipping object\n"
	"					#if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
	"						discard;\n"
	"					#endif\n"
	"				}\n"
735 736
	"				else\n"
	"				{\n"
737 738 739 740 741
	"					// In OR clipping mode, one match = no pixel clipping\n"
	"					#if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
	"						discardPixel = false;\n"
	"					#endif\n"
	"\n"
742 743
	"					// Keep the distance to the nearest plane\n"
	"					if (minDistanceToClipping < 0.0)\n"
744
	"						minDistanceToClipping = abs(distanceToPlane);\n"
745
	"					else\n"
746
	"						minDistanceToClipping = min(minDistanceToClipping, abs(distanceToPlane));\n"
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
	"				}\n"
	"			}\n"
	"\n"
	"		#endif\n"
	"\n"
	"		#if SPHERE_CLIPPING_ENABLED\n"

	"			// Do clipping for each sphere\n"
	"			for (int i = 0; i < CLIP_SPHERES_COUNT; i++)\n"
	"			{\n"
	"				// Get the current sphere center and radius\n"
	"				vec3 currClipSphereCenter = clip_clipSpheresCentersAndRadiuses[i].xyz;\n"
	"				float currClipSphereRadius = clip_clipSpheresCentersAndRadiuses[i].w;\n"
	"\n"
	"				// Signed distance between the point and the sphere\n"
	"				float distanceToSphere = length(clip_nonTransformedPos - currClipSphereCenter);\n"
763 764 765 766
	"				distanceToSphere -= abs(currClipSphereRadius);\n"
	"\n"
	"				// If the sphere radius is negative, this inverses the clipping effect\n"
	"				distanceToSphere *= sign(currClipSphereRadius);\n"
767 768 769
	"\n"
	"				// Keep the fragment only if it is inside the sphere\n"
	"				if (distanceToSphere > 0.0)\n"
770 771 772 773 774 775
	"				{\n"
	"					// AND clipping mode discards at first unmatched clipping object\n"
	"					#if (CLIPPING_MODE == CLIPPING_MODE_AND)\n"
	"						discard;\n"
	"					#endif\n"
	"				}\n"
776 777
	"				else\n"
	"				{\n"
778 779 780 781 782
	"					// In OR clipping mode, one match = no pixel clipping\n"
	"					#if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
	"						discardPixel = false;\n"
	"					#endif\n"
	"\n"
783 784
	"					// Keep the distance to the nearest sphere\n"
	"					if (minDistanceToClipping < 0.0)\n"
785
	"						minDistanceToClipping = abs(distanceToSphere);\n"
786
	"					else\n"
787
	"						minDistanceToClipping = min(minDistanceToClipping, abs(distanceToSphere));\n"
788 789 790 791 792
	"				}\n"
	"			}\n"
	"\n"
	"		#endif\n"
	"\n"
793 794 795 796 797 798
	"		// In OR clipping mode, the pixel may be deleted only after being matched with every object\n"
	"		#if (CLIPPING_MODE == CLIPPING_MODE_OR)\n"
	"			if (discardPixel)\n"
	"				discard;\n"
	"		#endif\n"
	"\n"
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
	"		return minDistanceToClipping;\n"
	"	}\n"
	"\n"
	"#endif\n"
	"\n";

	std::string FS_mainBeginInsertion =
	"\n"
	"	#if CLIPPING_ENABLED\n"
	"		// Apply clipping and get the clipping distance\n"
	"		float clip_minDistanceToClipping = clip_doClippingAndGetClippingDistance();\n"
	"	#endif\n";

	std::string FS_mainEndInsertion =
	"\n"
	"	#if CLIPPING_ENABLED\n"
	"		// Attenuate the final fragment color depending on its distance to the clipping\n"
	"		gl_FragColor.rgb /= (1.0 + clip_minDistanceToClipping * clip_clipColorAttenuationFactor);\n"
	"	#endif\n";

	// Shader name string
	std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

	// Use a shader mutator
	ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());

	// First check if the vertex shader contains the VertexPosition attribute
	if (errorRaiseVariableNotFoundInShader(!SM.containsVariableDeclaration(ShaderMutator::VERTEX_SHADER, "VertexPosition"), "ClippingShader::insertClippingCode", ShaderMutator::VERTEX_SHADER, "VertexPosition"))
		return false;

	// Modify vertex shader source code
830 831 832 833 834
	if (errorRaiseShaderMutatorFailure(
			   (!SM.insertCodeBeforeMainFunction(ShaderMutator::VERTEX_SHADER, VS_headInsertion))
			|| (!SM.insertCodeAtMainFunctionBeginning(ShaderMutator::VERTEX_SHADER, VS_mainEndInsertion)),
			"ClippingShader::insertClippingCode"))
		return false;
835 836

	// Modify fragment shader source code
837 838 839 840 841 842 843
	if (errorRaiseShaderMutatorFailure(
			   (!SM.setMinShadingLanguageVersion(ShaderMutator::FRAGMENT_SHADER, 120)) // Following code insertions need at least shading language 120 (GLSL arrays)
			|| (!SM.insertCodeBeforeMainFunction(ShaderMutator::FRAGMENT_SHADER, FS_headInsertion))
			|| (!SM.insertCodeAtMainFunctionBeginning(ShaderMutator::FRAGMENT_SHADER, FS_mainBeginInsertion))
			|| (!SM.insertCodeAtMainFunctionEnd(ShaderMutator::FRAGMENT_SHADER, FS_mainEndInsertion)),
			"ClippingShader::insertClippingCode"))
		return false;
844 845 846 847 848 849 850 851 852 853 854 855 856

	// Reload both shaders
	reloadVertexShaderFromMemory(SM.getModifiedVertexShaderSrc().c_str());
	reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());

	// Recompile shaders (automatically calls updateClippingUniforms)
	recompile();

	m_hasClippingCodeBeenInserted = true;

	return true;
}

857 858
void ClippingShader::setClipColorAttenuationFactor(float colorAttenuationFactor)
{
859
	if (colorAttenuationFactor != m_clipColorAttenuationFactor)
860 861 862 863 864 865 866 867 868 869 870 871 872 873
	{
		// Copy the given value
		m_clipColorAttenuationFactor = colorAttenuationFactor;

		// Send again the uniform to shader
		sendClipColorAttenuationFactorUniform();
	}
}

float ClippingShader::getClipColorAttenuationFactor()
{
	return m_clipColorAttenuationFactor;
}

874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
void ClippingShader::setClipMode(clippingMode clipMode)
{
	if (clipMode != m_clipMode)
	{
		// Check if the clipping code has been inserted into shader
		if (errorRaiseClippingCodeNotInserted(!m_hasClippingCodeBeenInserted, "ClippingShader::setClipPlanesCount"))
			return;

		// Shader name string
		std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

		// Copy the given value
		m_clipMode = clipMode;

		// Use a shader mutator
		ShaderMutator SM(shaderName, getVertexShaderSrc(), getFragmentShaderSrc());

		// Change clipping mode constant
		int newConstantValue;
		switch (clipMode)
		{
			case CLIPPING_MODE_AND :
				newConstantValue = 0;
				break;

			case CLIPPING_MODE_OR :
				newConstantValue = 1;
				break;

			default :
				newConstantValue = 0;
				break;
		}
907 908 909 910
		if (errorRaiseShaderMutatorFailure(
				(!SM.changeIntConstantValue(ShaderMutator::FRAGMENT_SHADER, "CLIPPING_MODE", newConstantValue)),
				"ClippingShader::setClipMode"))
			return;
911 912 913 914 915 916 917 918 919 920 921 922 923 924

		// Reload modified shader
		reloadFragmentShaderFromMemory(SM.getModifiedFragmentShaderSrc().c_str());

		// Recompile shaders (automatically calls updateClippingUniforms)
		recompile();
	}
}

ClippingShader::clippingMode ClippingShader::getClipMode()
{
	return m_clipMode;
}

925 926 927 928 929 930 931 932 933 934

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


void ClippingShader::updateClippingUniforms()
{
935 936 937 938 939 940 941 942 943 944
	// Plane clipping uniforms
	if (getClipPlanesCount() > 0)
	{
		// Get uniform location
		m_unif_clipPlanesEquations = glGetUniformLocation(program_handler(), "clip_clipPlanesEquations");
		errorRaiseUniformNotFoundInShader((m_unif_clipPlanesEquations == -1), "ClippingShader::updateClippingUniforms", "clip_clipPlanesEquations");

		// Send again uniform value
		sendClipPlanesEquationsUniform();
	}
945

946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962
	// Sphere clipping uniforms
	if (getClipSpheresCount() > 0)
	{
		// Get uniform location
		m_unif_clipSpheresCentersAndRadiuses = glGetUniformLocation(program_handler(), "clip_clipSpheresCentersAndRadiuses");
		errorRaiseUniformNotFoundInShader((m_unif_clipSpheresCentersAndRadiuses == -1), "ClippingShader::updateClippingUniforms", "clip_clipSpheresCentersAndRadiuses");

		// Send again uniform value
		sendClipSpheresCentersAndRadiusesUniform();
	}

	// Global clipping uniforms
	if ((getClipPlanesCount() > 0) || (getClipSpheresCount() > 0))
	{
		// Get uniform location
		m_unif_clipColorAttenuationFactor = glGetUniformLocation(program_handler(), "clip_clipColorAttenuationFactor");
		errorRaiseUniformNotFoundInShader((m_unif_clipColorAttenuationFactor == -1), "ClippingShader::updateClippingUniforms", "clip_clipColorAttenuationFactor");
963

964 965 966
		// Send again uniform value
		sendClipColorAttenuationFactorUniform();
	}
967 968 969 970 971 972 973 974
}

void ClippingShader::sendClipPlanesEquationsUniform()
{
	bind();
	glUniform4fv(m_unif_clipPlanesEquations, getClipPlanesCount(), &m_clipPlanesEquations.front());
}

975 976 977 978 979 980
void ClippingShader::sendClipSpheresCentersAndRadiusesUniform()
{
	bind();
	glUniform4fv(m_unif_clipSpheresCentersAndRadiuses, getClipSpheresCount(), &m_clipSpheresCentersAndRadiuses.front());
}

981 982 983 984 985 986 987 988 989 990 991 992 993 994
void ClippingShader::sendClipColorAttenuationFactorUniform()
{
	bind();
	glUniform1f(m_unif_clipColorAttenuationFactor, m_clipColorAttenuationFactor);
}


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


995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
bool ClippingShader::errorRaiseShaderMutatorFailure(bool condition, const std::string& location)
{
	if (condition)
	{
		CGoGNerr
		<< "ERROR - "
		<< location
		<< " - Shader Mutator failure"
		<< CGoGNendl;
	}

	return condition;
}

1009
bool ClippingShader::errorRaiseShaderSourceIsEmpty(bool condition, const std::string& location, ShaderMutator::shaderSrcType shaderType)
1010 1011 1012
{
	if (condition)
	{
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
		std::string shaderName;
		switch (shaderType)
		{
			case ShaderMutator::VERTEX_SHADER :
				shaderName = m_nameVS;
				break;

			case ShaderMutator::FRAGMENT_SHADER :
				shaderName = m_nameFS;
				break;

			case ShaderMutator::GEOMETRY_SHADER :
				shaderName = m_nameGS;
				break;

			default :
				shaderName = m_nameVS;
				break;
		}
1032 1033 1034 1035 1036

		CGoGNerr
		<< "ERROR - "
		<< location
		<< " - Could not process shader "
1037
		<< shaderName
1038
		<< " source code : shader source is empty"
1039 1040 1041
		<< CGoGNendl;
	}

1042 1043 1044 1045 1046 1047
	return condition;
}

bool ClippingShader::errorRaiseShaderUsesGeometryShader(bool condition, const std::string& location)
{
	if (condition)
1048
	{
1049 1050
		std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

1051 1052
		CGoGNerr
		<< "ERROR - "
1053 1054
		<< location
		<< " - Could not process shader "
1055
		<< shaderName
1056
		<< " source code : unable to add clipping to a shader which uses a geometry shader"
1057 1058 1059
		<< CGoGNendl;
	}

1060
	return condition;
1061 1062
}

1063
bool ClippingShader::errorRaiseVariableNotFoundInShader(bool condition, const std::string& location, ShaderMutator::shaderSrcType shaderType, const std::string& varName)
1064
{
1065 1066 1067
	if (condition)
	{
		std::string shaderName;
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085
		switch (shaderType)
		{
			case ShaderMutator::VERTEX_SHADER :
				shaderName = m_nameVS;
				break;

			case ShaderMutator::FRAGMENT_SHADER :
				shaderName = m_nameFS;
				break;

			case ShaderMutator::GEOMETRY_SHADER :
				shaderName = m_nameGS;
				break;

			default :
				shaderName = m_nameVS;
				break;
		}
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098

		CGoGNerr
		<< "ERROR - "
		<< location
		<< " - Could not process shader "
		<< shaderName
		<< " source code : "
		<< varName
		<< " not found"
		<< CGoGNendl;
	}

	return condition;
1099
}
1100
bool ClippingShader::errorRaiseWrongId(bool condition, const std::string& location)
1101 1102 1103 1104 1105 1106
{
	if (condition)
	{
		CGoGNerr
		<< "ERROR - "
		<< location
1107
		<< " - Given ID is not valid"
1108 1109
		<< CGoGNendl;
	}
1110

1111 1112 1113 1114
	return condition;
}

bool ClippingShader::errorRaiseUniformNotFoundInShader(bool condition, const std::string& location, const std::string& uniformName)
1115
{
1116 1117 1118 1119 1120 1121 1122
	if (condition)
	{
		std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

		CGoGNerr
		<< "ERROR - "
		<< location
1123
		<< " - Uniform "
1124 1125 1126 1127 1128 1129 1130
		<< uniformName
		<< " not found in shader "
		<< shaderName
		<< CGoGNendl;
	}

	return condition;
1131 1132
}

1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
bool ClippingShader::errorRaiseClippingCodeAlreadyInserted(bool condition, const std::string& location)
{
	if (condition)
	{
		std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

		CGoGNerr
		<< "ERROR - "
		<< location
		<< " - Clipping code has already been inserted into shader "
		<< shaderName
		<< CGoGNendl;
	}

	return condition;
}

bool ClippingShader::errorRaiseClippingCodeNotInserted(bool condition, const std::string& location)
{
	if (condition)
	{
		std::string shaderName = m_nameVS + "/" + m_nameFS + "/" + m_nameGS;

		CGoGNerr
		<< "ERROR - "
		<< location
		<< " - Clipping code must be inserted into shader "
		<< shaderName
		<< " before adding clipping objects"
		<< CGoGNendl;
	}

	return condition;
}

1168 1169 1170
} // namespace Utils

} // namespace CGoGN