clippingShader.h 4.89 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 the plane equation for plane clipping
59
	 * @warning planeIndex starts at 0
60
	 * @param clipPlane plane equation
61
	 * @param planeIndex index of plane to modify
62
	 */
63
	void setClippingPlaneEquation(Geom::Vec4f clipPlane, int planeIndex = 0);
64
	
65 66
	/**
	 * get the plane equation for plane clipping
67 68
	 * @warning planeIndex starts at 0
	 * @param planeIndex index of plane to get
69
	 */
70
	Geom::Vec4f getClippingPlaneEquation(int planeIndex = 0);
71 72 73 74 75

	/**
	 * set the plane quaternion for plane clipping
	 * @param quat plane quaternion
	 */
76
	//void setClippingPlaneQuaternion(float quat[4]);
77 78 79 80

	/**
	 * get the plane quaternion for plane clipping
	 */
81
	//Geom::Vec4f getClippingPlaneQuaternion();
82

83 84
	/**
	 * set the color attenuation factor for clipping
85
	 * @param colorAttenuationFactor color attenuation factor
86 87 88
	 */
	void setClippingColorAttenuationFactor(float colorAttenuationFactor);

89 90 91 92 93
	/**
	 * get the color attenuation factor for clipping
	 */
	float getClippingColorAttenuationFactor();

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

107
	/**
108
	 * update uniforms (get their locations and resend their values) for clipping
109 110 111
	 */
	void updateClippingUniforms();

112 113 114 115 116
	/**
	 * displays a quad corresponding to the current clipping plane position and orientation
	 */
	void displayClippingPlane();

117 118 119 120

private:

	/**
121 122 123 124 125 126 127 128 129
	 * sends the clipping planes uniform to shader
	 */
	void sendClippingPlanesUniform();

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

130 131 132 133 134 135 136 137 138 139
	/**
	 * stored original vertex shader source code (without clipping)
	 */
	std::string originalVertShaderSrc;

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

140 141
	/**
	 * clip planes equations (a, b, c, d)*planes count
142
	 */
143
	std::vector<float> m_clipPlanesEquations;
144
	
145 146 147
	/**
	 * clip plane quaternion
	 */
148
	//float m_clipPlaneQuaternion[4];
149

150
	/**
151
	 * clip planes vector uniform id
152
	 */
153
	GLint m_unif_clipPlanes;
154 155 156 157 158 159 160 161 162 163 164
	
	/**
	 * color attenuation factor
	 */
	float m_colorAttenuationFactor;
	
	/**
	 * color attenuation factor uniform id
	 */
	GLint m_unif_colorAttenuationFactor;

165 166 167 168 169
	/**
	 * plane drawer
	 */
	Drawer* m_planeDrawer;

170 171 172 173 174 175 176 177
};


} // namespace Utils

} // namespace CGoGN

#endif