Added glsafe() around OpenGL calls where missing

This commit is contained in:
Enrico Turri 2019-03-27 14:42:09 +01:00
parent 30c4e4fed6
commit d795f07e7b
15 changed files with 544 additions and 534 deletions

View file

@ -75,13 +75,13 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S
void GLGizmoSlaSupports::on_render(const Selection& selection) const
{
::glEnable(GL_BLEND);
::glEnable(GL_DEPTH_TEST);
glsafe(::glEnable(GL_BLEND));
glsafe(::glEnable(GL_DEPTH_TEST));
render_points(selection, false);
render_selection_rectangle();
::glDisable(GL_BLEND);
glsafe(::glDisable(GL_BLEND));
}
void GLGizmoSlaSupports::render_selection_rectangle() const
@ -89,44 +89,44 @@ void GLGizmoSlaSupports::render_selection_rectangle() const
if (!m_selection_rectangle_active)
return;
::glLineWidth(1.5f);
glsafe(::glLineWidth(1.5f));
float render_color[3] = {1.f, 0.f, 0.f};
::glColor3fv(render_color);
glsafe(::glColor3fv(render_color));
::glPushAttrib(GL_TRANSFORM_BIT); // remember current MatrixMode
glsafe(::glPushAttrib(GL_TRANSFORM_BIT)); // remember current MatrixMode
::glMatrixMode(GL_MODELVIEW); // cache modelview matrix and set to identity
::glPushMatrix();
::glLoadIdentity();
glsafe(::glMatrixMode(GL_MODELVIEW)); // cache modelview matrix and set to identity
glsafe(::glPushMatrix());
glsafe(::glLoadIdentity());
::glMatrixMode(GL_PROJECTION); // cache projection matrix and set to identity
::glPushMatrix();
::glLoadIdentity();
glsafe(::glMatrixMode(GL_PROJECTION)); // cache projection matrix and set to identity
glsafe(::glPushMatrix());
glsafe(::glLoadIdentity());
::glOrtho(0.f, m_canvas_width, m_canvas_height, 0.f, -1.f, 1.f); // set projection matrix so that world coords = window coords
glsafe(::glOrtho(0.f, m_canvas_width, m_canvas_height, 0.f, -1.f, 1.f)); // set projection matrix so that world coords = window coords
// render the selection rectangle (window coordinates):
::glPushAttrib(GL_ENABLE_BIT);
::glLineStipple(4, 0xAAAA);
::glEnable(GL_LINE_STIPPLE);
glsafe(::glPushAttrib(GL_ENABLE_BIT));
glsafe(::glLineStipple(4, 0xAAAA));
glsafe(::glEnable(GL_LINE_STIPPLE));
::glBegin(GL_LINE_LOOP);
::glVertex3f((GLfloat)m_selection_rectangle_start_corner(0), (GLfloat)m_selection_rectangle_start_corner(1), (GLfloat)0.5f);
::glVertex3f((GLfloat)m_selection_rectangle_end_corner(0), (GLfloat)m_selection_rectangle_start_corner(1), (GLfloat)0.5f);
::glVertex3f((GLfloat)m_selection_rectangle_end_corner(0), (GLfloat)m_selection_rectangle_end_corner(1), (GLfloat)0.5f);
::glVertex3f((GLfloat)m_selection_rectangle_start_corner(0), (GLfloat)m_selection_rectangle_end_corner(1), (GLfloat)0.5f);
::glEnd();
::glPopAttrib();
glsafe(::glEnd());
glsafe(::glPopAttrib());
::glPopMatrix(); // restore former projection matrix
::glMatrixMode(GL_MODELVIEW);
::glPopMatrix(); // restore former modelview matrix
::glPopAttrib(); // restore former MatrixMode
glsafe(::glPopMatrix()); // restore former projection matrix
glsafe(::glMatrixMode(GL_MODELVIEW));
glsafe(::glPopMatrix()); // restore former modelview matrix
glsafe(::glPopAttrib()); // restore former MatrixMode
}
void GLGizmoSlaSupports::on_render_for_picking(const Selection& selection) const
{
::glEnable(GL_DEPTH_TEST);
glsafe(::glEnable(GL_DEPTH_TEST));
render_points(selection, true);
}
@ -137,16 +137,16 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
return;
if (!picking)
::glEnable(GL_LIGHTING);
glsafe(::glEnable(GL_LIGHTING));
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
double z_shift = vol->get_sla_shift_z();
const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
::glPushMatrix();
::glTranslated(0.0, 0.0, z_shift);
::glMultMatrixd(instance_matrix.data());
glsafe(::glPushMatrix());
glsafe(::glTranslated(0.0, 0.0, z_shift));
glsafe(::glMultMatrixd(instance_matrix.data()));
float render_color[3];
for (int i = 0; i < (int)m_editing_mode_cache.size(); ++i)
@ -178,14 +178,14 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
for (unsigned char i=0; i<3; ++i) render_color[i] = 0.5f;
}
}
::glColor3fv(render_color);
glsafe(::glColor3fv(render_color));
float render_color_emissive[4] = { 0.5f * render_color[0], 0.5f * render_color[1], 0.5f * render_color[2], 1.f};
::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive);
glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive));
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
::glPushMatrix();
::glTranslated(support_point.pos(0), support_point.pos(1), support_point.pos(2));
::glMultMatrixd(instance_scaling_matrix_inverse.data());
glsafe(::glPushMatrix());
glsafe(::glTranslated(support_point.pos(0), support_point.pos(1), support_point.pos(2)));
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
// Matrices set, we can render the point mark now.
// If in editing mode, we'll also render a cone pointing to the sphere.
@ -196,31 +196,31 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_mode_cache[i].normal.cast<double>());
Eigen::AngleAxisd aa(q);
::glRotated(aa.angle() * (180./M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2));
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2)));
const float cone_radius = 0.25f; // mm
const float cone_height = 0.75f;
::glPushMatrix();
::glTranslatef(0.f, 0.f, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale);
glsafe(::glPushMatrix());
glsafe(::glTranslatef(0.f, 0.f, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale));
::gluCylinder(m_quadric, 0.f, cone_radius, cone_height, 24, 1);
::glTranslatef(0.f, 0.f, cone_height);
glsafe(::glTranslatef(0.f, 0.f, cone_height));
::gluDisk(m_quadric, 0.0, cone_radius, 24, 1);
::glPopMatrix();
glsafe(::glPopMatrix());
}
::gluSphere(m_quadric, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale, 24, 12);
::glPopMatrix();
glsafe(::glPopMatrix());
}
{
// Reset emissive component to zero (the default value)
float render_color_emissive[4] = { 0.f, 0.f, 0.f, 1.f };
::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive);
glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive));
}
if (!picking)
::glDisable(GL_LIGHTING);
glsafe(::glDisable(GL_LIGHTING));
::glPopMatrix();
glsafe(::glPopMatrix());
}
bool GLGizmoSlaSupports::is_mesh_update_necessary() const
@ -264,11 +264,11 @@ std::pair<Vec3f, Vec3f> GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse
update_mesh();
Eigen::Matrix<GLint, 4, 1, Eigen::DontAlign> viewport;
::glGetIntegerv(GL_VIEWPORT, viewport.data());
glsafe(::glGetIntegerv(GL_VIEWPORT, viewport.data()));
Eigen::Matrix<GLdouble, 4, 4, Eigen::DontAlign> modelview_matrix;
::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix.data());
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix.data()));
Eigen::Matrix<GLdouble, 4, 4, Eigen::DontAlign> projection_matrix;
::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix.data());
glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix.data()));
Vec3d point1;
Vec3d point2;
@ -356,11 +356,11 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous
if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp) && m_selection_rectangle_active) {
const Transform3d& instance_matrix = m_model_object->instances[m_active_instance]->get_transformation().get_matrix();
GLint viewport[4];
::glGetIntegerv(GL_VIEWPORT, viewport);
glsafe(::glGetIntegerv(GL_VIEWPORT, viewport));
GLdouble modelview_matrix[16];
::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix);
glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix));
GLdouble projection_matrix[16];
::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix);
glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix));
const Selection& selection = m_parent.get_selection();
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());