clippingShader.h 4.75 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
/*******************************************************************************
* 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"
30 31 32
#include "glm/glm.hpp"
#include "Geometry/matrix.h"
#include "Utils/trackball.h"
33 34
#include "Utils/cgognStream.h"
#include "Utils/shaderMutator.h"
35
#include "Utils/drawer.h"
36
#include <string>
37 38
#include <sstream>
#include <vector>
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

namespace CGoGN
{

namespace Utils
{

class ClippingShader : public GLSLShader
{

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

55 56 57 58 59
	/**
	 * destructor
	 */
	~ClippingShader();

60 61
	/**
	 * set the plane equation for plane clipping
62
	 * @warning planeIndex starts at 0
63
	 * @param clipPlane plane equation
64
	 * @param planeIndex index of plane to modify
65
	 */
66
	void setClippingPlaneEquation(Geom::Vec4f clipPlane, int planeIndex = 0);
67
	
68 69
	/**
	 * get the plane equation for plane clipping
70 71
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of plane to get
72
	 */
73
	Geom::Vec4f getClippingPlaneEquation(int planeIndex = 0);
74 75 76 77 78

	/**
	 * set the plane quaternion for plane clipping
	 * @param quat plane quaternion
	 */
79
	//void setClippingPlaneQuaternion(float quat[4]);
80 81 82 83

	/**
	 * get the plane quaternion for plane clipping
	 */
84
	//Geom::Vec4f getClippingPlaneQuaternion();
85

86 87
	/**
	 * set the color attenuation factor for clipping
88
	 * @param colorAttenuationFactor color attenuation factor
89 90 91
	 */
	void setClippingColorAttenuationFactor(float colorAttenuationFactor);

92 93 94 95 96
	/**
	 * get the color attenuation factor for clipping
	 */
	float getClippingColorAttenuationFactor();

97 98 99
	/**
	 * insert plane clipping instructions into vertex and fragment shader source code
	 * - does not modify the geometry shader source code
100 101
	 * @param planesCount the clipping planes count to use
	 * @warning this function is designed for shaders which *do not* use a geometry shader
102
	 */
103
	void setPlaneClipping(int planesCount);
104
	
105 106 107 108 109
	/**
	 * get the clipping planes count used for plane clipping
	 */
	int getClippingPlanesCount() { return (int)m_clipPlanesEquations.size(); }

110
	/**
111
	 * update uniforms (get their locations and resend their values) for clipping
112 113 114
	 */
	void updateClippingUniforms();

115 116 117 118 119
	/**
	 * displays a quad corresponding to the current clipping plane position and orientation
	 */
	void displayClippingPlane();

120 121 122 123

private:

	/**
124 125 126 127 128 129 130 131 132 133 134
	 * sends the clipping planes uniform to shader
	 */
	void sendClippingPlanesUniform();

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

	/**
	 * clip planes equations (a, b, c, d)*planes count
135
	 */
136
	std::vector<float> m_clipPlanesEquations;
137
	
138 139 140
	/**
	 * clip plane quaternion
	 */
141
	//float m_clipPlaneQuaternion[4];
142

143
	/**
144
	 * clip planes vector uniform id
145
	 */
146
	GLint m_unif_clipPlanes;
147 148 149 150 151 152 153 154 155 156 157
	
	/**
	 * color attenuation factor
	 */
	float m_colorAttenuationFactor;
	
	/**
	 * color attenuation factor uniform id
	 */
	GLint m_unif_colorAttenuationFactor;

158 159 160 161 162
	/**
	 * plane drawer
	 */
	Drawer* m_planeDrawer;

163 164 165 166 167 168 169 170
};


} // namespace Utils

} // namespace CGoGN

#endif