Commit 1cf1080e authored by Jan Möbius's avatar Jan Möbius

Dennis:

Use display lists to make picking 10 times faster.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5210 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 85fcfd27
......@@ -846,8 +846,9 @@ void GLState::pick_init (bool _color)
bool GLState::pick_set_maximum (unsigned int _idx)
{
bool rv = colorStack_.setMaximumIndex (_idx);
if (colorPicking_)
return colorStack_.setMaximumIndex (_idx);
return rv;
return true;
}
......
......@@ -76,8 +76,14 @@ MeshNodeT(const Mesh& _mesh,
vertexBufferInitialized_(false),
normalBufferInitialized_(false),
faceIndexBufferInitialized_(false),
textureMap_(0)
textureMap_(0),
updateFaceList_(true),
updateVertexList_(true),
faceBaseIndex_(0),
vertexBaseIndex_(0)
{
faceList_ = glGenLists (1);
vertexList_ = glGenLists (1);
}
......@@ -97,6 +103,11 @@ MeshNodeT<Mesh>::
if (face_index_buffer_)
glDeleteBuffersARB(1, (GLuint*) &face_index_buffer_ );
if (faceList_)
glDeleteLists (faceList_, 1);
if (vertexList_)
glDeleteLists (vertexList_, 1);
}
......@@ -351,6 +362,9 @@ void
MeshNodeT<Mesh>::
update_geometry()
{
updateFaceList_ = true;
updateVertexList_ = true;
if (GLEW_ARB_vertex_buffer_object) {
typedef typename Mesh::Point Point;
typedef typename Point::value_type PointScalar;
......@@ -448,6 +462,9 @@ void
MeshNodeT<Mesh>::
update_topology()
{
updateFaceList_ = true;
updateVertexList_ = true;
if (mesh_.is_trimesh())
{
typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
......@@ -1127,6 +1144,19 @@ pick_vertices(GLState& _state)
return;
}
if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_)
{
glCallList (vertexList_);
return;
}
if (vertexList_)
{
glNewList (vertexList_, GL_COMPILE_AND_EXECUTE);
updateVertexList_ = false;
vertexBaseIndex_ = _state.pick_current_index ();
}
for (; v_it!=v_end; ++v_it, ++idx)
{
_state.pick_set_name (idx);
......@@ -1134,6 +1164,9 @@ pick_vertices(GLState& _state)
glVertex(mesh_.point(v_it));
glEnd();
}
if (vertexList_)
glEndList ();
}
......@@ -1158,6 +1191,19 @@ pick_faces(GLState& _state)
return;
}
if (faceList_ && !updateFaceList_ && _state.pick_current_index () == faceBaseIndex_)
{
glCallList (faceList_);
return;
}
if (faceList_)
{
glNewList (faceList_, GL_COMPILE_AND_EXECUTE);
updateFaceList_ = false;
faceBaseIndex_ = _state.pick_current_index ();
}
if (mesh_.is_trimesh())
{
for (; f_it!=f_end; ++f_it)
......@@ -1187,6 +1233,9 @@ pick_faces(GLState& _state)
glEnd();
}
}
if (faceList_)
glEndList ();
}
......
......@@ -177,6 +177,15 @@ private:
// Mapping of mesh face texture indeces to gltexture id ( has to be provided externally )
std::vector< GLuint >* textureMap_;
// display Lists used for picking
GLuint faceList_;
GLuint vertexList_;
// do we need to update our display lists?
bool updateFaceList_;
bool updateVertexList_;
unsigned int faceBaseIndex_;
unsigned int vertexBaseIndex_;
};
......
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