Commit 5579ce2f authored by Sylvain Thery's avatar Sylvain Thery

minor update in GMap (const)

update flat shader color &  colorPerFaceRender
parent cd514af0
...@@ -52,13 +52,8 @@ namespace GL2 ...@@ -52,13 +52,8 @@ namespace GL2
class ColorPerFaceRender class ColorPerFaceRender
{ {
protected: protected:
Utils::VBO& m_vboPos;
Utils::VBO& m_vboColors;
GLuint m_nbTris; GLuint m_nbTris;
public: public:
/** /**
* Constructor * Constructor
...@@ -73,7 +68,11 @@ public: ...@@ -73,7 +68,11 @@ public:
* @param good selector * @param good selector
*/ */
template<typename PFP> template<typename PFP>
void updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ; void updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
template<typename PFP>
void updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNormals, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& normals, const typename PFP::TVEC3& colorPerFace, const FunctorSelect& good = allDarts) ;
/** /**
* draw * draw
......
...@@ -41,33 +41,31 @@ namespace GL2 ...@@ -41,33 +41,31 @@ namespace GL2
{ {
inline ColorPerFaceRender::ColorPerFaceRender(Utils::VBO& vboPosition, Utils::VBO& vboColor): //inline ColorPerFaceRender::ColorPerFaceRender(Utils::VBO& vboPosition, Utils::VBO& vboColor):
m_vboPosition(vboPosition), m_vboColor(vboColor), m_nbTris(0) // m_vboPos(vboPosition), m_vboColors(vboColor), m_nbTris(0)
//{
//}
inline ColorPerFaceRender::ColorPerFaceRender():
m_nbTris(0)
{ {
} }
template<typename PFP> template<typename PFP>
void ColorPerFaceRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& positions, typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good) void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions,const typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good)
{ {
typedef typename PFP::VEC3 VEC3; typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
CellMarker cmv(map,VOLUME);
AutoAttributeHandler<VEC3> centerVolumes(map,VOLUME,"centerVolumes");
TraversorW<typename PFP::MAP> traVol(map,good);
for (Dart d=traVol.begin(); d!=traVol.end(); d=traVol.next())
{
centerVolumes[d] = Algo::Geometry::volumeCentroid<PFP>(map, d, positions);
}
std::vector<VEC3> buffer; std::vector<VEC3> buffer;
buffer.reserve(16384); buffer.reserve(16384);
std::vector<VEC3> bufferColors; std::vector<VEC3> bufferColors;
bufferColors.reserve(16384); bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, PFP::MAP::ORBIT_IN_PARENT(FACE),good); TraversorCell<typename PFP::MAP> traFace(map, FACE,good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next()) for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{ {
...@@ -88,25 +86,88 @@ void ColorPerFaceRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3& ...@@ -88,25 +86,88 @@ void ColorPerFaceRender::updateData(typename PFP::MAP& map, typename PFP::TVEC3&
} while (c != d); } while (c != d);
} }
m_nbTris = buffer.size()/4; m_nbTris = buffer.size()/3;
m_vboPos->allocate(buffer.size()); vboPosition.setDataSize(3);
VEC3* ptrPos = reinterpret_cast<VEC3*>(m_vboPos->lockPtr()); vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3)); memcpy(ptrPos,&buffer[0],buffer.size()*sizeof(VEC3));
m_vboPos->releasePtr(); vboPosition.releasePtr();
m_vboColors->allocate(bufferColors.size()); vboColor.setDataSize(3);
VEC3* ptrCol = reinterpret_cast<VEC3*>(m_vboColors->lockPtr()); vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3)); memcpy(ptrCol,&bufferColors[0],bufferColors.size()*sizeof(VEC3));
m_vboColors->releasePtr(); vboColor.releasePtr();
}
template<typename PFP>
void ColorPerFaceRender::updateVBO(Utils::VBO& vboPosition, Utils::VBO& vboNormal, Utils::VBO& vboColor, typename PFP::MAP& map, const typename PFP::TVEC3& positions, const typename PFP::TVEC3& normals, const typename PFP::TVEC3& colorPerXXX, const FunctorSelect& good)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
std::vector<VEC3> buffer;
buffer.reserve(16384);
std::vector<VEC3> bufferNormals;
bufferNormals.reserve(16384);
std::vector<VEC3> bufferColors;
bufferColors.reserve(16384);
TraversorCell<typename PFP::MAP> traFace(map, FACE,good);
for (Dart d=traFace.begin(); d!=traFace.end(); d=traFace.next())
{
Dart a = d;
Dart b = map.phi1(a);
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{
buffer.push_back(positions[d]);
bufferNormals.push_back(normals[d]);
bufferColors.push_back(colorPerXXX[d]);
buffer.push_back(positions[b]);
bufferNormals.push_back(normals[b]);
bufferColors.push_back(colorPerXXX[b]);
buffer.push_back(positions[c]);
bufferNormals.push_back(normals[c]);
bufferColors.push_back(colorPerXXX[c]);
b = c;
c = map.phi1(b);
} while (c != d);
}
m_nbTris = buffer.size()/3;
vboPosition.setDataSize(3);
vboPosition.allocate(buffer.size());
VEC3* ptrPos = reinterpret_cast<VEC3*>(vboPosition.lockPtr());
memcpy(ptrPos, &buffer[0], buffer.size()*sizeof(VEC3));
vboPosition.releasePtr();
vboNormal.setDataSize(3);
vboNormal.allocate(bufferColors.size());
VEC3* ptrNorm = reinterpret_cast<VEC3*>(vboNormal.lockPtr());
memcpy(ptrNorm, &bufferColors[0], bufferColors.size()*sizeof(VEC3));
vboNormal.releasePtr();
vboColor.setDataSize(3);
vboColor.allocate(bufferColors.size());
VEC3* ptrCol = reinterpret_cast<VEC3*>(vboColor.lockPtr());
memcpy(ptrCol, &bufferColors[0], bufferColors.size()*sizeof(VEC3));
vboColor.releasePtr();
} }
void ColorPerFaceRender::draw(Utils::GLSLShader* sh)
inline void ColorPerFaceRender::draw(Utils::GLSLShader* sh)
{ {
sh->enableVertexAttribs(); sh->enableVertexAttribs();
glDrawArrays(GL_TRIANGLES , 0 , m_nbTris*3 ); glDrawArrays(GL_TRIANGLES , 0 , m_nbTris*3 );
sh->disableVertexAttribs(); sh->disableVertexAttribs();
} }
......
...@@ -254,7 +254,7 @@ public: ...@@ -254,7 +254,7 @@ public:
/** /**
* get the index of dart in topological table * get the index of dart in topological table
*/ */
unsigned int dartIndex(Dart d); unsigned int dartIndex(Dart d) const;
/** /**
* get the insertion level of a dart (use only in MRMaps) * get the insertion level of a dart (use only in MRMaps)
...@@ -602,7 +602,7 @@ public: ...@@ -602,7 +602,7 @@ public:
/** /**
* test if a dart belong to the boundary * test if a dart belong to the boundary
*/ */
bool isBoundaryMarked(Dart d); bool isBoundaryMarked(Dart d) const;
protected: protected:
/** /**
......
...@@ -187,7 +187,7 @@ inline void GenericMap::duplicateDart(Dart d) ...@@ -187,7 +187,7 @@ inline void GenericMap::duplicateDart(Dart d)
} }
} }
inline unsigned int GenericMap::dartIndex(Dart d) inline unsigned int GenericMap::dartIndex(Dart d) const
{ {
if (m_isMultiRes) if (m_isMultiRes)
return (*m_mrDarts[m_mrCurrentLevel])[d.index] ; return (*m_mrDarts[m_mrCurrentLevel])[d.index] ;
...@@ -396,4 +396,25 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na ...@@ -396,4 +396,25 @@ inline AttributeMultiVector<Dart>* GenericMap::getRelation(const std::string& na
return amv ; return amv ;
} }
/**************************
* BOUNDARY MANAGEMENT *
**************************/
inline void GenericMap::boundaryMark(Dart d)
{
m_markTables[DART][0]->operator[](dartIndex(d)).setMark(m_boundaryMarker);
}
inline void GenericMap::boundaryUnmark(Dart d)
{
m_markTables[DART][0]->operator[](dartIndex(d)).unsetMark(m_boundaryMarker);
}
inline bool GenericMap::isBoundaryMarked(Dart d) const
{
return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarker);
}
} //namespace CGoGN } //namespace CGoGN
// ShaderFlatColorPerFace::fragmentShaderText // ShaderFlatColor::fragmentShaderText
VARYING_FRAG vec4 ColorFS; VARYING_FRAG vec4 ColorFS;
void main() void main()
{ {
......
// ShaderFlatColorPerFace::geometryShaderText // ShaderFlatColor::geometryShaderText
uniform float explode; uniform float explode;
uniform mat4 ModelViewProjectionMatrix; uniform mat4 ModelViewProjectionMatrix;
uniform mat4 NormalMatrix; uniform mat4 NormalMatrix;
...@@ -21,7 +21,7 @@ void main(void) ...@@ -21,7 +21,7 @@ void main(void)
vec3 L = normalize (lightPosition - newPos.xyz); vec3 L = normalize (lightPosition - newPos.xyz);
float lambertTerm = dot(N,L); float lambertTerm = dot(N,L);
#ifdef AVERGAGE_COLOR #ifdef AVERAGE_COLOR
int i; int i;
vec3 averageColor=vec3(0.,0.,0.); vec3 averageColor=vec3(0.,0.,0.);
for(i=0; i< 3; i++) for(i=0; i< 3; i++)
......
...@@ -34,7 +34,7 @@ namespace CGoGN ...@@ -34,7 +34,7 @@ namespace CGoGN
namespace Utils namespace Utils
{ {
class ShaderFlatColorPerFace : public GLSLShader class ShaderFlatColor : public GLSLShader
{ {
protected: protected:
// shader sources // shader sources
...@@ -59,7 +59,7 @@ protected: ...@@ -59,7 +59,7 @@ protected:
void restoreUniformsAttribs(); void restoreUniformsAttribs();
public: public:
ShaderFlatColorPerFace(); ShaderFlatColor(bool averageColor=false);
void setExplode(float explode); void setExplode(float explode);
......
// ShaderFlatColorPerFace::vertexShaderText // ShaderFlatColor::vertexShaderText
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor; ATTRIBUTE vec3 VertexColor;
VARYING_VERT vec3 colorVertex; VARYING_VERT vec3 colorVertex;
......
...@@ -859,21 +859,6 @@ unsigned int GenericMap::getNbOrbits(unsigned int orbit, const FunctorSelect& go ...@@ -859,21 +859,6 @@ unsigned int GenericMap::getNbOrbits(unsigned int orbit, const FunctorSelect& go
return fcount.getNb(); return fcount.getNb();
} }
void GenericMap::boundaryMark(Dart d)
{
m_markTables[DART][0]->operator[](dartIndex(d)).setMark(m_boundaryMarker);
}
void GenericMap::boundaryUnmark(Dart d)
{
m_markTables[DART][0]->operator[](dartIndex(d)).unsetMark(m_boundaryMarker);
}
bool GenericMap::isBoundaryMarked(Dart d)
{
return m_markTables[DART][0]->operator[](dartIndex(d)).testMark(m_boundaryMarker);
}
void GenericMap::boundaryMarkOrbit(unsigned int orbit, Dart d) void GenericMap::boundaryMarkOrbit(unsigned int orbit, Dart d)
{ {
FunctorMark<GenericMap> fm(*this, m_boundaryMarker, m_markTables[DART][0]) ; FunctorMark<GenericMap> fm(*this, m_boundaryMarker, m_markTables[DART][0]) ;
......
...@@ -22,30 +22,32 @@ ...@@ -22,30 +22,32 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <string.h> #include <string>
#include <GL/glew.h> #include <GL/glew.h>
#include "Utils/Shaders/shaderFlatColorPerFace.h" #include "Utils/Shaders/shaderFlatColor.h"
namespace CGoGN namespace CGoGN
{ {
namespace Utils namespace Utils
{ {
#include "shaderFlatColorPerFace.vert" #include "shaderFlatColor.vert"
#include "shaderFlatColorPerFace.frag" #include "shaderFlatColor.frag"
#include "shaderFlatColorPerFace.geom" #include "shaderFlatColor.geom"
ShaderFlatColorPerFace::ShaderFlatColorPerFace() ShaderFlatColor::ShaderFlatColor(bool averageColor)
{ {
m_nameVS = "shaderFlatColorPerFace_vs"; m_nameVS = "shaderFlatColor_vs";
m_nameFS = "shaderFlatColorPerFace_fs"; m_nameFS = "shaderFlatColor_fs";
m_nameGS = "shaderFlatColorPerFace_gs"; m_nameGS = "shaderFlatColor_gs";
std::string glxvert(*GLSLShader::DEFINES_GL); std::string glxvert(*GLSLShader::DEFINES_GL);
glxvert.append(vertexShaderText); glxvert.append(vertexShaderText);
std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3); std::string glxgeom = GLSLShader::defines_Geom("triangles", "triangle_strip", 3);
if (averageColor)
glxgeom.append("#define AVERAGE_COLOR 1\n");
glxgeom.append(geometryShaderText); glxgeom.append(geometryShaderText);
std::string glxfrag(*GLSLShader::DEFINES_GL); std::string glxfrag(*GLSLShader::DEFINES_GL);
...@@ -63,19 +65,19 @@ ShaderFlatColorPerFace::ShaderFlatColorPerFace() ...@@ -63,19 +65,19 @@ ShaderFlatColorPerFace::ShaderFlatColorPerFace()
setParams(m_explode, m_ambiant, m_light_pos); setParams(m_explode, m_ambiant, m_light_pos);
} }
void ShaderFlatColorPerFace::getLocations() void ShaderFlatColor::getLocations()
{ {
m_unif_explode = glGetUniformLocation(program_handler(),"explode"); m_unif_explode = glGetUniformLocation(program_handler(),"explode");
m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition"); m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
} }
void ShaderFlatColorPerFace::setAttributePosition(VBO* vbo) void ShaderFlatColor::setAttributePosition(VBO* vbo)
{ {
m_vboPos = vbo; m_vboPos = vbo;
bindVA_VBO("VertexPosition", vbo); bindVA_VBO("VertexPosition", vbo);
} }
void ShaderFlatColorPerFace::setAttributeColor(VBO* vbo) void ShaderFlatColor::setAttributeColor(VBO* vbo)
{ {
m_vboColor = vbo; m_vboColor = vbo;
bindVA_VBO("VertexColor", vbo); bindVA_VBO("VertexColor", vbo);
...@@ -83,7 +85,7 @@ void ShaderFlatColorPerFace::setAttributeColor(VBO* vbo) ...@@ -83,7 +85,7 @@ void ShaderFlatColorPerFace::setAttributeColor(VBO* vbo)
void ShaderFlatColorPerFace::setParams(float expl, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos) void ShaderFlatColor::setParams(float expl, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos)
{ {
m_explode = expl; m_explode = expl;
m_ambiant = ambiant; m_ambiant = ambiant;
...@@ -98,14 +100,14 @@ void ShaderFlatColorPerFace::setParams(float expl, const Geom::Vec4f& ambiant, c ...@@ -98,14 +100,14 @@ void ShaderFlatColorPerFace::setParams(float expl, const Geom::Vec4f& ambiant, c
unbind(); // ?? unbind(); // ??
} }
void ShaderFlatColorPerFace::setExplode(float explode) void ShaderFlatColor::setExplode(float explode)
{ {
m_explode = explode; m_explode = explode;
bind(); bind();
glUniform1f(m_unif_explode, explode); glUniform1f(m_unif_explode, explode);
} }
void ShaderFlatColorPerFace::setAmbiant(const Geom::Vec4f& ambiant) void ShaderFlatColor::setAmbiant(const Geom::Vec4f& ambiant)
{ {
m_ambiant = ambiant; m_ambiant = ambiant;
bind(); bind();
...@@ -113,14 +115,14 @@ void ShaderFlatColorPerFace::setAmbiant(const Geom::Vec4f& ambiant) ...@@ -113,14 +115,14 @@ void ShaderFlatColorPerFace::setAmbiant(const Geom::Vec4f& ambiant)
} }
void ShaderFlatColorPerFace::setLightPosition(const Geom::Vec3f& lp) void ShaderFlatColor::setLightPosition(const Geom::Vec3f& lp)
{ {
m_light_pos = lp; m_light_pos = lp;
bind(); bind();
glUniform3fv(m_unif_lightPos,1,lp.data()); glUniform3fv(m_unif_lightPos,1,lp.data());
} }
void ShaderFlatColorPerFace::restoreUniformsAttribs() void ShaderFlatColor::restoreUniformsAttribs()
{ {
m_unif_explode = glGetUniformLocation(program_handler(),"explode"); m_unif_explode = glGetUniformLocation(program_handler(),"explode");
m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient"); m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
......
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