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) ...@@ -80,7 +80,8 @@ GLState::GLState(bool _updateGL)
mipmapping_(true), mipmapping_(true),
updateGL_(_updateGL), updateGL_(_updateGL),
blending_(false), blending_(false),
msSinceLastRedraw_ (1) msSinceLastRedraw_ (1),
depth_func_(GL_LESS)
{ {
initialize(); initialize();
} }
......
...@@ -314,6 +314,9 @@ public: ...@@ -314,6 +314,9 @@ public:
_direction will be nornalized. _direction will be nornalized.
*/ */
void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const; 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 ------------------------------------------ //--- project and unproject points ------------------------------------------
...@@ -585,6 +588,9 @@ private: //-------------------------------------------------------------------- ...@@ -585,6 +588,9 @@ private: //--------------------------------------------------------------------
// are we using color picking // are we using color picking
bool colorPicking_; bool colorPicking_;
// depth comparison function (GL_LESS by default)
GLenum depth_func_;
}; };
......
...@@ -79,7 +79,6 @@ BaseNode(BaseNode* _parent, std::string _name) ...@@ -79,7 +79,6 @@ BaseNode(BaseNode* _parent, std::string _name)
name_(_name), name_(_name),
status_(Active), status_(Active),
drawMode_(DrawModes::DEFAULT), drawMode_(DrawModes::DEFAULT),
depth_func_(GL_LESS),
pickingEnabled_(true), pickingEnabled_(true),
dirty_ (false), dirty_ (false),
traverseMode_ (BaseNode::NodeFirst) traverseMode_ (BaseNode::NodeFirst)
......
...@@ -209,13 +209,6 @@ public: ...@@ -209,13 +209,6 @@ public:
/// Handle mouse event (some interaction, e.g. modeling) /// Handle mouse event (some interaction, e.g. modeling)
virtual void mouseEvent(GLState& /* _state */, QMouseEvent* /* _event */ ) {} 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 /// mark node for redrawn
void setDirty (bool _dirty = true) { dirty_ = _dirty; } void setDirty (bool _dirty = true) { dirty_ = _dirty; }
...@@ -555,9 +548,6 @@ private: ...@@ -555,9 +548,6 @@ private:
/// private draw mode /// private draw mode
DrawModes::DrawMode drawMode_; DrawModes::DrawMode drawMode_;
/// depth func
GLenum depth_func_;
/** Flag indicating if picking should be done for this object /** Flag indicating if picking should be done for this object
* This flag has to be checked by your node if you implement picking * This flag has to be checked by your node if you implement picking
......
...@@ -138,9 +138,7 @@ availableDrawModes() const ...@@ -138,9 +138,7 @@ availableDrawModes() const
void void
GlutPrimitiveNode:: GlutPrimitiveNode::
draw(GLState& _state, DrawModes::DrawMode _drawMode) draw(GLState& _state, DrawModes::DrawMode _drawMode)
{ {
glDepthFunc(depthFunc());
for (int i = 0; i < (int)primitives_.size(); ++i) for (int i = 0; i < (int)primitives_.size(); ++i)
{ {
...@@ -235,8 +233,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) ...@@ -235,8 +233,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
glPopMatrix(); glPopMatrix();
} // end of primitives iter } // end of primitives iter
glDepthFunc(GL_LESS);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
......
...@@ -89,13 +89,28 @@ availableDrawModes() const ...@@ -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 void
LineNode:: LineNode::
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode) draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{ {
glDepthFunc(depthFunc());
if (_drawMode & DrawModes::WIREFRAME) if (_drawMode & DrawModes::WIREFRAME)
{ {
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
...@@ -131,10 +146,22 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode) ...@@ -131,10 +146,22 @@ draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
glEnd(); 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: ...@@ -103,7 +103,9 @@ public:
_name, _name,
MaterialNode::BaseColor | MaterialNode::BaseColor |
MaterialNode::LineWidth), MaterialNode::LineWidth),
line_mode_(_mode) line_mode_(_mode),
draw_always_on_top (false),
prev_depth_(GL_LESS)
{ {
drawMode(DrawModes::WIREFRAME); drawMode(DrawModes::WIREFRAME);
} }
...@@ -116,7 +118,6 @@ public: ...@@ -116,7 +118,6 @@ public:
void set_line_mode(LineMode _mode) { line_mode_ = _mode; } void set_line_mode(LineMode _mode) { line_mode_ = _mode; }
/// static name of this class /// static name of this class
ACG_CLASSNAME(LineNode); ACG_CLASSNAME(LineNode);
...@@ -125,16 +126,20 @@ public: ...@@ -125,16 +126,20 @@ public:
/// update bounding box /// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax); 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 /// draw lines and normals
void draw(GLState& _state, DrawModes::DrawMode _drawMode); 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 /// reserve mem for _n lines
void reserve_lines(unsigned int _n) { points_.reserve(2*_n); } void reserve_lines(unsigned int _n) { points_.reserve(2*_n); }
/// reserve mem for _n points /// reserve mem for _n points
void reserve_points(unsigned int _n) { points_.reserve(_n); } void reserve_points(unsigned int _n) { points_.reserve(_n); }
...@@ -163,8 +168,11 @@ public: ...@@ -163,8 +168,11 @@ public:
/// return reference to point vector /// return reference to point vector
const PointVector& points() const { return points_; } const PointVector& points() const { return points_; }
/// get color container /// get and set color container
ColorVector& colors() { return colors_; } ColorVector& colors() { return colors_; }
/// get and set always on top
bool& alwaysOnTop() { return draw_always_on_top; }
/// STL conformance /// STL conformance
...@@ -180,6 +188,9 @@ protected: ...@@ -180,6 +188,9 @@ protected:
ColorVector colors_; ColorVector colors_;
LineMode line_mode_; LineMode line_mode_;
bool draw_always_on_top;
GLint prev_depth_;
}; };
......
...@@ -222,8 +222,8 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) { ...@@ -222,8 +222,8 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
// Update strips if necessary // Update strips if necessary
stripProcessor_.stripify(); stripProcessor_.stripify();
/// \todo Whats this? Why is this set here GLint prev_depth;
glDepthFunc(depthFunc()); glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
unsigned int arrays = VERTEX_ARRAY; unsigned int arrays = VERTEX_ARRAY;
...@@ -295,7 +295,9 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) { ...@@ -295,7 +295,9 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
_state.set_base_color(base_color); _state.set_base_color(base_color);
draw_lines(); 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); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} }
...@@ -482,9 +484,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) { ...@@ -482,9 +484,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
// Unbind all remaining buffers // Unbind all remaining buffers
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB , 0 ); 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(); glPopAttrib();
} }
...@@ -990,10 +989,12 @@ void ...@@ -990,10 +989,12 @@ void
MeshNodeT<Mesh>:: MeshNodeT<Mesh>::
pick_vertices(GLState& _state, bool _front) pick_vertices(GLState& _state, bool _front)
{ {
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()), typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end()); v_end(mesh_.vertices_end());
if (!_state.pick_set_maximum (mesh_.n_vertices())) { if (!_state.pick_set_maximum (mesh_.n_vertices())) {
omerr() << "MeshNode::pick_vertices: color range too small, " << "picking failed\n"; omerr() << "MeshNode::pick_vertices: color range too small, " << "picking failed\n";
return; return;
...@@ -1030,8 +1031,7 @@ pick_vertices(GLState& _state, bool _front) ...@@ -1030,8 +1031,7 @@ pick_vertices(GLState& _state, bool _front)
if (vertexPickingList_ && !updateVertexPickingList_ && _state.pick_current_index () == vertexPickingBaseIndex_) { if (vertexPickingList_ && !updateVertexPickingList_ && _state.pick_current_index () == vertexPickingBaseIndex_) {
glCallList (vertexPickingList_); glCallList (vertexPickingList_);
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
return; return;
} }
...@@ -1062,14 +1062,13 @@ pick_vertices(GLState& _state, bool _front) ...@@ -1062,14 +1062,13 @@ pick_vertices(GLState& _state, bool _front)
} else } else
std::cerr << "Fallback not available pick_vertices!" << std::endl; std::cerr << "Fallback not available pick_vertices!" << std::endl;
if (vertexPickingList_) { if (vertexPickingList_) {
glEndList (); glEndList ();
glCallList (vertexPickingList_); glCallList (vertexPickingList_);
} }
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
} }
template<class Mesh> template<class Mesh>
...@@ -1077,7 +1076,9 @@ void ...@@ -1077,7 +1076,9 @@ void
MeshNodeT<Mesh>:: MeshNodeT<Mesh>::
pick_edges(GLState& _state, bool _front) pick_edges(GLState& _state, bool _front)
{ {
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (!_state.pick_set_maximum (mesh_.n_edges())) { if (!_state.pick_set_maximum (mesh_.n_edges())) {
omerr() << "MeshNode::pick_edges: color range too small, " << "picking failed\n"; omerr() << "MeshNode::pick_edges: color range too small, " << "picking failed\n";
return; return;
...@@ -1114,8 +1115,7 @@ pick_edges(GLState& _state, bool _front) ...@@ -1114,8 +1115,7 @@ pick_edges(GLState& _state, bool _front)
if (edgePickingList_ && !updateEdgePickingList_ && _state.pick_current_index () == edgePickingBaseIndex_) { if (edgePickingList_ && !updateEdgePickingList_ && _state.pick_current_index () == edgePickingBaseIndex_) {
glCallList (edgePickingList_); glCallList (edgePickingList_);
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
return; return;
} }
...@@ -1159,8 +1159,7 @@ pick_edges(GLState& _state, bool _front) ...@@ -1159,8 +1159,7 @@ pick_edges(GLState& _state, bool _front)
glCallList (edgePickingList_); glCallList (edgePickingList_);
} }
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
} }
template<class Mesh> template<class Mesh>
...@@ -1239,7 +1238,9 @@ void ...@@ -1239,7 +1238,9 @@ void
MeshNodeT<Mesh>:: MeshNodeT<Mesh>::
pick_any(GLState& _state) 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(); unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
if ( mesh_.n_vertices() == 0 ) { if ( mesh_.n_vertices() == 0 ) {
...@@ -1277,7 +1278,7 @@ pick_any(GLState& _state) ...@@ -1277,7 +1278,7 @@ pick_any(GLState& _state)
stripProcessor_.updatePickingAny(_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); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
...@@ -1329,13 +1330,10 @@ pick_any(GLState& _state) ...@@ -1329,13 +1330,10 @@ pick_any(GLState& _state)
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDepthFunc(depthFunc());
// disable all other arrays // disable all other arrays
enable_arrays(0); enable_arrays(0);
} }
if (anyPickingList_) if (anyPickingList_)
{ {
glEndList (); glEndList ();
...@@ -1343,8 +1341,9 @@ pick_any(GLState& _state) ...@@ -1343,8 +1341,9 @@ pick_any(GLState& _state)
glCallList (anyPickingList_+1); glCallList (anyPickingList_+1);
glCallList (anyPickingList_+2); glCallList (anyPickingList_+2);
} }
glCheckErrors(); glDepthFunc(prev_depth);
glCheckErrors();
} }
template<class Mesh> template<class Mesh>
......
...@@ -398,7 +398,7 @@ public: ...@@ -398,7 +398,7 @@ public:
private: private:
/** \brief Renders picking for vertices /** \brief Renders picking for vertices
* * _front: Only render front vertices (not occluded by geometry)
*/ */
void pick_vertices(GLState& _state, bool _front = false); void pick_vertices(GLState& _state, bool _front = false);
...@@ -422,7 +422,7 @@ private: ...@@ -422,7 +422,7 @@ private:
private: private:
/** \brief Renders picking for edges /** \brief Renders picking for edges
* * _front: Only render front edges (not occluded by geometry)
*/ */
void pick_edges(GLState& _state, bool _front = false); void pick_edges(GLState& _state, bool _front = false);
...@@ -445,7 +445,7 @@ private: ...@@ -445,7 +445,7 @@ private:
private: private:
/** \brief Renders picking for faces /** \brief Renders picking for faces
* * _front: Only render front faces (not occluded by geometry)
*/ */
void pick_faces(GLState& _state); void pick_faces(GLState& _state);
......
...@@ -564,8 +564,8 @@ void ...@@ -564,8 +564,8 @@ void
MeshNodeT<Mesh>:: MeshNodeT<Mesh>::
draw(GLState& _state, DrawModes::DrawMode _drawMode) draw(GLState& _state, DrawModes::DrawMode _drawMode)
{ {
glDepthFunc(depthFunc()); GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (_drawMode & DrawModes::POINTS) if (_drawMode & DrawModes::POINTS)
{ {
...@@ -632,7 +632,7 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) ...@@ -632,7 +632,7 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
_state.set_base_color(base_color); _state.set_base_color(base_color);
draw_faces(PER_VERTEX); draw_faces(PER_VERTEX);
glDepthFunc(depthFunc()); glDepthFunc(prev_depth);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} }
...@@ -881,7 +881,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) ...@@ -881,7 +881,6 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode)
enable_arrays(0); enable_arrays(0);
glDepthFunc(GL_LESS);
} }
...@@ -1238,6 +1237,9 @@ void ...@@ -1238,6 +1237,9 @@ void
MeshNodeT<Mesh>:: MeshNodeT<Mesh>::
pick_vertices(GLState& _state, bool _front) pick_vertices(GLState& _state, bool _front)
{ {
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()), typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
v_end(mesh_.vertices_end()); v_end(mesh_.vertices_end());
GLuint idx(0); GLuint idx(0);
...@@ -1277,8 +1279,7 @@ pick_vertices(GLState& _state, bool _front) ...@@ -1277,8 +1279,7 @@ pick_vertices(GLState& _state, bool _front)
if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_) if (vertexList_ && !updateVertexList_ && _state.pick_current_index () == vertexBaseIndex_)
{ {
glCallList (vertexList_); glCallList (vertexList_);
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
return; return;
} }
...@@ -1326,9 +1327,8 @@ pick_vertices(GLState& _state, bool _front) ...@@ -1326,9 +1327,8 @@ pick_vertices(GLState& _state, bool _front)
glEndList (); glEndList ();
glCallList (vertexList_); glCallList (vertexList_);
} }
if (_front) glDepthFunc(prev_depth);
glDepthFunc(depthFunc());
}