Commit d7adb3a7 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

avoid expensive matrix update

parent ff9ae980
Pipeline #68 skipped
......@@ -339,8 +339,6 @@ void GLState::reset_projection()
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
update_matrices();
}
......@@ -359,8 +357,6 @@ void GLState::set_projection(const GLMatrixd& _m, const GLMatrixd& _inv_m)
glLoadMatrixd(projection_.get_raw_data());
glMatrixMode(GL_MODELVIEW);
}
update_matrices();
}
......@@ -377,8 +373,6 @@ void GLState::reset_modelview()
makeCurrent();
glLoadIdentity();
}
update_matrices();
}
......@@ -395,8 +389,6 @@ void GLState::set_modelview(const GLMatrixd& _m, const GLMatrixd& _inv_m)
makeCurrent();
glLoadMatrixd(modelview_.get_raw_data());
}
update_matrices();
}
......@@ -420,8 +412,6 @@ void GLState::ortho( double _left, double _right,
glOrtho(_left, _right, _bottom, _top, _n, _f);
glMatrixMode(GL_MODELVIEW);
}
update_matrices();
}
......@@ -445,8 +435,6 @@ void GLState::frustum( double _left, double _right,
glFrustum(_left, _right, _bottom, _top, _n, _f);
glMatrixMode(GL_MODELVIEW);
}
update_matrices();
}
......@@ -469,8 +457,6 @@ void GLState::perspective( double _fovY, double _aspect,
glLoadMatrixd(projection_.data());
glMatrixMode(GL_MODELVIEW);
}
update_matrices();
}
......@@ -516,8 +502,6 @@ void GLState::viewport( int _left, int _bottom,
makeCurrent();
glViewport(_left, _bottom, _width, _height);
}
update_matrices();
}
......@@ -536,8 +520,6 @@ void GLState::lookAt( const Vec3d& _eye,
makeCurrent();
glLoadMatrixd(modelview_.data());
}
update_matrices();
}
......@@ -563,8 +545,6 @@ void GLState::translate( double _x, double _y, double _z,
makeCurrent();
glLoadMatrixd(modelview_.get_raw_data());
}
update_matrices();
}
//-----------------------------------------------------------------------------
......@@ -596,8 +576,6 @@ void GLState::rotate( double _angle, double _x, double _y, double _z,
makeCurrent();
glLoadMatrixd(modelview_.get_raw_data());
}
update_matrices();
}
......@@ -623,8 +601,6 @@ void GLState::scale( double _sx, double _sy, double _sz,
makeCurrent();
glLoadMatrixd(modelview_.get_raw_data());
}
update_matrices();
}
......@@ -650,34 +626,18 @@ void GLState::mult_matrix( const GLMatrixd& _m, const GLMatrixd& _inv_m,
makeCurrent();
glLoadMatrixd(modelview_.get_raw_data());
}
update_matrices();
}
//-----------------------------------------------------------------------------
void GLState::update_matrices(bool _changedModelView,
bool _changedProjection,
bool _changedViewport)
{
forward_projection_ = window2viewport_;
forward_projection_ *= projection_;
forward_projection_ *= modelview_;
backward_projection_ = inverse_modelview_;
backward_projection_ *= inverse_projection_;
backward_projection_ *= inverse_window2viewport_;
}
//-----------------------------------------------------------------------------
Vec3d GLState::project(const Vec3d& _point) const
{
return forward_projection_.transform_point(_point);
Vec3d t = modelview_.transform_point(_point);
t = projection_.transform_point(t);
return window2viewport_.transform_point(t);
}
......@@ -686,7 +646,9 @@ Vec3d GLState::project(const Vec3d& _point) const
Vec3d GLState::unproject(const Vec3d& _winPoint) const
{
return backward_projection_.transform_point(_winPoint);
Vec3d t = inverse_window2viewport_.transform_point(_winPoint);
t = inverse_projection_.transform_point(t);
return inverse_modelview_.transform_point(t);
}
......@@ -1026,8 +988,6 @@ void GLState::pop_projection_matrix()
stack_projection_.pop();
stack_inverse_projection_.pop();
update_matrices();
if (updateGL_ && compatibilityProfile_)
{
makeCurrent();
......@@ -1046,8 +1006,6 @@ void GLState::push_modelview_matrix()
stack_modelview_.push(modelview_);
stack_inverse_modelview_.push(inverse_modelview_);
update_matrices();
if (updateGL_ && compatibilityProfile_)
{
makeCurrent();
......@@ -1067,8 +1025,6 @@ void GLState::pop_modelview_matrix()
stack_modelview_.pop();
stack_inverse_modelview_.pop();
update_matrices();
if (updateGL_ && compatibilityProfile_)
{
makeCurrent();
......
......@@ -801,8 +801,8 @@ public:
}
/// get forward projection matrix
const GLMatrixd& forward_projection() const {
return forward_projection_;
GLMatrixd forward_projection() const {
return window2viewport_ * projection_ * modelview_;
}
/// get inverse projection matrix
......@@ -1148,12 +1148,6 @@ public:
private: //--------------------------------------------------------------------
// update forward projection and backward projection matrices
void update_matrices(bool _changedModelView = true,
bool _changedProjection = true,
bool _changedViewport = true);
// matrix stacks
std::stack<GLMatrixd> stack_projection_,
stack_modelview_,
......
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