From aa83b20b8ea0eb50c6e6d54b94a4fe3cdd3afc70 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Tue, 7 Feb 2023 10:01:09 +0100 Subject: [PATCH] Small optimizations in rendering functions --- src/slic3r/GUI/3DScene.cpp | 13 ++++++++----- src/slic3r/GUI/GLCanvas3D.cpp | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 185ebb743..0a07cb6f9 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -385,8 +385,10 @@ void GLVolume::render() GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) return; + + const bool is_left_handed = this->is_left_handed(); - if (this->is_left_handed()) + if (is_left_handed) glsafe(::glFrontFace(GL_CW)); glsafe(::glCullFace(GL_BACK)); @@ -395,7 +397,7 @@ void GLVolume::render() else model.render(this->tverts_range); - if (this->is_left_handed()) + if (is_left_handed) glsafe(::glFrontFace(GL_CCW)); } @@ -793,6 +795,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glsafe(::glDisable(GL_CULL_FACE)); for (GLVolumeWithIdAndZ& volume : to_render) { + const Transform3d& world_matrix = volume.first->world_matrix(); volume.first->set_render_color(true); // render sinking contours of non-hovered volumes @@ -814,9 +817,9 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab shader->set_uniform("print_volume.type", static_cast(m_print_volume.type)); shader->set_uniform("print_volume.xy_data", m_print_volume.data); shader->set_uniform("print_volume.z_data", m_print_volume.zs); - shader->set_uniform("volume_world_matrix", volume.first->world_matrix()); + shader->set_uniform("volume_world_matrix", world_matrix); shader->set_uniform("slope.actived", m_slope.active && !volume.first->is_modifier && !volume.first->is_wipe_tower); - shader->set_uniform("slope.volume_world_normal_matrix", static_cast(volume.first->world_matrix().matrix().block(0, 0, 3, 3).inverse().transpose().cast())); + shader->set_uniform("slope.volume_world_normal_matrix", static_cast(world_matrix.matrix().block(0, 0, 3, 3).inverse().transpose().cast())); shader->set_uniform("slope.normal_z", m_slope.normal_z); #if ENABLE_ENVIRONMENT_MAP @@ -829,7 +832,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab glcheck(); volume.first->model.set_color(volume.first->render_color); - const Transform3d model_matrix = volume.first->world_matrix(); + const Transform3d model_matrix = world_matrix; shader->set_uniform("view_model_matrix", view_matrix * model_matrix); shader->set_uniform("projection_matrix", projection_matrix); const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose(); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 82b6d3c95..880962434 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -818,8 +818,11 @@ static float get_cursor_height() void GLCanvas3D::Tooltip::set_text(const std::string& text) { // If the mouse is inside an ImGUI dialog, then the tooltip is suppressed. - m_text = m_in_imgui ? std::string() : text; - m_cursor_height = get_cursor_height(); + const std::string& new_text = m_in_imgui ? std::string() : text; + if (m_text != new_text) { // To avoid calling the expensive call to get_cursor_height. + m_text = new_text; + m_cursor_height = get_cursor_height(); + } } void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas)