shaderExplodeVolumesLines.cpp 4.49 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <string.h>
#include "Utils/Shaders/shaderExplodeVolumesLines.h"

namespace CGoGN
{

namespace Utils
{
#include "shaderExplodeVolumesLines.vert"
#include "shaderExplodeVolumesLines.frag"
#include "shaderExplodeVolumesLines.geom"


ShaderExplodeVolumesLines::ShaderExplodeVolumesLines()
{
	m_nameVS = "ShaderExplodeVolumesLines_vs";
	m_nameFS = "ShaderExplodeVolumesLines_fs";
	m_nameGS = "ShaderExplodeVolumesLines_gs";

	std::string glxvert(*GLSLShader::DEFINES_GL);
	glxvert.append(vertexShaderText);

47
	std::string glxgeom(GLSLShader::defines_Geom("triangles", "line_strip", 4));
48 49 50 51 52 53 54 55 56 57 58 59
	glxgeom.append(geometryShaderText);

	std::string glxfrag(*GLSLShader::DEFINES_GL);
	glxfrag.append(fragmentShaderText);

	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_TRIANGLES , GL_LINE_STRIP,4);

	getLocations();

	//Default values
	m_explodeV = 0.9f;
	m_color = Geom::Vec4f(0.05f, 0.05f, 0.05f, 0.0f);
60 61
	m_plane   = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f);
	setParams(m_explodeV, m_color, m_plane);
62 63 64 65
}

void ShaderExplodeVolumesLines::getLocations()
{
66 67 68
	*m_unif_explodeV  = glGetUniformLocation(program_handler(),"explodeV");
	*m_unif_color  = glGetUniformLocation(program_handler(),"color");
	*m_unif_plane   = glGetUniformLocation(program_handler(),"plane");
69 70 71 72 73 74 75 76
}

void ShaderExplodeVolumesLines::setAttributePosition(VBO* vbo)
{
	m_vboPos = vbo;
	bindVA_VBO("VertexPosition", vbo);
}

77
void ShaderExplodeVolumesLines::setParams(float explV, const Geom::Vec4f& color, const Geom::Vec4f& plane)
78 79 80
{
	m_explodeV = explV;
	m_color = color;
81
	m_plane = plane;
82 83 84

	bind();

85 86 87
	glUniform1f(*m_unif_explodeV, explV);
	glUniform4fv(*m_unif_color, 1, color.data());
	glUniform4fv(*m_unif_plane,    1, m_plane.data());
88 89 90 91 92 93 94
	unbind(); // ??
}

void ShaderExplodeVolumesLines::setExplodeVolumes(float explode)
{
	m_explodeV = explode;
	bind();
95
	glUniform1f(*m_unif_explodeV, explode);
96 97 98 99 100 101 102
}


void ShaderExplodeVolumesLines::setColor(const Geom::Vec4f& color)
{
	m_color = color;
	bind();
103
	glUniform4fv(*m_unif_color,1, color.data());
104 105
}

106 107 108 109
void ShaderExplodeVolumesLines::setClippingPlane(const Geom::Vec4f& plane)
{
	m_plane = plane;
	bind();
110
	glUniform4fv(*m_unif_plane,1, plane.data());
111
}
112 113 114

void ShaderExplodeVolumesLines::restoreUniformsAttribs()
{
115 116 117
	*m_unif_explodeV   = glGetUniformLocation(program_handler(),"explodeV");
	*m_unif_color   = glGetUniformLocation(program_handler(),"color");
	*m_unif_plane   = glGetUniformLocation(program_handler(),"plane");
118 119

	bind();
120 121 122
	glUniform1f (*m_unif_explodeV, m_explodeV);
	glUniform4fv(*m_unif_color,  1, m_color.data());
	glUniform4fv(*m_unif_plane,    1, m_plane.data());
123 124 125 126 127 128 129 130

	bindVA_VBO("VertexPosition", m_vboPos);
	unbind();
}

} // namespace Utils

} // namespace CGoGN