Commit 9a08b7b1 authored by untereiner's avatar untereiner

update mapRender index buffers management (dirty flag)

parent 8dbdbd97
......@@ -602,8 +602,10 @@ void MyQT::cb_Open()
void MyQT::cb_Save()
{
std::string filename = selectFileSave("Export SVG file ",".","(*.off)");
Algo::Surface::Export::exportOFF<PFP>(myMap, position, filename.c_str()); // ???
std::string filename = selectFileSave("Export MAP file ",".","(*.map)");
//Algo::Surface::Export::exportOFF<PFP>(myMap, position, filename.c_str()); // ???
if(!myMap.saveMapBin(filename))
std::cout << "could not save file : " << filename << std::endl;
}
void MyQT::importMesh(std::string& filename)
......
......@@ -26,7 +26,7 @@ MapHandlerGen* ImportSurfacePlugin::importFromFile(const QString& fileName)
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
PFP2::MAP* map = mh->getMap();
std::vector<std::string> attrNames ;
std::vector<std::string> attrNames;
Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toUtf8().constData(), attrNames);
// get vertex position attribute
......@@ -37,11 +37,6 @@ MapHandlerGen* ImportSurfacePlugin::importFromFile(const QString& fileName)
// compute map bounding box
mh->updateBB(position);
// compute primitive connectivity VBOs
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
return mhg;
}
......
......@@ -37,11 +37,6 @@ MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
// compute map bounding box
mh->updateBB(position);
// compute primitive connectivity VBOs
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
}
return mhg;
}
......
......@@ -44,9 +44,10 @@ void SubdivideSurfacePlugin::subdivideSurface()
else if(m_subdivideSurfaceDialog->radio_trianguleFaces->isChecked())
trianguleFaces(map, position);
mh->updatePrimitives(Algo::Render::GL2::POINTS);
mh->updatePrimitives(Algo::Render::GL2::LINES);
mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
mh->setPrimitiveDirty(Algo::Render::GL2::POINTS);
mh->setPrimitiveDirty(Algo::Render::GL2::LINES);
mh->setPrimitiveDirty(Algo::Render::GL2::TRIANGLES);
mh->updateVBO(position);
QList<View*> views = mh->getLinkedViews();
......
importPlugin = schnapps.loadPlugin("ImportSurface");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
renderPlugin = schnapps.loadPlugin("Render");
renderVectorPlugin = schnapps.loadPlugin("RenderVector");
differentialPropertiesPlugin = schnapps.loadPlugin("DifferentialProperties");
subdivisionPlugin = schnapps.loadPlugin("SubdivideSurface");
obj = importPlugin.importFromFile("/home/kraemer/Media/Data/surface/midRes/bimba_75k.off");
#obj = importPlugin.importFromFile("/home/untereiner/Developments/meshes/egea.off");
v = schnapps.getView("view_0");
schnapps.linkViewAndPlugin(v.getName(), renderPlugin.getName());
schnapps.linkViewAndPlugin(v.getName(), renderVectorPlugin.getName());
schnapps.linkViewAndMap(v.getName(), obj.getName());
#schnapps.linkViewAndMap(v.getName(), obj.getName());
differentialPropertiesPlugin.computeNormal(obj.getName());
differentialPropertiesPlugin.computeCurvature(obj.getName());
#differentialPropertiesPlugin.computeNormal(obj.getName());
#differentialPropertiesPlugin.computeCurvature(obj.getName());
......@@ -47,7 +47,9 @@ public slots:
bool isUsed() const { return !l_views.empty(); }
public:
void draw(Utils::GLSLShader* shader, int primitive) { m_render->draw(shader, primitive); }
virtual void draw(Utils::GLSLShader* shader, int primitive) = 0;
void setPrimitiveDirty(int primitive) { m_render->setPrimitiveDirty(primitive); }
/*********************************************************
* MANAGE ATTRIBUTES
......@@ -143,6 +145,13 @@ public:
delete m_map;
}
virtual void draw(Utils::GLSLShader* shader, int primitive)
{
if(!m_render->isPrimitiveUpToDate(primitive))
updatePrimitives(primitive);
m_render->draw(shader, primitive);
}
typename PFP::MAP* getMap() { return static_cast<typename PFP::MAP*>(m_map); }
void updateBB(const VertexAttribute<typename PFP::VEC3>& position)
......
......@@ -539,18 +539,21 @@ MapHandlerGen* Window::addMap(const QString& name, unsigned int dim)
if (h_maps.contains(name))
return NULL;
GenericMap* map = NULL;
MapHandlerGen* mh = NULL;
switch(dim)
{
case 2 :
map = new PFP2::MAP();
case 2 : {
PFP2::MAP* map = new PFP2::MAP();
mh = new MapHandler<PFP2>(name, this, map);
break;
case 3 :
map = new PFP3::MAP();
}
case 3 : {
PFP3::MAP* map = new PFP3::MAP();
mh = new MapHandler<PFP3>(name, this, map);
break;
}
}
MapHandlerGen* mh = new MapHandlerGen(name, this, map);
h_maps.insert(name, mh);
emit(mapAdded(mh));
......
......@@ -138,10 +138,20 @@ public:
Dart df = m_map.phi_1(m_map.phi2(m_map.phi1(d))) ;
m_map.decCurrentLevel() ;
if(!Algo::Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(m_map,df)
&& !Algo::Surface::Modelisation::isPrism<PFP>(m_map,df)
&& !Algo::Surface::Modelisation::isPyra<PFP>(m_map,df))
{
typename PFP::VEC3 p = Algo::Surface::Geometry::volumeCentroid<PFP>(m_map, df, m_position);
m_map.incCurrentLevel() ;
m_position[d] = p ;
}
else
m_map.incCurrentLevel() ;
return false ;
}
......
......@@ -622,7 +622,7 @@ unsigned int Map3MR<PFP>::subdivideVolume(Dart d, bool triQuad, bool OneLevelDif
Dart dd = m_map.phi1(m_map.phi1(old));
m_map.splitFace(old,dd) ;
centralDart = old;
//centralDart = old;
}
else
{
......@@ -712,7 +712,7 @@ unsigned int Map3MR<PFP>::subdivideVolume(Dart d, bool triQuad, bool OneLevelDif
}
//replonger l'orbit de ditV.
//m_map.template setOrbitEmbedding<VERTEX>(x, m_map.template getEmbedding<VERTEX>(d));
m_map.template setOrbitEmbedding<VERTEX>(centralDart, m_map.template getEmbedding<VERTEX>(centralDart));
(*volumeVertexFunctor)(centralDart) ;
......@@ -747,6 +747,7 @@ unsigned int Map3MR<PFP>::subdivideVolume(Dart d, bool triQuad, bool OneLevelDif
//replonger l'orbit de ditV.
m_map.template setOrbitEmbedding<VERTEX>(x, m_map.template getEmbedding<VERTEX>(x));
(*volumeVertexFunctor)(x) ;
m_map.decCurrentLevel() ;
}
......@@ -786,8 +787,8 @@ unsigned int Map3MR<PFP>::subdivideVolume(Dart d, bool triQuad, bool OneLevelDif
}
m_map.template setOrbitEmbedding<VERTEX>(centralDart, m_map.template getEmbedding<VERTEX>(centralDart));
(*volumeVertexFunctor)(centralDart) ;
m_map.template setOrbitEmbedding<VERTEX>(x, m_map.template getEmbedding<VERTEX>(x));
(*volumeVertexFunctor)(x) ;
m_map.decCurrentLevel() ;
}
......@@ -836,8 +837,8 @@ unsigned int Map3MR<PFP>::subdivideVolume(Dart d, bool triQuad, bool OneLevelDif
m_map.decCurrentLevel() ;
}
m_map.incCurrentLevel();
m_map.popLevel() ;
return vLevel;
......
......@@ -132,7 +132,6 @@ public:
template<typename PFP>
void updateData(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
/**
* draw edges
*/
......
......@@ -58,22 +58,12 @@ namespace GL2
enum drawingType
{
TRIANGLES = 1,
LINES = 2,
POINTS = 4,
EXPLODED = 8,
FLAT_TRIANGLES = 16,
BOUNDARY = 32,
ERR = 64
} ;
enum bufferIndex
{
POINT_INDICES = 0,
LINE_INDICES = 1,
TRIANGLE_INDICES = 2,
FLAT_BUFFER = 3,
BOUNDARY_INDICES = 4,
POINTS = 0,
LINES = 1,
TRIANGLES = 2,
FLAT_TRIANGLES = 3,
BOUNDARY = 4,
EXPLODED = 5,
SIZE_BUFFER
} ;
......@@ -84,6 +74,7 @@ protected:
* vbo buffers
*/
GLuint m_indexBuffers[SIZE_BUFFER] ;
bool m_indexBufferUpToDate[SIZE_BUFFER];
/**
* nb indices
......@@ -208,6 +199,7 @@ public:
*/
template <typename PFP>
void initBoundaries(typename PFP::MAP& map, const FunctorSelect& good, std::vector<GLuint>& tableIndices, unsigned int thread = 0) ;
/**
* initialization of the VBO indices primitives
* computed by a traversal of the map
......@@ -226,6 +218,20 @@ public:
*/
void initPrimitives(int prim, std::vector<GLuint>& tableIndices) ;
/**
* initialization of the VBO indices primitives
* using the given table
* @param prim primitive to draw: POINT_INDICES, LINE_INDICES, TRIANGLE_INDICES
*/
bool isPrimitiveUpToDate(int prim) { return m_indexBufferUpToDate[prim]; }
/**
* initialization of the VBO indices primitives
* using the given table
* @param prim primitive to draw: POINT_INDICES, LINE_INDICES, TRIANGLE_INDICES
*/
void setPrimitiveDirty(int prim) { m_indexBufferUpToDate[prim] = false; }
/**
* draw the VBO (function to call in the drawing callback)
*/
......
......@@ -495,48 +495,39 @@ void MapRender::initPrimitives(typename PFP::MAP& map, const FunctorSelect& good
{
std::vector<GLuint> tableIndices;
// indice du VBO a utiliser
int vbo_ind = 0;
switch(prim)
{
case POINTS:
initPoints<PFP>(map, good, tableIndices, thread);
m_nbIndices[POINT_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[POINT_INDICES];
break;
case LINES:
if(optimized)
initLinesOptimized<PFP>(map, good, tableIndices, thread);
else
initLines<PFP>(map, good, tableIndices, thread) ;
m_nbIndices[LINE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[LINE_INDICES];
break;
case TRIANGLES:
if(optimized)
initTrianglesOptimized<PFP>(map, good, tableIndices, position, thread);
else
initTriangles<PFP>(map, good, tableIndices, position, thread) ;
m_nbIndices[TRIANGLE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[TRIANGLE_INDICES];
break;
case FLAT_TRIANGLES:
break;
case BOUNDARY:
initBoundaries<PFP>(map, good, tableIndices, thread) ;
m_nbIndices[BOUNDARY_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[BOUNDARY_INDICES];
break;
default:
CGoGNerr << "problem initializing VBO indices" << CGoGNendl;
break;
}
unsigned int size = tableIndices.size();
m_nbIndices[prim] = tableIndices.size();
m_indexBufferUpToDate[prim] = true;
// setup du buffer d'indices
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, vbo_ind);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
} // namespace GL2
......
......@@ -41,7 +41,10 @@ MapRender::MapRender()
{
glGenBuffers(SIZE_BUFFER, m_indexBuffers) ;
for(unsigned int i = 0; i < SIZE_BUFFER; ++i)
{
m_nbIndices[i] = 0 ;
m_indexBufferUpToDate[i] = false;
}
}
MapRender::~MapRender()
......@@ -51,65 +54,33 @@ MapRender::~MapRender()
void MapRender::initPrimitives(int prim, std::vector<GLuint>& tableIndices)
{
// indice du VBO a utiliser
int vbo_ind = 0;
int size = 0;
switch(prim)
{
case POINTS:
m_nbIndices[POINT_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[POINT_INDICES];
size = m_nbIndices[POINT_INDICES];
break;
case LINES:
m_nbIndices[LINE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[LINE_INDICES];
size = m_nbIndices[LINE_INDICES];
break;
case TRIANGLES:
m_nbIndices[TRIANGLE_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[TRIANGLE_INDICES];
size = m_nbIndices[TRIANGLE_INDICES];
break;
case BOUNDARY:
m_nbIndices[BOUNDARY_INDICES] = tableIndices.size();
vbo_ind = m_indexBuffers[BOUNDARY_INDICES];
size = m_nbIndices[BOUNDARY_INDICES];
break;
default:
CGoGNerr << "problem initializing VBO indices" << CGoGNendl;
break;
}
m_nbIndices[prim] = tableIndices.size();
m_indexBufferUpToDate[prim] = true;
// setup du buffer d'indices
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_ind);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_nbIndices[prim] * sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
void MapRender::draw(Utils::GLSLShader* sh, int prim)
{
sh->enableVertexAttribs();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
switch(prim)
{
case POINTS:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[POINT_INDICES]);
glDrawElements(GL_POINTS, m_nbIndices[POINT_INDICES], GL_UNSIGNED_INT, 0) ;
glDrawElements(GL_POINTS, m_nbIndices[POINTS], GL_UNSIGNED_INT, 0) ;
break;
case LINES:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[LINE_INDICES]);
glDrawElements(GL_LINES, m_nbIndices[LINE_INDICES], GL_UNSIGNED_INT, 0);
glDrawElements(GL_LINES, m_nbIndices[LINES], GL_UNSIGNED_INT, 0);
break;
case TRIANGLES:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[TRIANGLE_INDICES]);
glDrawElements(GL_TRIANGLES, m_nbIndices[TRIANGLE_INDICES], GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, m_nbIndices[TRIANGLES], GL_UNSIGNED_INT, 0);
break;
case BOUNDARY:
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[BOUNDARY_INDICES]);
glDrawElements(GL_LINES, m_nbIndices[BOUNDARY_INDICES], GL_UNSIGNED_INT, 0);
glDrawElements(GL_LINES, m_nbIndices[BOUNDARY], GL_UNSIGNED_INT, 0);
break;
default:
break;
}
......@@ -121,25 +92,22 @@ unsigned int MapRender::drawSub(Utils::GLSLShader* sh, int prim, unsigned int nb
{
sh->enableVertexAttribs();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[prim]);
switch(prim)
{
case POINTS:
if (nb_elm > m_nbIndices[POINT_INDICES])
nb_elm = m_nbIndices[POINT_INDICES];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[POINT_INDICES]);
if (nb_elm > m_nbIndices[POINTS])
nb_elm = m_nbIndices[POINTS];
glDrawElements(GL_POINTS, nb_elm, GL_UNSIGNED_INT, 0) ;
break;
case LINES:
if (2*nb_elm > m_nbIndices[LINE_INDICES])
nb_elm = m_nbIndices[LINE_INDICES]/2;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[LINE_INDICES]);
if (2*nb_elm > m_nbIndices[LINES])
nb_elm = m_nbIndices[LINES]/2;
glDrawElements(GL_LINES, 2*nb_elm, GL_UNSIGNED_INT, 0);
break;
case TRIANGLES:
if (3*nb_elm > m_nbIndices[TRIANGLE_INDICES])
nb_elm = m_nbIndices[TRIANGLE_INDICES]/3;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBuffers[TRIANGLE_INDICES]);
if (3*nb_elm > m_nbIndices[TRIANGLES])
nb_elm = m_nbIndices[TRIANGLES]/3;
glDrawElements(GL_TRIANGLES, 3*nb_elm, GL_UNSIGNED_INT, 0);
break;
default:
......
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