shaderVectorPerVertex.cpp 3.78 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
#include "Utils/Shaders/shaderVectorPerVertex.h"
26 27 28

namespace CGoGN
{
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
29

30 31
namespace Utils
{
32 33 34
#include "shaderVectorPerVertex.vert"
#include "shaderVectorPerVertex.geom"
#include "shaderVectorPerVertex.frag"
35

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
36 37 38 39

ShaderVectorPerVertex::ShaderVectorPerVertex() :
	m_scale(1.0f),
	m_color(Geom::Vec4f(1.0f, 0.0f, 0.0f, 0.0f))
40
{
41 42 43 44 45

	m_nameVS = "ShaderVectorPerVertex_vs";
	m_nameFS = "ShaderVectorPerVertex_fs";
	m_nameGS = "ShaderVectorPerVertex_gs";

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

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
49
	std::string glxgeom = GLSLShader::defines_Geom("points", "line_strip", 4);
50 51 52 53 54
	glxgeom.append(geometryShaderText);

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

Sylvain Thery's avatar
Sylvain Thery committed
55
	loadShadersFromMemory(glxvert.c_str(), glxfrag.c_str(), glxgeom.c_str(), GL_POINTS, GL_LINE_STRIP,2);
56

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
57
	// get and fill uniforms
58
	bind();
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
59 60
	getLocations();
	sendParams();
61 62
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
63
void ShaderVectorPerVertex::getLocations()
64
{
65 66
	*m_uniform_scale = glGetUniformLocation(this->program_handler(), "vectorScale");
	*m_uniform_color = glGetUniformLocation(this->program_handler(), "vectorColor");
67 68
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
69
void ShaderVectorPerVertex::sendParams()
70
{
71 72
	glUniform1f(*m_uniform_scale, m_scale);
	glUniform4fv(*m_uniform_color, 1, m_color.data());
73 74
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
75
void ShaderVectorPerVertex::setScale(float scale)
76 77
{
	bind();
78
	glUniform1f(*m_uniform_scale, scale);
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
79
	m_scale = scale;
80 81
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
82
void ShaderVectorPerVertex::setColor(const Geom::Vec4f& color)
83 84
{
	bind();
85
	glUniform4fv(*m_uniform_color, 1, color.data());
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
86 87 88 89 90 91 92
	m_color = color;
}

unsigned int ShaderVectorPerVertex::setAttributePosition(VBO* vbo)
{
	m_vboPos = vbo;
	return bindVA_VBO("VertexPosition", vbo);
93 94
}

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
95 96 97 98
unsigned int ShaderVectorPerVertex::setAttributeVector(VBO* vbo)
{
	m_vboVec = vbo;
	return bindVA_VBO("VertexVector", vbo);
99
}
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
100 101 102 103 104

void ShaderVectorPerVertex::restoreUniformsAttribs()
{
	getLocations();
	sendParams();
105
	bind();
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
106 107
	bindVA_VBO("VertexPosition", m_vboPos);
	bindVA_VBO("VertexVector", m_vboVec);
108
	unbind();
109
}
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
110 111 112 113

} // namespace Utils

} // namespace CGoGN