Commit 2149201e authored by Marlin Frickenschmidt's avatar Marlin Frickenschmidt

Fixed a bug in MeshNode2T that would permanently change the depth comparison...

Fixed a bug in MeshNode2T that would permanently change the depth comparison function instead of only temporarily

Changed scenegraph nodes to use new GLState getter/setter for depth comparison function

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@10105 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0b840ec2
......@@ -827,10 +827,10 @@ void GLState::viewing_ray( int _x, int _y,
const GLenum& GLState::depthFunc() const
{
///\todo Remove this additional check if there are no errors here ever.
GLint prev_depth;
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth);
if (depth_func_ != prev_depth)
std::cerr << "GLState depth_func_ doesn't match actual enabled GL_DEPTH_FUNC!" << std::endl;
GLenum real_depth;
glGetIntegerv (GL_DEPTH_FUNC, (GLint*) &real_depth);
if (depth_func_ != real_depth)
std::cerr << "GLState depth_func_ ("<<depth_func_<<") doesn't match actual enabled GL_DEPTH_FUNC ("<<real_depth<<")!" << std::endl;
return depth_func_;
}
......
......@@ -315,9 +315,9 @@ public:
*/
void viewing_ray(int _x, int _y, Vec3d& _origin, Vec3d& _direction) const;
/// get glDepthFunc() parameter
/// get glDepthFunc() that is supposed to be active
const GLenum& depthFunc() const;
/// set glDepthFunc() parameter
/// Call glDepthFunc() to actually change the depth comparison function, and store the new value in this GLState
void set_depthFunc(const GLenum& _depth_func);
//--- project and unproject points ------------------------------------------
......
......@@ -210,6 +210,8 @@ void
CoordsysNode::
draw(GLState& _state , DrawModes::DrawMode /*_drawMode*/)
{
GLenum prev_depth = _state.depthFunc();
GLboolean colorMask[4];
glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
......@@ -287,7 +289,7 @@ draw(GLState& _state , DrawModes::DrawMode /*_drawMode*/)
drawCoordsys(_state);
glDepthRange (0.0, 1.0);
glDepthFunc (GL_LESS);
glDepthFunc (prev_depth);
glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
// Projection reload
......@@ -328,9 +330,8 @@ draw(GLState& _state , DrawModes::DrawMode /*_drawMode*/)
// reset to default
glDepthRange (0.0, 1.0);
glDepthFunc (GL_LESS);
glDepthFunc (prev_depth);
glColorMask (colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
}
glPopAttrib();
......@@ -366,6 +367,8 @@ getMode() const
void
CoordsysNode::pick(GLState& _state, PickTarget _target)
{
GLenum prev_depth = _state.depthFunc();
if (_target == PICK_ANYTHING) {
GLdouble mat[16];
......@@ -453,7 +456,7 @@ CoordsysNode::pick(GLState& _state, PickTarget _target)
// reset to default
glDepthRange (0.0, 1.0);
glDepthFunc (GL_LESS);
glDepthFunc (prev_depth);
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
......@@ -523,7 +526,7 @@ CoordsysNode::pick(GLState& _state, PickTarget _target)
// reset to default
glDepthRange (0.0, 1.0);
glDepthFunc (GL_LESS);
glDepthFunc (prev_depth);
glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
}
......@@ -537,6 +540,8 @@ CoordsysNode::pick(GLState& _state, PickTarget _target)
void CoordsysNode::clearPickArea(GLState& _state, bool _draw, GLfloat _depth)
{
GLenum prev_depth = _state.depthFunc();
std::vector<Vec2f> points;
Vec2f center;
float radius;
......@@ -585,7 +590,7 @@ void CoordsysNode::clearPickArea(GLState& _state, bool _draw, GLfloat _depth)
// 10% more to ensure everything is in
gluDisk( quadric, 0, radius * 1.1, 10, 10 );
glDepthFunc (GL_LESS);
glDepthFunc (prev_depth);
_state.pop_modelview_matrix();
_state.pop_projection_matrix();
......
......@@ -97,10 +97,9 @@ enter(GLState& _state , DrawModes::DrawMode _drawMode)
if (alwaysOnTop()) {
//store current depth comparison function (needed for lasso selection)
glGetIntegerv (GL_DEPTH_FUNC, &prev_depth_);
prev_depth_ = _state.depthFunc();
//set depth function and change GLState accordingly
glDepthFunc(GL_ALWAYS);
_state.set_depthFunc(GL_ALWAYS);
}
}
......@@ -156,7 +155,6 @@ leave(GLState& _state , DrawModes::DrawMode _drawMode)
{
if (alwaysOnTop()) {
//restore depth function and change GLState accordingly
glDepthFunc(prev_depth_);
_state.set_depthFunc(prev_depth_);
}
......
......@@ -157,6 +157,7 @@ void Material2Node::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
if (applyProperties_ & Blending)
{
blending_backup_ = _state.blending();
depth_backup_ = _state.depthFunc();
glGetIntegerv( GL_BLEND_SRC, (GLint*) &blend_param1_backup_);
glGetIntegerv( GL_BLEND_DST, (GLint*) &blend_param2_backup_);
......@@ -164,13 +165,13 @@ void Material2Node::enter(GLState& _state, DrawModes::DrawMode /* _drawmode */ )
if (blending_)
{
glDepthFunc(GL_LEQUAL);
_state.set_depthFunc(GL_LEQUAL);
glBlendFunc(blend_param1_, blend_param2_);
glEnable(GL_BLEND);
}
else
{
glDepthFunc(GL_LESS);
_state.set_depthFunc(GL_LESS);
glDisable(GL_BLEND);
}
}
......@@ -260,16 +261,15 @@ void Material2Node::leave(GLState& _state, DrawModes::DrawMode /* _drawmode*/ )
if (applyProperties_ & Blending)
{
_state.set_blending(blending_backup_);
_state.set_depthFunc(depth_backup_);
if (blending_backup_)
{
glDepthFunc(GL_LEQUAL);
glBlendFunc(blend_param1_backup_, blend_param2_backup_);
glEnable(GL_BLEND);
}
else
{
glDepthFunc(GL_LESS);
glDisable(GL_BLEND);
}
}
......
......@@ -259,6 +259,7 @@ private:
bool blending_, blending_backup_;
GLenum blend_param1_, blend_param1_backup_;
GLenum blend_param2_, blend_param2_backup_;
GLenum depth_backup_;
bool backface_culling_, backface_culling_backup_;
......
......@@ -168,13 +168,13 @@ void MaterialNode::enter(GLState& _state, DrawModes::DrawMode _drawmode )
if (material_.blending_)
{
glDepthFunc(GL_LEQUAL);
_state.set_depthFunc(GL_LEQUAL);
glBlendFunc(material_.blendParam1_, material_.blendParam2_);
glEnable(GL_BLEND);
}
else
{
glDepthFunc(GL_LESS);
_state.set_depthFunc(GL_LESS);
glDisable(GL_BLEND);
}
}
......@@ -291,13 +291,13 @@ void MaterialNode::leave(GLState& _state, DrawModes::DrawMode _drawmode )
if (materialBackup_.blending_)
{
glDepthFunc(GL_LEQUAL);
_state.set_depthFunc(GL_LEQUAL);
glBlendFunc(materialBackup_.blendParam1_, materialBackup_.blendParam2_);
glEnable(GL_BLEND);
}
else
{
glDepthFunc(GL_LESS);
_state.set_depthFunc(GL_LESS);
glDisable(GL_BLEND);
}
}
......
......@@ -221,9 +221,9 @@ draw(GLState& _state, DrawModes::DrawMode _drawMode) {
// Update strips if necessary
stripProcessor_.stripify();
GLenum prev_depth = _state.depthFunc();
unsigned int arrays = VERTEX_ARRAY;
glPushAttrib(GL_ENABLE_BIT);
......@@ -490,6 +490,7 @@ template<class Mesh>
void
MeshNodeT<Mesh>::
draw_vertices() {
if ( !vertexBufferInitialized_ || ( mesh_.n_vertices() == 0 ))
return;
......@@ -987,7 +988,7 @@ template<class Mesh>
void
MeshNodeT<Mesh>::
pick_vertices(GLState& _state, bool _front)
{
{
GLenum prev_depth = _state.depthFunc();
typename Mesh::ConstVertexIter v_it(mesh_.vertices_begin()),
......@@ -1060,20 +1061,20 @@ pick_vertices(GLState& _state, bool _front)
} else
std::cerr << "Fallback not available pick_vertices!" << std::endl;
glDepthFunc(prev_depth);
if (vertexPickingList_) {
glEndList ();
glCallList (vertexPickingList_);
}
glDepthFunc(prev_depth);
}
template<class Mesh>
void
MeshNodeT<Mesh>::
pick_edges(GLState& _state, bool _front)
{
{
GLenum prev_depth = _state.depthFunc();
if (!_state.pick_set_maximum (mesh_.n_edges())) {
......@@ -1151,12 +1152,12 @@ pick_edges(GLState& _state, bool _front)
std::cerr << "No fallback pick_edges!" << std::endl;
}
glDepthFunc(prev_depth);
if (edgePickingList_) {
glEndList ();
glCallList (edgePickingList_);
}
glDepthFunc(prev_depth);
}
template<class Mesh>
......@@ -1234,9 +1235,8 @@ template<class Mesh>
void
MeshNodeT<Mesh>::
pick_any(GLState& _state)
{
{
GLenum prev_depth = _state.depthFunc();
unsigned int numElements = mesh_.n_faces() + mesh_.n_edges() + mesh_.n_vertices();
if ( mesh_.n_vertices() == 0 ) {
......@@ -1287,7 +1287,6 @@ pick_any(GLState& _state)
glColorPointer( stripProcessor_.pickFaceColorBuffer() );
glDrawArrays(GL_TRIANGLES, 0, stripProcessor_.perFaceVertexBufferSize() );
}
if (anyPickingList_)
......@@ -1309,8 +1308,13 @@ pick_any(GLState& _state)
if (anyPickingList_)
{
//restore depth buffer comparison function for this display list
glDepthFunc(prev_depth);
glEndList ();
glNewList (anyPickingList_+2, GL_COMPILE);
glDepthFunc(GL_LEQUAL);
}
enable_arrays(VERTEX_ARRAY);
......@@ -1330,6 +1334,9 @@ pick_any(GLState& _state)
enable_arrays(0);
}
//restore depth buffer comparison function for the active display list
glDepthFunc(prev_depth);
if (anyPickingList_)
{
glEndList ();
......@@ -1338,7 +1345,6 @@ pick_any(GLState& _state)
glCallList (anyPickingList_+2);
}
glDepthFunc(prev_depth);
glCheckErrors();
}
......
......@@ -1721,8 +1721,10 @@ pick_any(GLState& _state)
if (anyList_)
{
glDepthFunc(prev_depth);
glEndList ();
glNewList (anyList_+2, GL_COMPILE);
glDepthFunc(GL_LEQUAL);
}
// vertices
......@@ -1776,6 +1778,7 @@ pick_any(GLState& _state)
if (anyList_)
{
glDepthFunc(prev_depth);
glEndList ();
glNewList (anyList_+1, GL_COMPILE);
}
......@@ -1794,8 +1797,10 @@ pick_any(GLState& _state)
if (anyList_)
{
glDepthFunc(prev_depth);
glEndList ();
glNewList (anyList_+2, GL_COMPILE);
glDepthFunc(GL_LEQUAL);
}
// vertices
......@@ -1807,7 +1812,9 @@ pick_any(GLState& _state)
glEnd();
}
}
glDepthFunc(prev_depth);
if (anyList_)
{
glEndList ();
......@@ -1815,8 +1822,6 @@ pick_any(GLState& _state)
glCallList (anyList_+1);
glCallList (anyList_+2);
}
glDepthFunc(prev_depth);
}
//----------------------------------------------------------------------------
......
......@@ -688,6 +688,8 @@ void TranslationManipulatorNode::drawManipulator (GLState& _state, bool _active)
void
TranslationManipulatorNode::draw(GLState& _state, DrawModes::DrawMode /* _drawMode */ )
{
GLenum prev_depth = _state.depthFunc();
if (draw_manipulator_) {
// Store lighting bits and enable lighting
......@@ -737,6 +739,8 @@ TranslationManipulatorNode::draw(GLState& _state, DrawModes::DrawMode /* _drawMo
// restore active colors
_state.set_diffuse_color(backup_diffuse);
_state.set_specular_color(backup_specular);
glDepthFunc(prev_depth);
}
}
......@@ -1735,6 +1739,8 @@ void
TranslationManipulatorNode::
pick(GLState& _state, PickTarget _target)
{
GLenum prev_depth = _state.depthFunc();
if (_target == PICK_FACE ||
_target == PICK_ANYTHING) {
......@@ -1847,8 +1853,10 @@ pick(GLState& _state, PickTarget _target)
// Restore old attributes and modelview
glPopAttrib();
_state.pop_modelview_matrix();
//restore original depth comparison function
glDepthFunc(prev_depth);
}
}
}
......
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