clippingShader.h 6.67 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 46 47 48 49 50 51

namespace CGoGN
{

namespace Utils
{

class ClippingShader : public GLSLShader
{

public:
	/**
	 * constructor
	 */
	ClippingShader();

52 53 54 55 56
	/**
	 * destructor
	 */
	~ClippingShader();

57
	/**
58
	 * set all parameters for one clipping plane
59
	 * @warning planeIndex starts at 0
60 61 62 63
	 * @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
64
	 */
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
	void setClippingPlane(Geom::Vec3f vec1, Geom::Vec3f vec2, Geom::Vec3f origin, int planeIndex = 0);

	/**
	 * set first vector parameter for one clipping plane
	 * @warning planeIndex starts at 0
	 * @param vec1 first basis vector
	 * @param planeIndex index of the plane to modify
	 */
	void setClippingPlaneFirstVec(Geom::Vec3f vec1, int planeIndex = 0);

	/**
	 * set second vector parameter for one clipping plane
	 * @warning planeIndex starts at 0
	 * @param vec2 second basis vector
	 * @param planeIndex index of the plane to modify
	 */
	void setClippingPlaneSecondVec(Geom::Vec3f vec2, int planeIndex = 0);
82
	
83
	/**
84
	 * set origin parameter for one clipping plane
85
	 * @warning planeIndex starts at 0
86 87
	 * @param origin point of the plane that will be used as origin to display it
	 * @param planeIndex index of the plane to modify
88
	 */
89
	void setClippingPlaneOrigin(Geom::Vec3f origin, int planeIndex = 0);
90 91

	/**
92 93 94
	 * get first parameter for one clipping plane
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
95
	 */
96
	Geom::Vec3f getClippingPlaneFirstVec(int planeIndex = 0);
97 98

	/**
99 100 101 102 103 104 105 106 107 108
	 * get second vector parameter for one clipping plane
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
	 */
	Geom::Vec3f getClippingPlaneSecondVec(int planeIndex = 0);

	/**
	 * get origin parameter for one clipping plane
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of the plane to modify
109
	 */
110
	Geom::Vec3f getClippingPlaneOrigin(int planeIndex = 0);
111

112 113
	/**
	 * set the color attenuation factor for clipping
114
	 * @param colorAttenuationFactor color attenuation factor
115 116 117
	 */
	void setClippingColorAttenuationFactor(float colorAttenuationFactor);

118 119 120
	/**
	 * get the color attenuation factor for clipping
	 */
121
	float getClippingColorAttenuationFactor() { return m_colorAttenuationFactor; }
122

123
	/**
124 125 126
	 * set the clipping planes count used for plane clipping
	 * - insert plane clipping instructions into vertex and fragment shader source code
	 * but does not modify the geometry shader source code
127 128
	 * @param planesCount the clipping planes count to use
	 * @warning this function is designed for shaders which *do not* use a geometry shader
129
	 */
130
	void setClippingPlanesCount(int planesCount);
131
	
132 133 134
	/**
	 * get the clipping planes count used for plane clipping
	 */
135
	int getClippingPlanesCount() { return (int)m_clipPlanes.size(); }
136

137
	/**
138
	 * update uniforms (get their locations and send their values again) for clipping
139 140 141
	 */
	void updateClippingUniforms();

142
	/**
143
	 * display all clipping planes
144
	 */
145 146 147 148 149 150 151 152 153 154 155 156
	void displayClippingPlanes();

	/**
	 * set the plane display size
	 * @param size the new size
	 */
	void setPlaneDisplaySize(float size) { m_planeDisplaySize = size; }

	/**
	 * get the plane display size
	 */
	float getPlaneDisplaySize() { return m_planeDisplaySize; }
157

158 159 160

private:

161 162 163 164 165 166 167 168
	/**
	 * clipping planes structure
	 */
	struct clipPlane
	{
		Geom::Vec3f firstVec, secondVec, origin;
	};

169
	/**
170 171 172 173 174 175 176 177 178
	 * sends the clipping planes uniform to shader
	 */
	void sendClippingPlanesUniform();

	/**
	 * sends the color attenuation factor uniform to shader
	 */
	void sendColorAttenuationFactorUniform();

179
	/**
180 181 182 183 184 185 186
	 * update VBO for one plane(recalculate quad)
	 * @param planeIndex index of the plane
	 */
	void updateClippingPlaneVBO(int planeIndex);

	/**
	 * original vertex shader source code (without clipping)
187 188 189 190
	 */
	std::string originalVertShaderSrc;

	/**
191
	 * original fragment shader source code (without clipping)
192 193 194
	 */
	std::string originalFragShaderSrc;

195
	/**
196
	 * clip planes array
197
	 */
198 199
	std::vector<clipPlane> m_clipPlanes;

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

206
	/**
207
	 * clip planes equations vector uniform id
208
	 */
209
	GLint m_unif_clipPlanesEquations;
210 211 212 213 214 215 216 217 218 219 220
	
	/**
	 * color attenuation factor
	 */
	float m_colorAttenuationFactor;
	
	/**
	 * color attenuation factor uniform id
	 */
	GLint m_unif_colorAttenuationFactor;

221
	/**
222 223 224 225 226 227
	 * clip planes drawers array
	 */
	std::vector<Drawer*> m_clipPlanesDrawers;

	/**
	 * plane display size
228
	 */
229
	float m_planeDisplaySize;
230

231 232 233 234 235 236 237 238
};


} // namespace Utils

} // namespace CGoGN

#endif