Commit ad262b15 authored by Marlin Frickenschmidt's avatar Marlin Frickenschmidt
Browse files

Moved depth_func_ from BaseNode to GL_State since most nodes don't use this....

Moved depth_func_ from BaseNode to GL_State since most nodes don't use this. Updated all nodes to reflect this, especially LineNode which can now be set to be "always on top" as is desired by the lasso selection.

Fixed a crash in Lasso Selection that would occur if the line was not properly closed.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10091 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f09147d4
......@@ -80,7 +80,8 @@ GLState::GLState(bool _updateGL)
mipmapping_(true),
updateGL_(_updateGL),
blending_(false),
msSinceLastRedraw_ (1)
msSinceLastRedraw_ (1),
depth_func_(GL_LESS)
{
initialize();
}
......
......@@ -314,6 +314,9 @@ public:
_direction will be nornalized.
*/
void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
/// get and set glDepthFunc() parameter
GLenum& depthFunc() { return depth_func_; }
//--- project and unproject points ------------------------------------------
......@@ -585,6 +588,9 @@ private: //--------------------------------------------------------------------
// are we using color picking
bool colorPicking_;
// depth comparison function (GL_LESS by default)
GLenum depth_func_;
};
......
......@@ -79,7 +79,6 @@ BaseNode(BaseNode* _parent, std::string _name)
name_(_name),
status_(Active),
drawMode_(DrawModes::DEFAULT),
depth_func_(GL_LESS),
pickingEnabled_(true),
dirty_ (false),
traverseMode_ (BaseNode::NodeFirst)
......
......@@ -209,13 +209,6 @@ public:
/// Handle mouse event (some interaction, e.g. modeling)
virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {}
/// get glDepthFunc() parameter
GLenum depthFunc() const { return depth_func_; }
/// set glDepthFunc parameter (it's GL_LESS by default)
void depthFunc(GLenum _func) { depth_func_ = _func; }
/// mark node for redrawn
void setDirty (bool _dirty = true) { dirty_ = _dirty; }
......@@ -555,9 +548,6 @@ private:
/// private draw mode
DrawModes::DrawMode drawMode_;
/// depth func
GLenum depth_func_;
/** Flag indicating if picking should be done for this object
* This flag has to be checked by your node if you implement picking
......
......@@ -138,9 +138,7 @@ availableDrawModes() const
void
GlutPrimitiveNode::
draw(GLState& _state, DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
{
for (int i = 0; i < (int)primitives_.size(); ++i)
{
......@@ -235,8 +233,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
glPopMatrix();
} // end of primitives iter
glDepthFunc(GL_LESS);
}
//----------------------------------------------------------------------------
......
......@@ -89,13 +89,28 @@ availableDrawModes() const
//----------------------------------------------------------------------------
void
LineNode::
enter(GLState& _state , DrawModes::DrawMode _drawMode)
{
MaterialNode::enter(_state, _drawMode);
if (alwaysOnTop()) {
//store current depth comparison function (needed for lasso selection)
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth_);
//set depth function and change GLState accordingly
glDepthFunc(GL_ALWAYS);
_state.depthFunc() = GL_ALWAYS;
}
}
//----------------------------------------------------------------------------
void
LineNode::
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
if (_drawMode & DrawModes::WIREFRAME)
{
glDisable(GL_LIGHTING);
......@@ -131,10 +146,22 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
glEnd();
}
glDepthFunc(GL_LESS);
}
//----------------------------------------------------------------------------
void
LineNode::
leave(GLState& _state , DrawModes::DrawMode _drawMode)
{
if (alwaysOnTop()) {
//restore depth function and change GLState accordingly
glDepthFunc(prev_depth_);
_state.depthFunc() = prev_depth_;
}
MaterialNode::leave(_state, _drawMode);
}
//=============================================================================
......
......@@ -103,7 +103,9 @@ public:
_name,
MaterialNode::BaseColor |
MaterialNode::LineWidth),
line_mode_(_mode)
line_mode_(_mode),
draw_always_on_top (false),
prev_depth_(GL_LESS)
{
drawMode(DrawModes::WIREFRAME);
}
......@@ -116,7 +118,6 @@ public:
void set_line_mode(LineMode _mode) { line_mode_ = _mode; }
/// static name of this class
ACG_CLASSNAME(LineNode);
......@@ -125,16 +126,20 @@ public:
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// set depth function (needed for lasso selection so that the line can be draw in pseudo-2D)
void enter(GLState& _state, DrawModes::DrawMode _drawMode);
/// draw lines and normals
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
/// reset depth function to what it was before enter()
void leave(GLState& _state, DrawModes::DrawMode _drawMode);
/// reserve mem for _n lines
void reserve_lines(unsigned int _n) { points_.reserve(2*_n); }
/// reserve mem for _n points
void reserve_points(unsigned int _n) { points_.reserve(_n); }
......@@ -163,8 +168,11 @@ public:
/// return reference to point vector
const PointVector& points() const { return points_; }
/// get color container
/// get and set color container
ColorVector& colors() { return colors_; }
/// get and set always on top
bool& alwaysOnTop() { return draw_always_on_top; }
/// STL conformance
......@@ -180,6 +188,9 @@ protected:
ColorVector colors_;
LineMode line_mode_;
bool draw_always_on_top;
GLint prev_depth_;
};
......
......@@ -222,8 +222,8 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
// Update strips if necessary
stripProcessor_.stripify();
/// \todo Whats this? Why is this set here
glDepthFunc(depthFunc());
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
unsigned int arrays = VERTEX_ARRAY;
......@@ -295,7 +295,9 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
glDepthFunc(GL_LEQUAL);
_state.set_base_color(base_color);
draw_lines();
glDepthFunc(depthFunc());
//restore depth buffer comparison function for the next draw calls inside this function
glDepthFunc(prev_depth);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -482,9 +484,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
// Unbind all remaining buffers
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB , 0 );
/// \todo Whats this? Why is this set here and why isnt it set to the one before entering the function?
glDepthFunc(GL_LESS);
glPopAttrib();
}
......@@ -990,10 +989,12 @@ void
MeshNodeT<Mesh>::
pick_vertices(GLState& _state, bool _front)
{
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end());
if (!_state.pick_set_maximum (mesh_.n_vertices())) {
omerr() << "MeshNode::pick_vertices: color range too small, " << "picking failed\n";
return;
......@@ -1030,8 +1031,7 @@ pick_vertices(GLState& _state, bool _front)
if (vertexPickingList_ && !updateVertexPickingList_ && _state.pick_current_index () == vertexPickingBaseIndex_) {
glCallList (vertexPickingList_);
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
return;
}
......@@ -1062,14 +1062,13 @@ pick_vertices(GLState& _state, bool _front)
} else
std::cerr << "Fallback not available pick_vertices!" << std::endl;
if (vertexPickingList_) {
glEndList ();
glCallList (vertexPickingList_);
}
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
}
template<class Mesh>
......@@ -1077,7 +1076,9 @@ void
MeshNodeT<Mesh>::
pick_edges(GLState& _state, bool _front)
{
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (!_state.pick_set_maximum (mesh_.n_edges())) {
omerr() << "MeshNode::pick_edges: color range too small, " << "picking failed\n";
return;
......@@ -1114,8 +1115,7 @@ pick_edges(GLState& _state, bool _front)
if (edgePickingList_ && !updateEdgePickingList_ && _state.pick_current_index () == edgePickingBaseIndex_) {
glCallList (edgePickingList_);
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
return;
}
......@@ -1159,8 +1159,7 @@ pick_edges(GLState& _state, bool _front)
glCallList (edgePickingList_);
}
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
}
template<class Mesh>
......@@ -1239,7 +1238,9 @@ void
MeshNodeT<Mesh>::
pick_any(GLState& _state)
{
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
if ( mesh_.n_vertices() == 0 ) {
......@@ -1277,7 +1278,7 @@ pick_any(GLState& _state)
stripProcessor_.updatePickingAny(_state);
// For this version we load the colors directly not from vbo
// For this version we load the colors directly, not from vbo
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glEnableClientState(GL_VERTEX_ARRAY);
......@@ -1329,13 +1330,10 @@ pick_any(GLState& _state)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDepthFunc(depthFunc());
// disable all other arrays
enable_arrays(0);
}
if (anyPickingList_)
{
glEndList ();
......@@ -1343,8 +1341,9 @@ pick_any(GLState& _state)
glCallList (anyPickingList_+1);
glCallList (anyPickingList_+2);
}
glCheckErrors();
glDepthFunc(prev_depth);
glCheckErrors();
}
template<class Mesh>
......
......@@ -398,7 +398,7 @@ public:
private:
/** \brief Renders picking for vertices
*
* _front: Only render front vertices (not occluded by geometry)
*/
void pick_vertices(GLState& _state, bool _front = false);
......@@ -422,7 +422,7 @@ private:
private:
/** \brief Renders picking for edges
*
* _front: Only render front edges (not occluded by geometry)
*/
void pick_edges(GLState& _state, bool _front = false);
......@@ -445,7 +445,7 @@ private:
private:
/** \brief Renders picking for faces
*
* _front: Only render front faces (not occluded by geometry)
*/
void pick_faces(GLState& _state);
......
......@@ -564,8 +564,8 @@ void
MeshNodeT<Mesh>::
draw(GLState& _state, DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (_drawMode & DrawModes::POINTS)
{
......@@ -632,7 +632,7 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
glDepthFunc(GL_LEQUAL);
_state.set_base_color(base_color);
draw_faces(PER_VERTEX);
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
......@@ -881,7 +881,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
enable_arrays(0);
glDepthFunc(GL_LESS);
}
......@@ -1238,6 +1237,9 @@ void
MeshNodeT<Mesh>::
pick_vertices(GLState& _state, bool _front)
{
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end());
GLuint idx(0);
......@@ -1277,8 +1279,7 @@ pick_vertices(GLState& _state, bool _front)
if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_)
{
glCallList (vertexList_);
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
return;
}
......@@ -1326,9 +1327,8 @@ pick_vertices(GLState& _state, bool _front)
glEndList ();
glCallList (vertexList_);
}
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
}
......@@ -1339,7 +1339,7 @@ template<class Mesh>
void
MeshNodeT<Mesh>::
pick_faces(GLState& _state)
{
{
typename Mesh::ConstFaceIter f_it(mesh_.faces_sbegin()),
f_end(mesh_.faces_end());
typename Mesh::ConstFaceVertexIter fv_it;
......@@ -1492,6 +1492,9 @@ pick_edges(GLState& _state, bool _front)
typename Mesh::ConstEdgeIter e_it(mesh_.edges_sbegin()),
e_end(mesh_.edges_end());
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (!_state.pick_set_maximum (mesh_.n_edges()))
{
omerr() << "MeshNode::pick_edges: color range too small, "
......@@ -1526,8 +1529,7 @@ pick_edges(GLState& _state, bool _front)
if (edgeList_ && !updateEdgeList_ && _state.pick_current_index () == edgeBaseIndex_)
{
glCallList (edgeList_);
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
return;
}
......@@ -1580,9 +1582,8 @@ pick_edges(GLState& _state, bool _front)
glEndList ();
glCallList (edgeList_);
}
if (_front)
glDepthFunc(depthFunc());
glDepthFunc(prev_depth);
}
//----------------------------------------------------------------------------
......@@ -1593,6 +1594,9 @@ void
MeshNodeT<Mesh>::
pick_any(GLState& _state)
{
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
// nothing to pick ?
......@@ -1740,8 +1744,6 @@ pick_any(GLState& _state)
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDepthFunc(depthFunc());
}
else
{
......@@ -1808,11 +1810,8 @@ pick_any(GLState& _state)
glVertex(mesh_.point(v_it));
glEnd();
}
glDepthFunc(depthFunc());
}
if (anyList_)
{
glEndList ();
......@@ -1820,6 +1819,8 @@ pick_any(GLState& _state)
glCallList (anyList_+1);
glCallList (anyList_+2);
}
glDepthFunc(prev_depth);
}
//----------------------------------------------------------------------------
......
......@@ -203,8 +203,6 @@ void
MeshNodeT<Mesh>::
draw(GLState& _state, DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
if ( ( _drawMode & DrawModes::SOLID_ENV_MAPPED ) && mesh_.has_vertex_normals())
{
enable_arrays(VERTEX_ARRAY | NORMAL_ARRAY);
......
......@@ -96,9 +96,6 @@ void
PointNode::
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
// points
if (_drawMode & DrawModes::POINTS)
{
......@@ -143,8 +140,6 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDepthFunc(GL_LESS);
}
......
......@@ -132,8 +132,6 @@ void
QuadNode::
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
if (_drawMode & DrawModes::WIREFRAME ||
_drawMode & DrawModes::HIDDENLINE )
{
......
......@@ -79,8 +79,6 @@ StatusNodeT( const Mesh& _mesh,
bbMin_(FLT_MAX, FLT_MAX, FLT_MAX),
bbMax_(-FLT_MAX, -FLT_MAX, -FLT_MAX)
{
depthFunc(GL_LEQUAL);
set_line_width(3);
set_point_size(5);
}
......@@ -238,7 +236,10 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
(_drawMode & DrawModes::SOLID_FLAT_SHADED));
glDepthFunc(depthFunc());
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
glDepthFunc(GL_LEQUAL);
if (shaded) glEnable(GL_LIGHTING);
else glDisable(GL_LIGHTING);
......@@ -256,8 +257,7 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(mesh_.points());
// points
if (points)
......@@ -310,11 +310,10 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
}
}
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDepthFunc(GL_LESS);
glDepthFunc(prev_depth);
}
......@@ -326,7 +325,6 @@ void
StatusNodeT<Mesh, Mod>::
draw_points()
{
if ( !v_cache_.empty() )
glDrawElements(GL_POINTS,
v_cache_.size(),
......
......@@ -132,8 +132,6 @@ void
TriangleNode::
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{
glDepthFunc(depthFunc());
if (_drawMode & DrawModes::WIREFRAME ||
_drawMode & DrawModes::HIDDENLINE )
{
......
......@@ -429,15 +429,15 @@ void SelectionPlugin::surfaceLassoSelection(QMouseEvent* _event){
if ( PluginFunctions::getPickedObject(node_idx, object) ) {
if ( polyLineID_ == -1){
emit log("Polyline -1");
if ( polyLineID_ == -1) {
emit log("Polyline -1");
//switch back to PolyLine drawing
PluginFunctions::actionMode( Viewer::PickingMode );
waitingForPolyLineSelection_ = true;
PluginFunctions::pickMode("PolyLine");
//switch back to PolyLine drawing
PluginFunctions::actionMode( Viewer::PickingMode );
waitingForPolyLineSelection_ = true;
PluginFunctions::pickMode("PolyLine");
return;