Commit 7aea3ea5 authored by Sylvain Thery's avatar Sylvain Thery

update GLSL usage on VRJ

parent 089fc32b
......@@ -370,6 +370,12 @@ public:
*/
void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview);
/**
* update projection, modelview, ... matrices
*/
void updateMatrices(const glm::mat4& projection, const glm::mat4& modelview, const glm::mat4& PMV, const glm::mat4& normalMatrix);
/**
* bind, enable, and set all vertex attrib pointers
* @param stride: the stride parameter, number osf byte between two consecutive attributes
......@@ -386,6 +392,11 @@ public:
/// sent current matrices to all shaders
static void updateCurrentMatrices();
static glm::mat4& currentNormalMatrix() { return s_current_matrices->m_matrices[4];}
static glm::mat4& currentPMV() { return s_current_matrices->m_matrices[3];}
/// get current transformation matrix
static glm::mat4& currentTransfo() { return s_current_matrices->m_matrices[2];}
/// get current modelview matrix
......
......@@ -27,7 +27,9 @@
#define __GL_MATRICES_H_
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include <stack>
#include "Geometry/vector_gen.h"
namespace CGoGN
{
......@@ -37,13 +39,49 @@ namespace Utils
class GL_Matrices
{
public:
/// 0: projection / 1: modelView /2: transfo
glm::mat4 m_matrices[3];
/// 0: projection / 1: modelView /2: transfo / 3:PMV /4:normal
glm::mat4 m_matrices[5];
/// stack of transfo matrix
std::stack<glm::mat4> m_stack;
void pushTransfo() { m_stack.push(m_matrices[2]); }
void popTransfo() { if (m_stack.empty()) return; m_matrices[2] = m_stack.top(); m_stack.pop(); }
public:
void pushTransfo()
{
m_stack.push(m_matrices[2]);
}
void popTransfo()
{
if (m_stack.empty()) return;
m_matrices[2] = m_stack.top();
m_stack.pop();
}
glm::mat4 getTransfo() const
{
return m_matrices[2];
}
void rotate(float angle, const Geom::Vec3f& Axis)
{
m_matrices[2] = glm::rotate(m_matrices[2], angle, glm::vec3(Axis[0],Axis[1],Axis[2]));
}
void translate(const Geom::Vec3f& P)
{
m_matrices[2] = glm::translate(m_matrices[2], glm::vec3(P[0],P[1],P[2]));
}
void scale(const Geom::Vec3f& S)
{
m_matrices[2] = glm::scale(m_matrices[2], glm::vec3(S[0],S[1],S[2]));
}
void scale(float s)
{
m_matrices[2] = glm::scale(m_matrices[2], glm::vec3(s,s,s));
}
};
......
......@@ -1020,9 +1020,32 @@ void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& mo
glm::mat4 normalMatrix = glm::gtx::inverse_transpose::inverseTranspose(modelview);
glUniformMatrix4fv(*m_uniMat_Normal, 1 , false, &normalMatrix[0][0]);
}
}
void GLSLShader::updateMatrices(const glm::mat4& projection, const glm::mat4& modelview, const glm::mat4& PMV, const glm::mat4& normalMatrix)
{
this->bind();
if (*m_uniMat_Proj >= 0)
glUniformMatrix4fv(*m_uniMat_Proj, 1, false, &projection[0][0]);
if (*m_uniMat_Model >= 0)
glUniformMatrix4fv(*m_uniMat_Model, 1, false, &modelview[0][0]);
if (*m_uniMat_ModelProj >= 0)
{
glUniformMatrix4fv(*m_uniMat_ModelProj, 1 , false, &PMV[0][0]);
}
if (*m_uniMat_Normal >= 0)
{
glUniformMatrix4fv(*m_uniMat_Normal, 1 , false, &normalMatrix[0][0]);
}
}
void GLSLShader::enableVertexAttribs(unsigned int stride, unsigned int begin) const
{
this->bind();
......@@ -1042,13 +1065,17 @@ void GLSLShader::disableVertexAttribs() const
this->unbind();
}
void GLSLShader::updateCurrentMatrices()
{
glm::mat4 model(currentModelView());
model *= currentTransfo();
currentPMV() = currentProjection() * model;
currentNormalMatrix() = glm::gtx::inverse_transpose::inverseTranspose(model);
for(std::set< std::pair<void*, GLSLShader*> >::iterator it = m_registeredShaders.begin(); it != m_registeredShaders.end(); ++it)
it->second->updateMatrices(currentProjection(), model);
it->second->updateMatrices(currentProjection(), model, currentPMV(), currentNormalMatrix());
}
void GLSLShader::updateAllFromGLMatrices()
......@@ -1062,14 +1089,20 @@ void GLSLShader::updateAllFromGLMatrices()
glm::mat4 proj;
for (unsigned int i=0; i< 4; ++i)
{
for (unsigned int j=0; j<4; ++j)
{
proj[i][j] = float(projection[4*i+j]);
model[i][j] = float(modelview[4*i+j]);
}
}
model *= currentTransfo();
currentPMV() = proj * model;
currentNormalMatrix() = glm::gtx::inverse_transpose::inverseTranspose(model);
for(std::set< std::pair<void*, GLSLShader*> >::iterator it = m_registeredShaders.begin(); it != m_registeredShaders.end(); ++it)
it->second->updateMatrices(proj, model);
it->second->updateMatrices(proj, model, currentPMV(), currentNormalMatrix());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment