From acd225cee288f00a7c5f31ab545a49316bec5b66 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 11 Jan 2022 09:09:09 +0100 Subject: [PATCH 01/22] Techs ENABLE_NEW_CAMERA_MOVEMENTS_XXXX - 1st installment - Modified camera manipulation and selection by mouse --- src/libslic3r/Technologies.hpp | 4 + src/slic3r/GUI/GLCanvas3D.cpp | 127 +++++++++++++++---- src/slic3r/GUI/GLSelectionRectangle.cpp | 12 +- src/slic3r/GUI/GLSelectionRectangle.hpp | 22 ++-- src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 4 +- 6 files changed, 126 insertions(+), 47 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 8f372e7c58..957a060eda 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -65,6 +65,10 @@ // Enable detection of layers for spiral vase prints #define ENABLE_SPIRAL_VASE_LAYERS (1 && ENABLE_2_4_1_RC) +// Enable modified camera control and selection using mouse +#define ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE (1 && ENABLE_2_4_1_RC) +#define ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE (1 && ENABLE_2_4_1_RC) +#define ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION (1 && ENABLE_2_4_1_RC) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 6d5bc3eb42..7a8c13e5d8 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1460,7 +1460,11 @@ void GLCanvas3D::render() wxGetApp().imgui()->new_frame(); if (m_picking_enabled) { +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (m_rectangle_selection.is_dragging() && !m_rectangle_selection.is_empty()) +#else if (m_rectangle_selection.is_dragging()) +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION // picking pass using rectangle selection _rectangular_selection_picking_pass(); else if (!m_volumes.empty()) @@ -2635,8 +2639,13 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) _update_selection_from_hover(); m_rectangle_selection.stop_dragging(); m_mouse.ignore_left_up = true; +#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_dirty = true; +#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION } +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + m_dirty = true; +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION // set_cursor(Standard); } else if (keyCode == WXK_ALT) { @@ -2680,15 +2689,16 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) if (keyCode == WXK_SHIFT) { translationProcessor.process(evt); - if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) - { + if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) { m_mouse.ignore_left_up = false; // set_cursor(Cross); } +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + m_dirty = true; +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION } else if (keyCode == WXK_ALT) { - if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) - { + if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) { m_mouse.ignore_left_up = false; // set_cursor(Cross); } @@ -3085,6 +3095,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_layers_editing.state = LayersEditing::Editing; _perform_layer_editing_action(&evt); } +#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION else if (evt.LeftDown() && (evt.ShiftDown() || evt.AltDown()) && m_picking_enabled) { if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports && m_gizmos.get_current_type() != GLGizmosManager::FdmSupports @@ -3094,23 +3105,52 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } } +#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION else { +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (evt.LeftDown() && (evt.ShiftDown() || evt.AltDown()) && m_picking_enabled) { + if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports + && m_gizmos.get_current_type() != GLGizmosManager::FdmSupports + && m_gizmos.get_current_type() != GLGizmosManager::Seam + && m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation) { + m_rectangle_selection.start_dragging(m_mouse.position, evt.ShiftDown() ? GLSelectionRectangle::EState::Select : GLSelectionRectangle::EState::Deselect); + m_dirty = true; + } + } +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + // Select volume in this 3D canvas. // Don't deselect a volume if layer editing is enabled or any gizmo is active. We want the object to stay selected // during the scene manipulation. +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (m_picking_enabled && (!any_gizmo_active || !evt.ShiftDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled())) { +#else if (m_picking_enabled && (!any_gizmo_active || !evt.CmdDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled())) { +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION if (evt.LeftDown() && !m_hover_volume_idxs.empty()) { int volume_idx = get_first_hover_volume_idx(); bool already_selected = m_selection.contains_volume(volume_idx); +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + bool shift_down = evt.ShiftDown(); +#else bool ctrl_down = evt.CmdDown(); +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION Selection::IndicesList curr_idxs = m_selection.get_volume_idxs(); +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (already_selected && shift_down) +#else if (already_selected && ctrl_down) +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_selection.remove(volume_idx); else { +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + m_selection.add(volume_idx, !shift_down, true); +#else m_selection.add(volume_idx, !ctrl_down, true); +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_mouse.drag.move_requires_threshold = !already_selected; if (already_selected) m_mouse.set_move_start_threshold_position_2D_as_invalid(); @@ -3135,7 +3175,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (!m_hover_volume_idxs.empty()) { if (evt.LeftDown() && m_moving_enabled && m_mouse.drag.move_volume_idx == -1) { // Only accept the initial position, if it is inside the volume bounding box. - int volume_idx = get_first_hover_volume_idx(); + const int volume_idx = get_first_hover_volume_idx(); BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box(); volume_bbox.offset(1.0); if ((!any_gizmo_active || !evt.CmdDown()) && volume_bbox.contains(m_mouse.scene_position)) { @@ -3143,6 +3183,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // The dragging operation is initiated. m_mouse.drag.move_volume_idx = volume_idx; m_selection.start_dragging(); +#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + if (!evt.CmdDown()) +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE m_mouse.drag.start_position_3D = m_mouse.scene_position; m_sequential_print_clearance_first_displacement = true; m_moving = true; @@ -3151,31 +3194,35 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } } +#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + else if (evt.Dragging() && evt.LeftIsDown() && !evt.CmdDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { +#else else if (evt.Dragging() && evt.LeftIsDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { - if (!m_mouse.drag.move_requires_threshold) { +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + if (!m_mouse.drag.move_requires_threshold) { m_mouse.dragging = true; Vec3d cur_pos = m_mouse.drag.start_position_3D; // we do not want to translate objects if the user just clicked on an object while pressing shift to remove it from the selection and then drag if (m_selection.contains_volume(get_first_hover_volume_idx())) { const Camera& camera = wxGetApp().plater()->get_camera(); - if (std::abs(camera.get_dir_forward()(2)) < EPSILON) { + if (std::abs(camera.get_dir_forward().z()) < EPSILON) { // side view -> move selected volumes orthogonally to camera view direction - Linef3 ray = mouse_ray(pos); - Vec3d dir = ray.unit_vector(); + const Linef3 ray = mouse_ray(pos); + const Vec3d dir = ray.unit_vector(); // finds the intersection of the mouse ray with the plane parallel to the camera viewport and passing throught the starting position // use ray-plane intersection see i.e. https://en.wikipedia.org/wiki/Line%E2%80%93plane_intersection algebric form // in our case plane normal and ray direction are the same (orthogonal view) // when moving to perspective camera the negative z unit axis of the camera needs to be transformed in world space and used as plane normal - Vec3d inters = ray.a + (m_mouse.drag.start_position_3D - ray.a).dot(dir) / dir.squaredNorm() * dir; + const Vec3d inters = ray.a + (m_mouse.drag.start_position_3D - ray.a).dot(dir) / dir.squaredNorm() * dir; // vector from the starting position to the found intersection - Vec3d inters_vec = inters - m_mouse.drag.start_position_3D; + const Vec3d inters_vec = inters - m_mouse.drag.start_position_3D; - Vec3d camera_right = camera.get_dir_right(); - Vec3d camera_up = camera.get_dir_up(); + const Vec3d camera_right = camera.get_dir_right(); + const Vec3d camera_up = camera.get_dir_up(); // finds projection of the vector along the camera axes - double projection_x = inters_vec.dot(camera_right); - double projection_z = inters_vec.dot(camera_up); + const double projection_x = inters_vec.dot(camera_right); + const double projection_z = inters_vec.dot(camera_up); // apply offset cur_pos = m_mouse.drag.start_position_3D + projection_x * camera_right + projection_z * camera_up; @@ -3185,7 +3232,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // Get new position at the same Z of the initial click point. float z0 = 0.0f; float z1 = 1.0f; - cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D(2)); + cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D.z()); } } @@ -3210,13 +3257,21 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } // do not process the dragging if the left mouse was set down in another canvas +#if ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE + else if (evt.LeftIsDown() || evt.MiddleIsDown()) { +#else else if (evt.LeftIsDown()) { +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE // if dragging over blank area with left button, rotate +#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + if ((any_gizmo_active || evt.CmdDown() || evt.MiddleIsDown() || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { +#else if ((any_gizmo_active || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { - const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.); +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.0) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.0); if (wxGetApp().app_config->get("use_free_camera") == "1") // Virtual track ball (similar to the 3DConnexion mouse). - wxGetApp().plater()->get_camera().rotate_local_around_target(Vec3d(rot.y(), rot.x(), 0.)); + wxGetApp().plater()->get_camera().rotate_local_around_target(Vec3d(rot.y(), rot.x(), 0.0)); else { // Forces camera right vector to be parallel to XY plane in case it has been misaligned using the 3D mouse free rotation. // It is cheaper to call this function right away instead of testing wxGetApp().plater()->get_mouse3d_controller().connected(), @@ -3229,15 +3284,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } - m_mouse.drag.start_position_3D = Vec3d((double)pos(0), (double)pos(1), 0.0); + m_mouse.drag.start_position_3D = Vec3d((double)pos.x(), (double)pos.y(), 0.0); } +#if ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE + else if (evt.RightIsDown()) { + // If dragging with right button, pan. +#else else if (evt.MiddleIsDown() || evt.RightIsDown()) { // If dragging over blank area with right button, pan. +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE if (m_mouse.is_start_position_2D_defined()) { // get point in model space at Z = 0 float z = 0.0f; const Vec3d& cur_pos = _mouse_to_3d(pos, &z); - Vec3d orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z); + const Vec3d orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z); Camera& camera = wxGetApp().plater()->get_camera(); if (wxGetApp().app_config->get("use_free_camera") != "1") // Forces camera right vector to be parallel to XY plane in case it has been misaligned using the 3D mouse free rotation. @@ -3254,7 +3314,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } else if (evt.LeftUp() || evt.MiddleUp() || evt.RightUp()) { - if (evt.LeftUp()) + if (evt.LeftUp() && m_selection.is_dragging()) m_selection.stop_dragging(); if (m_layers_editing.state != LayersEditing::Unknown) { @@ -3313,7 +3373,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) if (!m_mouse.dragging) { // do not post the event if the user is panning the scene // or if right click was done over the wipe tower - bool post_right_click_event = m_hover_volume_idxs.empty() || !m_volumes.volumes[get_first_hover_volume_idx()]->is_wipe_tower; + const bool post_right_click_event = m_hover_volume_idxs.empty() || !m_volumes.volumes[get_first_hover_volume_idx()]->is_wipe_tower; if (post_right_click_event) post_event(RBtnEvent(EVT_GLCANVAS_RIGHT_CLICK, { logical_pos, m_hover_volume_idxs.empty() })); } @@ -5675,9 +5735,14 @@ void GLCanvas3D::_update_volumes_hover_state() if (volume.hover != GLVolume::HS_None) continue; +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + bool deselect = volume.selected && ((shift_pressed && m_rectangle_selection.is_empty()) || (alt_pressed && !m_rectangle_selection.is_empty())); + bool select = !volume.selected && (m_rectangle_selection.is_empty() || (shift_pressed && !m_rectangle_selection.is_empty())); +#else bool deselect = volume.selected && ((ctrl_pressed && !shift_pressed) || alt_pressed); // (volume->is_modifier && !selection_modifiers_only && !is_ctrl_pressed) -> allows hovering on selected modifiers belonging to selection of type Instance bool select = (!volume.selected || (volume.is_modifier && !selection_modifiers_only && !ctrl_pressed)) && !alt_pressed; +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION if (select || deselect) { bool as_volume = @@ -6436,7 +6501,7 @@ void GLCanvas3D::_update_selection_from_hover() bool ctrl_pressed = wxGetKeyState(WXK_CONTROL); if (m_hover_volume_idxs.empty()) { - if (!ctrl_pressed && (m_rectangle_selection.get_state() == GLSelectionRectangle::Select)) + if (!ctrl_pressed && m_rectangle_selection.get_state() == GLSelectionRectangle::EState::Select) m_selection.remove_all(); return; @@ -6453,7 +6518,10 @@ void GLCanvas3D::_update_selection_from_hover() } bool selection_changed = false; - if (state == GLSelectionRectangle::Select) { +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (!m_rectangle_selection.is_empty()) { +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (state == GLSelectionRectangle::EState::Select) { bool contains_all = true; for (int i : m_hover_volume_idxs) { if (!m_selection.contains_volume((unsigned int)i)) { @@ -6464,7 +6532,7 @@ void GLCanvas3D::_update_selection_from_hover() // the selection is going to be modified (Add) if (!contains_all) { - wxGetApp().plater()->take_snapshot(_(L("Selection-Add from rectangle")), UndoRedo::SnapshotType::Selection); + wxGetApp().plater()->take_snapshot(_L("Selection-Add from rectangle"), UndoRedo::SnapshotType::Selection); selection_changed = true; } } @@ -6479,21 +6547,24 @@ void GLCanvas3D::_update_selection_from_hover() // the selection is going to be modified (Remove) if (contains_any) { - wxGetApp().plater()->take_snapshot(_(L("Selection-Remove from rectangle")), UndoRedo::SnapshotType::Selection); + wxGetApp().plater()->take_snapshot(_L("Selection-Remove from rectangle"), UndoRedo::SnapshotType::Selection); selection_changed = true; } } +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + } +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION if (!selection_changed) return; Plater::SuppressSnapshots suppress(wxGetApp().plater()); - if ((state == GLSelectionRectangle::Select) && !ctrl_pressed) + if (state == GLSelectionRectangle::EState::Select && !ctrl_pressed) m_selection.clear(); for (int i : m_hover_volume_idxs) { - if (state == GLSelectionRectangle::Select) { + if (state == GLSelectionRectangle::EState::Select) { if (hover_modifiers_only) { const GLVolume& v = *m_volumes.volumes[i]; m_selection.add_volume(v.object_idx(), v.volume_idx(), v.instance_idx(), false); diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index 13467499a1..f3d032fc31 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -13,12 +13,12 @@ namespace GUI { void GLSelectionRectangle::start_dragging(const Vec2d& mouse_position, EState state) { - if (is_dragging() || (state == Off)) + if (is_dragging() || state == EState::Off) return; m_state = state; m_start_corner = mouse_position; - m_end_corner = mouse_position; + m_end_corner = mouse_position; } void GLSelectionRectangle::dragging(const Vec2d& mouse_position) @@ -36,7 +36,7 @@ namespace GUI { if (!is_dragging()) return out; - m_state = Off; + m_state = EState::Off; const Camera& camera = wxGetApp().plater()->get_camera(); Matrix4d modelview = camera.get_view_matrix().matrix(); @@ -66,7 +66,7 @@ namespace GUI { void GLSelectionRectangle::stop_dragging() { if (is_dragging()) - m_state = Off; + m_state = EState::Off; } void GLSelectionRectangle::render(const GLCanvas3D& canvas) const @@ -93,8 +93,8 @@ namespace GUI { glsafe(::glLineWidth(1.5f)); float color[3]; - color[0] = (m_state == Select) ? 0.3f : 1.0f; - color[1] = (m_state == Select) ? 1.0f : 0.3f; + color[0] = (m_state == EState::Select) ? 0.3f : 1.0f; + color[1] = (m_state == EState::Select) ? 1.0f : 0.3f; color[2] = 0.3f; glsafe(::glColor3fv(color)); diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index d9869771ef..dbbb056a94 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -11,7 +11,7 @@ class GLCanvas3D; class GLSelectionRectangle { public: - enum EState { + enum class EState { Off, Select, Deselect @@ -32,18 +32,22 @@ public: void render(const GLCanvas3D& canvas) const; - bool is_dragging() const { return m_state != Off; } + bool is_dragging() const { return m_state != EState::Off; } +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + bool is_empty() const { return m_state == EState::Off || m_start_corner.isApprox(m_end_corner); } +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + EState get_state() const { return m_state; } - float get_width() const { return std::abs(m_start_corner(0) - m_end_corner(0)); } - float get_height() const { return std::abs(m_start_corner(1) - m_end_corner(1)); } - float get_left() const { return std::min(m_start_corner(0), m_end_corner(0)); } - float get_right() const { return std::max(m_start_corner(0), m_end_corner(0)); } - float get_top() const { return std::max(m_start_corner(1), m_end_corner(1)); } - float get_bottom() const { return std::min(m_start_corner(1), m_end_corner(1)); } + float get_width() const { return std::abs(m_start_corner.x() - m_end_corner.x()); } + float get_height() const { return std::abs(m_start_corner.y() - m_end_corner.y()); } + float get_left() const { return std::min(m_start_corner.x(), m_end_corner.x()); } + float get_right() const { return std::max(m_start_corner.x(), m_end_corner.x()); } + float get_top() const { return std::max(m_start_corner.y(), m_end_corner.y()); } + float get_bottom() const { return std::min(m_start_corner.y(), m_end_corner.y()); } private: - EState m_state = Off; + EState m_state{ EState::Off }; Vec2d m_start_corner; Vec2d m_end_corner; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 691a867063..e5dee5248f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -258,7 +258,7 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos if (action == SLAGizmoEventType::LeftDown && (shift_down || alt_down || control_down)) { if (m_hover_id == -1) { if (shift_down || alt_down) { - m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::Select : GLSelectionRectangle::Deselect); + m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::EState::Select : GLSelectionRectangle::EState::Deselect); } } else { @@ -324,7 +324,7 @@ bool GLGizmoHollow::gizmo_event(SLAGizmoEventType action, const Vec2d& mouse_pos trafo, wxGetApp().plater()->get_camera(), points_inside, m_c->object_clipper()->get_clipping_plane())) { - if (rectangle_status == GLSelectionRectangle::Deselect) + if (rectangle_status == GLSelectionRectangle::EState::Deselect) unselect_point(points_idxs[idx]); else select_point(points_idxs[idx]); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 29e1fd2f30..8395adadf2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -344,7 +344,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous if (action == SLAGizmoEventType::LeftDown && (shift_down || alt_down || control_down)) { if (m_hover_id == -1) { if (shift_down || alt_down) { - m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::Select : GLSelectionRectangle::Deselect); + m_selection_rectangle.start_dragging(mouse_position, shift_down ? GLSelectionRectangle::EState::Select : GLSelectionRectangle::EState::Deselect); } } else { @@ -415,7 +415,7 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous { if (idx >= orig_pts_num) // this is a cone-base, get index of point it belongs to idx -= orig_pts_num; - if (rectangle_status == GLSelectionRectangle::Deselect) + if (rectangle_status == GLSelectionRectangle::EState::Deselect) unselect_point(points_idxs[idx]); else select_point(points_idxs[idx]); From 7274d2bb6e7009a0bfbd0f5a281a8b6037ca7ad5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 11 Jan 2022 09:43:43 +0100 Subject: [PATCH 02/22] Fixed warning --- src/slic3r/GUI/GLCanvas3D.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 7a8c13e5d8..955287f0f6 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -5706,7 +5706,9 @@ void GLCanvas3D::_update_volumes_hover_state() return; } +#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION bool selection_modifiers_only = m_selection.is_empty() || m_selection.is_any_modifier(); +#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION bool hover_modifiers_only = true; for (int i : m_hover_volume_idxs) { From f09c3e111803bc30d4cb007b898770869d93f730 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 14 Jan 2022 11:28:20 +0100 Subject: [PATCH 03/22] Techs ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE, ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE and ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION moved to 2.5.1.alpha1 --- src/libslic3r/Technologies.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f267d4f55f..1641e5804a 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -43,10 +43,6 @@ // Enable detection of layers for spiral vase prints #define ENABLE_SPIRAL_VASE_LAYERS (1 && ENABLE_2_4_1_RC) -// Enable modified camera control and selection using mouse -#define ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE (1 && ENABLE_2_4_1_RC) -#define ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE (1 && ENABLE_2_4_1_RC) -#define ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION (1 && ENABLE_2_4_1_RC) //==================== @@ -62,6 +58,10 @@ #define ENABLE_PREVIEW_LAYER_TIME (1 && ENABLE_2_5_0_ALPHA1) // Enable showing time estimate for travel moves in legend #define ENABLE_TRAVEL_TIME (1 && ENABLE_2_5_0_ALPHA1) +// Enable modified camera control and selection using mouse +#define ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE (1 && ENABLE_2_5_0_ALPHA1) +#define ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE (1 && ENABLE_2_5_0_ALPHA1) +#define ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ From 1ad8460a3cfbd840d374fe32c0e01749effcb39e Mon Sep 17 00:00:00 2001 From: Nick Berardi Date: Sun, 27 Feb 2022 09:58:07 -0500 Subject: [PATCH 04/22] creality.ini: add Ender-3 Pro Added missing profile for Creality Ender-3 Pro --- resources/profiles/Creality.ini | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resources/profiles/Creality.ini b/resources/profiles/Creality.ini index 381efbe2ff..1ebcb8ebcb 100644 --- a/resources/profiles/Creality.ini +++ b/resources/profiles/Creality.ini @@ -32,6 +32,15 @@ bed_model = ender3_bed.stl bed_texture = ender3.svg default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Matt @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY +[printer_model:ENDER3PRO] +name = Creality Ender-3 Pro +variants = 0.4 +technology = FFF +family = ENDER +bed_model = ender3_bed.stl +bed_texture = ender3.svg +default_materials = Generic PLA @CREALITY; Generic PETG @CREALITY; Generic ABS @CREALITY; Creality PLA @CREALITY; Prusament PLA @CREALITY; Prusament PETG @CREALITY; AzureFilm PLA @CREALITY; Devil Design PLA @CREALITY; Devil Design PLA Matt @CREALITY; Devil Design PLA Galaxy @CREALITY; Extrudr PLA NX2 @CREALITY; Real Filament PLA @CREALITY; Velleman PLA @CREALITY; 3DJAKE ecoPLA @CREALITY; 3DJAKE ecoPLA Matt @CREALITY; 3DJAKE ecoPLA Tough @CREALITY; 123-3D Jupiter PLA @CREALITY + [printer_model:ENDER3V2] name = Creality Ender-3 V2 variants = 0.4 @@ -960,6 +969,14 @@ inherits = Creality Ender-3; *fastabl* renamed_from = "Creality ENDER-3 BLTouch" printer_model = ENDER3BLTOUCH +[printer:Creality Ender-3 Pro] +inherits = *common* +renamed_from = "Creality Ender-3 Pro" +bed_shape = 5x0,215x0,215x220,5x220 +max_print_height = 250 +printer_model = ENDER3PRO +printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN + [printer:Creality Ender-3 V2] inherits = *common* renamed_from = "Creality Ender-3V2" From 537fa118df7cd16ac1b265056f7cbdb5d280c768 Mon Sep 17 00:00:00 2001 From: Nick Berardi Date: Sun, 27 Feb 2022 10:32:58 -0500 Subject: [PATCH 05/22] Added support for `*pauseprint*` to Ender-3 models Added support for `*pauseprint*` to Ender-3 models, as they do support `M25` out of the box from at least the Ender-3 line forward. --- resources/profiles/Creality.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/profiles/Creality.ini b/resources/profiles/Creality.ini index 1ebcb8ebcb..b3d8507093 100644 --- a/resources/profiles/Creality.ini +++ b/resources/profiles/Creality.ini @@ -970,7 +970,7 @@ renamed_from = "Creality ENDER-3 BLTouch" printer_model = ENDER3BLTOUCH [printer:Creality Ender-3 Pro] -inherits = *common* +inherits = *common*; *pauseprint* renamed_from = "Creality Ender-3 Pro" bed_shape = 5x0,215x0,215x220,5x220 max_print_height = 250 @@ -978,7 +978,7 @@ printer_model = ENDER3PRO printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN [printer:Creality Ender-3 V2] -inherits = *common* +inherits = *common*; *pauseprint* renamed_from = "Creality Ender-3V2" bed_shape = 5x0,215x0,215x220,5x220 max_print_height = 250 @@ -986,7 +986,7 @@ printer_model = ENDER3V2 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3V2\nPRINTER_HAS_BOWDEN [printer:Creality Ender-3 S1] -inherits = *common*; *spriteextruder* +inherits = *common*; *pauseprint*; *spriteextruder* bed_shape = 5x0,215x0,215x220,5x220 max_print_height = 270 printer_model = ENDER3S1 From a1846e38d2439854d17a0985de7277849204cc1d Mon Sep 17 00:00:00 2001 From: Nick Berardi Date: Sun, 27 Feb 2022 10:37:08 -0500 Subject: [PATCH 06/22] Reved Creality.ini version Reved Creality.ini version, and included `*pauseprint*` for Ender-3 Max as well. --- resources/profiles/Creality.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/profiles/Creality.ini b/resources/profiles/Creality.ini index b3d8507093..0fa14d8a8b 100644 --- a/resources/profiles/Creality.ini +++ b/resources/profiles/Creality.ini @@ -5,7 +5,7 @@ name = Creality # Configuration version of this file. Config file will only be installed, if the config_version differs. # This means, the server may force the PrusaSlicer configuration to be downgraded. -config_version = 0.1.3 +config_version = 0.1.4 # Where to get the updates from? config_update_url = https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/Creality/ # changelog_url = https://files.prusa3d.com/?latest=slicer-profiles&lng=%1% @@ -993,7 +993,7 @@ printer_model = ENDER3S1 printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3S1 [printer:Creality Ender-3 Max] -inherits = *common* +inherits = *common*; *pauseprint* retract_length = 6 bed_shape = 5x5,295x5,295x295,5x295 max_print_height = 340 From 3dddfa919a6340a73973c6c48db3a7c0d98fe650 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 10 Mar 2022 15:55:15 +0100 Subject: [PATCH 07/22] Debug tech ENABLE_GLMODEL_STATISTICS - Shows an imgui dialog with GLModel statistics data --- src/libslic3r/Technologies.hpp | 2 + src/slic3r/GUI/GLCanvas3D.cpp | 7 ++ src/slic3r/GUI/GLModel.cpp | 95 +++++++++++++++++++++++++ src/slic3r/GUI/GLModel.hpp | 31 ++++++++ src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 3 +- 5 files changed, 136 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index f8f9f80e21..85158ccb22 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -70,6 +70,8 @@ #define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) // Enable using vertex attributes and matrices in shaders #define ENABLE_GL_SHADERS_ATTRIBUTES (1 && ENABLE_LEGACY_OPENGL_REMOVAL) +// Shows an imgui dialog with GLModel statistics data +#define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable show non-manifold edges #define ENABLE_SHOW_NON_MANIFOLD_EDGES (1 && ENABLE_2_5_0_ALPHA1) // Enable rework of Reload from disk command diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index d8d1556c87..46219c1d12 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1667,6 +1667,10 @@ void GLCanvas3D::render() wxGetApp().plater()->init_environment_texture(); #endif // ENABLE_ENVIRONMENT_MAP +#if ENABLE_GLMODEL_STATISTICS + GLModel::reset_statistics_counters(); +#endif // ENABLE_GLMODEL_STATISTICS + const Size& cnv_size = get_canvas_size(); // Probably due to different order of events on Linux/GTK2, when one switched from 3D scene // to preview, this was called before canvas had its final size. It reported zero width @@ -1776,6 +1780,9 @@ void GLCanvas3D::render() #if ENABLE_CAMERA_STATISTICS camera.debug_render(); #endif // ENABLE_CAMERA_STATISTICS +#if ENABLE_GLMODEL_STATISTICS + GLModel::render_statistics(); +#endif // ENABLE_GLMODEL_STATISTICS std::string tooltip; diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index a92153330c..b81287ecee 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -4,6 +4,10 @@ #include "3DScene.hpp" #include "GUI_App.hpp" #include "GLShader.hpp" +#if ENABLE_GLMODEL_STATISTICS +#include "Plater.hpp" +#include "GLCanvas3D.hpp" +#endif // ENABLE_GLMODEL_STATISTICS #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Model.hpp" @@ -13,6 +17,10 @@ #include "libslic3r/Geometry/ConvexHull.hpp" #endif // ENABLE_LEGACY_OPENGL_REMOVAL +#if ENABLE_GLMODEL_STATISTICS +#include +#endif // ENABLE_GLMODEL_STATISTICS + #include #include @@ -380,6 +388,10 @@ size_t GLModel::Geometry::indices_count() const } #endif // ENABLE_LEGACY_OPENGL_REMOVAL +#if ENABLE_GLMODEL_STATISTICS +GLModel::Statistics GLModel::s_statistics; +#endif // ENABLE_GLMODEL_STATISTICS + #if ENABLE_LEGACY_OPENGL_REMOVAL void GLModel::init_from(Geometry&& data) #else @@ -702,10 +714,16 @@ void GLModel::reset() if (m_render_data.ibo_id > 0) { glsafe(::glDeleteBuffers(1, &m_render_data.ibo_id)); m_render_data.ibo_id = 0; +#if ENABLE_GLMODEL_STATISTICS + s_statistics.gpu_memory.indices.current -= indices_size_bytes(); +#endif // ENABLE_GLMODEL_STATISTICS } if (m_render_data.vbo_id > 0) { glsafe(::glDeleteBuffers(1, &m_render_data.vbo_id)); m_render_data.vbo_id = 0; +#if ENABLE_GLMODEL_STATISTICS + s_statistics.gpu_memory.vertices.current -= vertices_size_bytes(); +#endif // ENABLE_GLMODEL_STATISTICS } m_render_data.vertices_count = 0; @@ -899,6 +917,10 @@ void GLModel::render(const std::pair& range) #endif // ENABLE_GL_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + +#if ENABLE_GLMODEL_STATISTICS + ++s_statistics.render_calls; +#endif // ENABLE_GLMODEL_STATISTICS } #endif // ENABLE_LEGACY_OPENGL_REMOVAL @@ -1054,6 +1076,10 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance #endif // ENABLE_LEGACY_OPENGL_REMOVAL glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + +#if ENABLE_GLMODEL_STATISTICS + ++s_statistics.render_instanced_calls; +#endif // ENABLE_GLMODEL_STATISTICS } #if ENABLE_LEGACY_OPENGL_REMOVAL @@ -1076,6 +1102,10 @@ bool GLModel::send_to_gpu() glsafe(::glBufferData(GL_ARRAY_BUFFER, data.vertices_size_bytes(), data.vertices.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); m_render_data.vertices_count = vertices_count(); +#if ENABLE_GLMODEL_STATISTICS + s_statistics.gpu_memory.vertices.current += data.vertices_size_bytes(); + s_statistics.gpu_memory.vertices.max = std::max(s_statistics.gpu_memory.vertices.current, s_statistics.gpu_memory.vertices.max); +#endif // ENABLE_GLMODEL_STATISTICS data.vertices = std::vector(); // indices @@ -1107,10 +1137,75 @@ bool GLModel::send_to_gpu() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } m_render_data.indices_count = indices_count; +#if ENABLE_GLMODEL_STATISTICS + s_statistics.gpu_memory.indices.current += data.indices_size_bytes(); + s_statistics.gpu_memory.indices.max = std::max(s_statistics.gpu_memory.indices.current, s_statistics.gpu_memory.indices.max); +#endif // ENABLE_GLMODEL_STATISTICS data.indices = std::vector(); return true; } + +#if ENABLE_GLMODEL_STATISTICS +void GLModel::render_statistics() +{ + static const float offset = 175.0f; + ImGuiWrapper& imgui = *wxGetApp().imgui(); + + auto add_memory = [&imgui](const std::string& label, int64_t memory) { + auto format_string = [memory](const std::string& units, float value) { + return std::to_string(memory) + " bytes (" + + Slic3r::float_to_string_decimal_point(float(memory) * value, 3) + + " " + units + ")"; + }; + + static const float kb = 1024.0f; + static const float inv_kb = 1.0f / kb; + static const float mb = 1024.0f * kb; + static const float inv_mb = 1.0f / mb; + static const float gb = 1024.0f * mb; + static const float inv_gb = 1.0f / gb; + imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); + ImGui::SameLine(offset); + if (static_cast(memory) < mb) + imgui.text(format_string("KB", inv_kb)); + else if (static_cast(memory) < gb) + imgui.text(format_string("MB", inv_mb)); + else + imgui.text(format_string("GB", inv_gb)); + }; + + auto add_counter = [&imgui](const std::string& label, int64_t counter) { + imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label); + ImGui::SameLine(offset); + imgui.text(std::to_string(counter)); + }; + + imgui.set_next_window_pos(0.5f * wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width(), 0.0f, ImGuiCond_Once, 0.5f, 0.0f); + ImGui::SetNextWindowSizeConstraints({ 300.0f, 100.0f }, { 600.0f, 900.0f }); + imgui.begin(std::string("GLModel Statistics"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize); + ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow()); + + add_counter(std::string("Render calls:"), s_statistics.render_calls); + add_counter(std::string("Render instanced calls:"), s_statistics.render_instanced_calls); + + if (ImGui::CollapsingHeader("GPU memory")) { + ImGui::Indent(10.0f); + if (ImGui::CollapsingHeader("Vertices")) { + add_memory(std::string("Current:"), s_statistics.gpu_memory.vertices.current); + add_memory(std::string("Max:"), s_statistics.gpu_memory.vertices.max); + } + if (ImGui::CollapsingHeader("Indices")) { + add_memory(std::string("Current:"), s_statistics.gpu_memory.indices.current); + add_memory(std::string("Max:"), s_statistics.gpu_memory.indices.max); + } + ImGui::Unindent(10.0f); + } + + imgui.end(); +} +#endif // ENABLE_GLMODEL_STATISTICS + #else void GLModel::send_to_gpu(RenderData& data, const std::vector& vertices, const std::vector& indices) { diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index e18d046783..e2da09484d 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -177,6 +177,29 @@ namespace GUI { private: #if ENABLE_LEGACY_OPENGL_REMOVAL +#if ENABLE_GLMODEL_STATISTICS + struct Statistics + { + struct Buffers + { + struct Data + { + size_t current{ 0 }; + size_t max{ 0 }; + }; + Data indices; + Data vertices; + }; + + Buffers gpu_memory; + + int64_t render_calls{ 0 }; + int64_t render_instanced_calls{ 0 }; + }; + + static Statistics s_statistics; +#endif // ENABLE_GLMODEL_STATISTICS + RenderData m_render_data; // By default the vertex and index buffers data are sent to gpu at the first call to render() method. @@ -272,6 +295,14 @@ namespace GUI { ret += indices_size_bytes(); return ret; } + +#if ENABLE_GLMODEL_STATISTICS + static void render_statistics(); + static void reset_statistics_counters() { + s_statistics.render_calls = 0; + s_statistics.render_instanced_calls = 0; + } +#endif // ENABLE_GLMODEL_STATISTICS #endif // ENABLE_LEGACY_OPENGL_REMOVAL private: diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 266b6a3cac..1d817b58bc 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -182,8 +182,7 @@ void GLGizmoRotate::on_render() #if ENABLE_GL_SHADERS_ATTRIBUTES const Camera& camera = wxGetApp().plater()->get_camera(); - Transform3d view_model_matrix = camera.get_view_matrix() * m_grabbers.front().matrix; - + const Transform3d view_model_matrix = camera.get_view_matrix() * m_grabbers.front().matrix; shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); #endif // ENABLE_GL_SHADERS_ATTRIBUTES From b32c97ea76493dc4125e390585f2cedc4478e44d Mon Sep 17 00:00:00 2001 From: rtyr <36745189+rtyr@users.noreply.github.com> Date: Fri, 11 Mar 2022 10:55:47 +0100 Subject: [PATCH 08/22] Added Ender-3 Pro. --- resources/profiles/Creality.idx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/profiles/Creality.idx b/resources/profiles/Creality.idx index f8abfb40a0..1ff148aad3 100644 --- a/resources/profiles/Creality.idx +++ b/resources/profiles/Creality.idx @@ -1,3 +1,5 @@ +min_slic3r_version = 2.4.1 +0.1.4 Added Ender-3 Pro. Added M25 support for some printers. min_slic3r_version = 2.4.0-rc 0.1.3 Ender-3 S1 improvements. 0.1.2 Added alpha Ender 3 S1 profiles. From 2342002151a2ce4f25cb3b0b9cae10ce797ddc8e Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 11 Mar 2022 11:28:08 +0100 Subject: [PATCH 09/22] Tech ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE - Fixed volumes moving after releasing CTRL key Tech ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION - Selection rectangle not started while hovering on a volume --- src/slic3r/GUI/GLCanvas3D.cpp | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 76bcde9471..6e1c1c536f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2928,8 +2928,7 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) if (imgui->update_key_data(evt)) { render(); } - else - { + else { if (!m_gizmos.on_key(evt)) { if (evt.GetEventType() == wxEVT_KEY_UP) { if (evt.ShiftDown() && evt.ControlDown() && keyCode == WXK_SPACE) { @@ -2970,8 +2969,17 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } // set_cursor(Standard); } - else if (keyCode == WXK_CONTROL) + else if (keyCode == WXK_CONTROL) { +#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + if (m_mouse.dragging) { + // if the user releases CTRL while rotating the 3D scene + // prevent from moving the selected volume + m_mouse.drag.move_volume_idx = -1; + m_mouse.set_start_position_3D_as_invalid(); + } +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE m_dirty = true; + } else if (m_gizmos.is_enabled() && !m_selection.is_empty()) { translationProcessor.process(evt); @@ -3444,10 +3452,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) else { #if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION if (evt.LeftDown() && (evt.ShiftDown() || evt.AltDown()) && m_picking_enabled) { - if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports - && m_gizmos.get_current_type() != GLGizmosManager::FdmSupports - && m_gizmos.get_current_type() != GLGizmosManager::Seam - && m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation) { + if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports && + m_gizmos.get_current_type() != GLGizmosManager::FdmSupports && + m_gizmos.get_current_type() != GLGizmosManager::Seam && + m_gizmos.get_current_type() != GLGizmosManager::MmuSegmentation) { m_rectangle_selection.start_dragging(m_mouse.position, evt.ShiftDown() ? GLSelectionRectangle::EState::Select : GLSelectionRectangle::EState::Deselect); m_dirty = true; } @@ -3459,7 +3467,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // during the scene manipulation. #if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION - if (m_picking_enabled && (!any_gizmo_active || !evt.ShiftDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled())) { + if (m_picking_enabled && (!any_gizmo_active || !evt.ShiftDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled()) && + !m_rectangle_selection.is_dragging()) { #else if (m_picking_enabled && (!any_gizmo_active || !evt.CmdDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled())) { #endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION @@ -3507,7 +3516,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + if (!m_hover_volume_idxs.empty() && !m_rectangle_selection.is_dragging()) { +#else if (!m_hover_volume_idxs.empty()) { +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION if (evt.LeftDown() && m_moving_enabled && m_mouse.drag.move_volume_idx == -1) { // Only accept the initial position, if it is inside the volume bounding box. const int volume_idx = get_first_hover_volume_idx(); @@ -3518,6 +3531,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // The dragging operation is initiated. m_mouse.drag.move_volume_idx = volume_idx; #if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE + m_selection.setup_cache(); if (!evt.CmdDown()) #endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE m_mouse.drag.start_position_3D = m_mouse.scene_position; @@ -3529,7 +3543,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } #if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE - else if (evt.Dragging() && evt.LeftIsDown() && !evt.CmdDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { + else if (evt.Dragging() && evt.LeftIsDown() && !evt.CmdDown() && m_layers_editing.state == LayersEditing::Unknown && + m_mouse.drag.move_volume_idx != -1 && m_mouse.is_start_position_3D_defined()) { #else else if (evt.Dragging() && evt.LeftIsDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { #endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE @@ -3578,7 +3593,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } else if (evt.Dragging() && evt.LeftIsDown() && m_picking_enabled && m_rectangle_selection.is_dragging()) { +#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION + // keeps the mouse position updated while dragging the selection rectangle + m_mouse.position = pos.cast(); + m_rectangle_selection.dragging(m_mouse.position); +#else m_rectangle_selection.dragging(pos.cast()); +#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_dirty = true; } else if (evt.Dragging()) { From ac0ec5fa4391423e6a23dd8d4463431fb6c43d02 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Fri, 11 Mar 2022 12:36:09 +0100 Subject: [PATCH 10/22] Tech ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE renamed as ENABLE_NEW_CAMERA_MOVEMENTS Tech ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE merged into ENABLE_NEW_CAMERA_MOVEMENTS Tech ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION renamed as ENABLE_NEW_RECTANGLE_SELECTION --- src/libslic3r/Technologies.hpp | 8 +- src/slic3r/GUI/GLCanvas3D.cpp | 97 ++++++++++++------------- src/slic3r/GUI/GLSelectionRectangle.hpp | 4 +- 3 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index c306cccc4d..b46b8731fd 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -80,10 +80,10 @@ #define ENABLE_SHOW_TOOLPATHS_COG (1 && ENABLE_2_5_0_ALPHA1) // Enable recalculating toolpaths when switching to/from volumetric rate visualization #define ENABLE_VOLUMETRIC_RATE_TOOLPATHS_RECALC (1 && ENABLE_2_5_0_ALPHA1) -// Enable modified camera control and selection using mouse -#define ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE (1 && ENABLE_2_5_0_ALPHA1) -#define ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE (1 && ENABLE_2_5_0_ALPHA1) -#define ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION (1 && ENABLE_2_5_0_ALPHA1) +// Enable modified camera control using mouse +#define ENABLE_NEW_CAMERA_MOVEMENTS (1 && ENABLE_2_5_0_ALPHA1) +// Enable modified rectangle selection +#define ENABLE_NEW_RECTANGLE_SELECTION (1 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 6e1c1c536f..ea08f98711 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1696,11 +1696,11 @@ void GLCanvas3D::render() wxGetApp().imgui()->new_frame(); if (m_picking_enabled) { -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (m_rectangle_selection.is_dragging() && !m_rectangle_selection.is_empty()) #else if (m_rectangle_selection.is_dragging()) -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION // picking pass using rectangle selection _rectangular_selection_picking_pass(); else if (!m_volumes.empty()) @@ -2951,13 +2951,13 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) _update_selection_from_hover(); m_rectangle_selection.stop_dragging(); m_mouse.ignore_left_up = true; -#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if !ENABLE_NEW_RECTANGLE_SELECTION m_dirty = true; -#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // !ENABLE_NEW_RECTANGLE_SELECTION } -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION m_dirty = true; -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION // set_cursor(Standard); } else if (keyCode == WXK_ALT) { @@ -2970,14 +2970,14 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) // set_cursor(Standard); } else if (keyCode == WXK_CONTROL) { -#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#if ENABLE_NEW_CAMERA_MOVEMENTS if (m_mouse.dragging) { // if the user releases CTRL while rotating the 3D scene // prevent from moving the selected volume m_mouse.drag.move_volume_idx = -1; m_mouse.set_start_position_3D_as_invalid(); } -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#endif // ENABLE_NEW_CAMERA_MOVEMENTS m_dirty = true; } else if (m_gizmos.is_enabled() && !m_selection.is_empty()) { @@ -3014,9 +3014,9 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) m_mouse.ignore_left_up = false; // set_cursor(Cross); } -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION m_dirty = true; -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION } else if (keyCode == WXK_ALT) { if (m_picking_enabled && (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports)) { @@ -3438,7 +3438,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_layers_editing.state = LayersEditing::Editing; _perform_layer_editing_action(&evt); } -#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if !ENABLE_NEW_RECTANGLE_SELECTION else if (evt.LeftDown() && (evt.ShiftDown() || evt.AltDown()) && m_picking_enabled) { if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports && m_gizmos.get_current_type() != GLGizmosManager::FdmSupports @@ -3448,9 +3448,9 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } } -#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // !ENABLE_NEW_RECTANGLE_SELECTION else { -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (evt.LeftDown() && (evt.ShiftDown() || evt.AltDown()) && m_picking_enabled) { if (m_gizmos.get_current_type() != GLGizmosManager::SlaSupports && m_gizmos.get_current_type() != GLGizmosManager::FdmSupports && @@ -3460,41 +3460,40 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_dirty = true; } } -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION // Select volume in this 3D canvas. // Don't deselect a volume if layer editing is enabled or any gizmo is active. We want the object to stay selected // during the scene manipulation. -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (m_picking_enabled && (!any_gizmo_active || !evt.ShiftDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled()) && !m_rectangle_selection.is_dragging()) { #else if (m_picking_enabled && (!any_gizmo_active || !evt.CmdDown()) && (!m_hover_volume_idxs.empty() || !is_layers_editing_enabled())) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION if (evt.LeftDown() && !m_hover_volume_idxs.empty()) { int volume_idx = get_first_hover_volume_idx(); bool already_selected = m_selection.contains_volume(volume_idx); -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION bool shift_down = evt.ShiftDown(); #else bool ctrl_down = evt.CmdDown(); -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION Selection::IndicesList curr_idxs = m_selection.get_volume_idxs(); -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (already_selected && shift_down) -#else - if (already_selected && ctrl_down) -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_selection.remove(volume_idx); else { -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION m_selection.add(volume_idx, !shift_down, true); #else + if (already_selected && ctrl_down) + m_selection.remove(volume_idx); + else { m_selection.add(volume_idx, !ctrl_down, true); -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION m_mouse.drag.move_requires_threshold = !already_selected; if (already_selected) m_mouse.set_move_start_threshold_position_2D_as_invalid(); @@ -3516,11 +3515,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (!m_hover_volume_idxs.empty() && !m_rectangle_selection.is_dragging()) { #else if (!m_hover_volume_idxs.empty()) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION if (evt.LeftDown() && m_moving_enabled && m_mouse.drag.move_volume_idx == -1) { // Only accept the initial position, if it is inside the volume bounding box. const int volume_idx = get_first_hover_volume_idx(); @@ -3530,11 +3529,11 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_volumes.volumes[volume_idx]->hover = GLVolume::HS_None; // The dragging operation is initiated. m_mouse.drag.move_volume_idx = volume_idx; -#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#if ENABLE_NEW_CAMERA_MOVEMENTS m_selection.setup_cache(); if (!evt.CmdDown()) -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE - m_mouse.drag.start_position_3D = m_mouse.scene_position; +#endif // ENABLE_NEW_CAMERA_MOVEMENTS + m_mouse.drag.start_position_3D = m_mouse.scene_position; m_sequential_print_clearance_first_displacement = true; m_moving = true; } @@ -3542,12 +3541,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } } -#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#if ENABLE_NEW_CAMERA_MOVEMENTS else if (evt.Dragging() && evt.LeftIsDown() && !evt.CmdDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1 && m_mouse.is_start_position_3D_defined()) { #else else if (evt.Dragging() && evt.LeftIsDown() && m_layers_editing.state == LayersEditing::Unknown && m_mouse.drag.move_volume_idx != -1) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#endif // ENABLE_NEW_CAMERA_MOVEMENTS if (!m_mouse.drag.move_requires_threshold) { m_mouse.dragging = true; Vec3d cur_pos = m_mouse.drag.start_position_3D; @@ -3593,13 +3592,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } else if (evt.Dragging() && evt.LeftIsDown() && m_picking_enabled && m_rectangle_selection.is_dragging()) { -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION // keeps the mouse position updated while dragging the selection rectangle m_mouse.position = pos.cast(); m_rectangle_selection.dragging(m_mouse.position); #else m_rectangle_selection.dragging(pos.cast()); -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION m_dirty = true; } else if (evt.Dragging()) { @@ -3612,17 +3611,15 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } } // do not process the dragging if the left mouse was set down in another canvas -#if ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE +#if ENABLE_NEW_CAMERA_MOVEMENTS else if (evt.LeftIsDown() || evt.MiddleIsDown()) { -#else - else if (evt.LeftIsDown()) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE // if dragging over blank area with left button, rotate -#if ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE if ((any_gizmo_active || evt.CmdDown() || evt.MiddleIsDown() || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { #else + // if dragging over blank area with left button, rotate + else if (evt.LeftIsDown()) { if ((any_gizmo_active || m_hover_volume_idxs.empty()) && m_mouse.is_start_position_3D_defined()) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_CTRL_ROTATE +#endif // ENABLE_NEW_CAMERA_MOVEMENTS const Vec3d rot = (Vec3d(pos.x(), pos.y(), 0.0) - m_mouse.drag.start_position_3D) * (PI * TRACKBALLSIZE / 180.0); if (wxGetApp().app_config->get("use_free_camera") == "1") // Virtual track ball (similar to the 3DConnexion mouse). @@ -3641,13 +3638,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) } m_mouse.drag.start_position_3D = Vec3d((double)pos.x(), (double)pos.y(), 0.0); } -#if ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE +#if ENABLE_NEW_CAMERA_MOVEMENTS else if (evt.RightIsDown()) { // If dragging with right button, pan. #else else if (evt.MiddleIsDown() || evt.RightIsDown()) { // If dragging over blank area with right button, pan. -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_MIDMOUSE_ROTATE +#endif // ENABLE_NEW_CAMERA_MOVEMENTS if (m_mouse.is_start_position_2D_defined()) { // get point in model space at Z = 0 float z = 0.0f; @@ -6418,9 +6415,9 @@ void GLCanvas3D::_update_volumes_hover_state() return; } -#if !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if !ENABLE_NEW_RECTANGLE_SELECTION bool selection_modifiers_only = m_selection.is_empty() || m_selection.is_any_modifier(); -#endif // !ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // !ENABLE_NEW_RECTANGLE_SELECTION bool hover_modifiers_only = true; for (int i : m_hover_volume_idxs) { @@ -6449,14 +6446,14 @@ void GLCanvas3D::_update_volumes_hover_state() if (volume.hover != GLVolume::HS_None) continue; -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION bool deselect = volume.selected && ((shift_pressed && m_rectangle_selection.is_empty()) || (alt_pressed && !m_rectangle_selection.is_empty())); - bool select = !volume.selected && (m_rectangle_selection.is_empty() || (shift_pressed && !m_rectangle_selection.is_empty())); + bool select = !volume.selected && (m_rectangle_selection.is_empty() || (shift_pressed && !m_rectangle_selection.is_empty())); #else bool deselect = volume.selected && ((ctrl_pressed && !shift_pressed) || alt_pressed); // (volume->is_modifier && !selection_modifiers_only && !is_ctrl_pressed) -> allows hovering on selected modifiers belonging to selection of type Instance bool select = (!volume.selected || (volume.is_modifier && !selection_modifiers_only && !ctrl_pressed)) && !alt_pressed; -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION if (select || deselect) { bool as_volume = @@ -7391,9 +7388,9 @@ void GLCanvas3D::_update_selection_from_hover() } bool selection_changed = false; -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION if (!m_rectangle_selection.is_empty()) { -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION if (state == GLSelectionRectangle::EState::Select) { bool contains_all = true; for (int i : m_hover_volume_idxs) { @@ -7424,9 +7421,9 @@ void GLCanvas3D::_update_selection_from_hover() selection_changed = true; } } -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION } -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION if (!selection_changed) return; diff --git a/src/slic3r/GUI/GLSelectionRectangle.hpp b/src/slic3r/GUI/GLSelectionRectangle.hpp index f18dc4a6ab..49b3447ba9 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.hpp +++ b/src/slic3r/GUI/GLSelectionRectangle.hpp @@ -36,9 +36,9 @@ public: void render(const GLCanvas3D& canvas); bool is_dragging() const { return m_state != EState::Off; } -#if ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#if ENABLE_NEW_RECTANGLE_SELECTION bool is_empty() const { return m_state == EState::Off || m_start_corner.isApprox(m_end_corner); } -#endif // ENABLE_NEW_CAMERA_MOVEMENTS_SHIFT_SELECTION +#endif // ENABLE_NEW_RECTANGLE_SELECTION EState get_state() const { return m_state; } From d0d89a4d5bc02a87f417a2f2c73f5f91db0da5d6 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 09:04:44 +0100 Subject: [PATCH 11/22] Tech ENABLE_GL_IMGUI_SHADERS - Render imgui using shaders --- resources/shaders/imgui.fs | 11 +++ resources/shaders/imgui.vs | 17 ++++ src/libslic3r/Technologies.hpp | 2 + src/slic3r/GUI/GLShader.cpp | 16 +++- src/slic3r/GUI/GLShader.hpp | 8 ++ src/slic3r/GUI/GLShadersManager.cpp | 2 + src/slic3r/GUI/ImGuiWrapper.cpp | 133 ++++++++++++++++++++++++++-- 7 files changed, 182 insertions(+), 7 deletions(-) create mode 100644 resources/shaders/imgui.fs create mode 100644 resources/shaders/imgui.vs diff --git a/resources/shaders/imgui.fs b/resources/shaders/imgui.fs new file mode 100644 index 0000000000..4b0e27ce9d --- /dev/null +++ b/resources/shaders/imgui.fs @@ -0,0 +1,11 @@ +#version 110 + +uniform sampler2D Texture; + +varying vec2 Frag_UV; +varying vec4 Frag_Color; + +void main() +{ + gl_FragColor = Frag_Color * texture2D(Texture, Frag_UV.st); +} \ No newline at end of file diff --git a/resources/shaders/imgui.vs b/resources/shaders/imgui.vs new file mode 100644 index 0000000000..100813e2b5 --- /dev/null +++ b/resources/shaders/imgui.vs @@ -0,0 +1,17 @@ +#version 110 + +uniform mat4 ProjMtx; + +attribute vec2 Position; +attribute vec2 UV; +attribute vec4 Color; + +varying vec2 Frag_UV; +varying vec4 Frag_Color; + +void main() +{ + Frag_UV = UV; + Frag_Color = Color; + gl_Position = ProjMtx * vec4(Position.xy, 0.0, 1.0); +} \ No newline at end of file diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 85158ccb22..b90769541c 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -70,6 +70,8 @@ #define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) // Enable using vertex attributes and matrices in shaders #define ENABLE_GL_SHADERS_ATTRIBUTES (1 && ENABLE_LEGACY_OPENGL_REMOVAL) +// Enable rendering imgui using shaders +#define ENABLE_GL_IMGUI_SHADERS (1 && ENABLE_GL_SHADERS_ATTRIBUTES) // Shows an imgui dialog with GLModel statistics data #define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable show non-manifold edges diff --git a/src/slic3r/GUI/GLShader.cpp b/src/slic3r/GUI/GLShader.cpp index 7e5704e87d..c82658e5c0 100644 --- a/src/slic3r/GUI/GLShader.cpp +++ b/src/slic3r/GUI/GLShader.cpp @@ -122,8 +122,7 @@ bool GLShaderProgram::init_from_texts(const std::string& name, const ShaderSourc for (size_t i = 0; i < static_cast(EShaderType::Count); ++i) { const std::string& source = sources[i]; - if (!source.empty()) - { + if (!source.empty()) { EShaderType type = static_cast(i); auto [result, id] = create_shader(type); if (result) @@ -303,6 +302,19 @@ void GLShaderProgram::set_uniform(int id, const Matrix3d& value) const } #endif // ENABLE_GL_SHADERS_ATTRIBUTES +#if ENABLE_GL_IMGUI_SHADERS +void GLShaderProgram::set_uniform(int id, const Matrix4f& value) const +{ + if (id >= 0) + glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, static_cast(value.data()))); +} + +void GLShaderProgram::set_uniform(int id, const Matrix4d& value) const +{ + set_uniform(id, (Matrix4f)value.cast()); +} +#endif // ENABLE_GL_IMGUI_SHADERS + void GLShaderProgram::set_uniform(int id, const Vec3f& value) const { if (id >= 0) diff --git a/src/slic3r/GUI/GLShader.hpp b/src/slic3r/GUI/GLShader.hpp index a867a62bda..3b669fc77d 100644 --- a/src/slic3r/GUI/GLShader.hpp +++ b/src/slic3r/GUI/GLShader.hpp @@ -64,6 +64,10 @@ public: #if ENABLE_GL_SHADERS_ATTRIBUTES void set_uniform(const char* name, const Matrix3d& value) const { set_uniform(get_uniform_location(name), value); } #endif // ENABLE_GL_SHADERS_ATTRIBUTES +#if ENABLE_GL_IMGUI_SHADERS + void set_uniform(const char* name, const Matrix4f& value) const { set_uniform(get_uniform_location(name), value); } + void set_uniform(const char* name, const Matrix4d& value) const { set_uniform(get_uniform_location(name), value); } +#endif // ENABLE_GL_IMGUI_SHADERS void set_uniform(const char* name, const Vec3f& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const Vec3d& value) const { set_uniform(get_uniform_location(name), value); } void set_uniform(const char* name, const ColorRGB& value) const { set_uniform(get_uniform_location(name), value); } @@ -86,6 +90,10 @@ public: #if ENABLE_GL_SHADERS_ATTRIBUTES void set_uniform(int id, const Matrix3d& value) const; #endif // ENABLE_GL_SHADERS_ATTRIBUTES +#if ENABLE_GL_IMGUI_SHADERS + void set_uniform(int id, const Matrix4f& value) const; + void set_uniform(int id, const Matrix4d& value) const; +#endif // ENABLE_GL_IMGUI_SHADERS void set_uniform(int id, const Vec3f& value) const; void set_uniform(int id, const Vec3d& value) const; void set_uniform(int id, const ColorRGB& value) const; diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index 75b6824a70..9f0b03ea0e 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -35,6 +35,8 @@ std::pair GLShadersManager::init() #if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_SHADERS_ATTRIBUTES + // imgui shader + valid &= append_shader("imgui", { "imgui.vs", "imgui.fs" }); // basic shader, used to render all what was previously rendered using the immediate mode valid &= append_shader("flat_attr", { "flat_attr.vs", "flat.fs" }); // basic shader for textures, used to render textures diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 4b75befb6c..819d6141e0 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -26,13 +26,18 @@ #include "libslic3r/libslic3r.h" #include "libslic3r/Utils.hpp" #include "libslic3r/Color.hpp" + #include "3DScene.hpp" #include "GUI.hpp" #include "I18N.hpp" #include "Search.hpp" #include "BitmapCache.hpp" +#if ENABLE_GL_IMGUI_SHADERS +#include "GUI_App.hpp" +#endif // ENABLE_GL_IMGUI_SHADERS #include "../Utils/MacDarkMode.hpp" + #include "nanosvg/nanosvg.h" #include "nanosvg/nanosvgrast.h" @@ -1442,12 +1447,30 @@ void ImGuiWrapper::init_style() void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) { + if (draw_data == nullptr || draw_data->CmdListsCount == 0) + return; + +#if ENABLE_GL_IMGUI_SHADERS + GLShaderProgram* shader = wxGetApp().get_shader("imgui"); + if (shader == nullptr) + return; +#endif // ENABLE_GL_IMGUI_SHADERS + // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); const int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x); const int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y); if (fb_width == 0 || fb_height == 0) return; + +#if ENABLE_GL_IMGUI_SHADERS + GLShaderProgram* curr_shader = wxGetApp().get_current_shader(); + if (curr_shader != nullptr) + curr_shader->stop_using(); + + shader->start_using(); +#endif // ENABLE_GL_IMGUI_SHADERS + draw_data->ScaleClipRects(io.DisplayFramebufferScale); // We are using the OpenGL fixed pipeline to make the example code simpler to read! @@ -1464,17 +1487,37 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glDisable(GL_LIGHTING)); glsafe(::glDisable(GL_COLOR_MATERIAL)); glsafe(::glEnable(GL_SCISSOR_TEST)); +#if !ENABLE_GL_IMGUI_SHADERS glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); glsafe(::glEnableClientState(GL_COLOR_ARRAY)); +#endif // !ENABLE_GL_IMGUI_SHADERS glsafe(::glEnable(GL_TEXTURE_2D)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); GLint texture_env_mode = GL_MODULATE; glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texture_env_mode)); glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); - //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound +#if ENABLE_GL_IMGUI_SHADERS + // Setup viewport, orthographic projection matrix + // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. + glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); + const float L = draw_data->DisplayPos.x; + const float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; + const float T = draw_data->DisplayPos.y; + const float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; + + Matrix4f ortho_projection; + ortho_projection << + 2.0f / (R - L), 0.0f, 0.0f, (R + L) / (L - R), + 0.0f, 2.0f / (T - B), 0.0f, (T + B) / (B - T), + 0.0f, 0.0f, -1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f; + + shader->set_uniform("Texture", 0); + shader->set_uniform("ProjMtx", ortho_projection); +#else // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps. glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); @@ -1485,16 +1528,57 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glMatrixMode(GL_MODELVIEW)); glsafe(::glPushMatrix()); glsafe(::glLoadIdentity()); +#endif // ENABLE_GL_IMGUI_SHADERS + +#if ENABLE_GL_IMGUI_SHADERS + // Will project scissor/clipping rectangles into framebuffer space + const ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports + const ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2) +#else + const ImVec2 pos = draw_data->DisplayPos; +#endif // ENABLE_GL_IMGUI_SHADERS // Render command lists - ImVec2 pos = draw_data->DisplayPos; for (int n = 0; n < draw_data->CmdListsCount; ++n) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; +#if ENABLE_GL_IMGUI_SHADERS + const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); + const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); + + GLuint vbo_id; + glsafe(::glGenBuffers(1, &vbo_id)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); + glsafe(::glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, nullptr, GL_STREAM_DRAW)); + glsafe(::glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data)); + + GLuint ibo_id; + glsafe(::glGenBuffers(1, &ibo_id)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, nullptr, GL_STREAM_DRAW)); + glsafe(::glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data)); + + const int position_id = shader->get_attrib_location("Position"); + if (position_id != -1) { + glVertexAttribPointer(position_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); + glEnableVertexAttribArray(position_id); + } + const int uv_id = shader->get_attrib_location("UV"); + if (uv_id != -1) { + glVertexAttribPointer(uv_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); + glEnableVertexAttribArray(uv_id); + } + const int color_id = shader->get_attrib_location("Color"); + if (color_id != -1) { + glVertexAttribPointer(color_id, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); + glEnableVertexAttribArray(color_id); + } +#else glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)))); glsafe(::glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)))); glsafe(::glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)))); +#endif // ENABLE_GL_IMGUI_SHADERS for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; ++cmd_i) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; @@ -1502,34 +1586,73 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // User callback (registered via ImDrawList::AddCallback) pcmd->UserCallback(cmd_list, pcmd); else { - ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y); +#if ENABLE_GL_IMGUI_SHADERS + // Project scissor/clipping rectangles into framebuffer space + const ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); + const ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); + if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) + continue; + + // Apply scissor/clipping rectangle (Y is inverted in OpenGL) + glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); + + // Bind texture, Draw + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); + glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)))); +#else + const ImVec4 clip_rect = ImVec4(pcmd->ClipRect.x - pos.x, pcmd->ClipRect.y - pos.y, pcmd->ClipRect.z - pos.x, pcmd->ClipRect.w - pos.y); if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) { // Apply scissor/clipping rectangle glsafe(::glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y))); // Bind texture, Draw - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId)); - glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer)); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); + glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(intptr_t)(pcmd->IdxOffset * sizeof(ImDrawIdx)))); } +#endif // ENABLE_GL_IMGUI_SHADERS } idx_buffer += pcmd->ElemCount; } + +#if ENABLE_GL_IMGUI_SHADERS + if (position_id != -1) + glDisableVertexAttribArray(position_id); + if (uv_id != -1) + glDisableVertexAttribArray(uv_id); + if (color_id != -1) + glDisableVertexAttribArray(color_id); + + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + + glsafe(::glDeleteBuffers(1, &ibo_id)); + glsafe(::glDeleteBuffers(1, &vbo_id)); +#endif // ENABLE_GL_IMGUI_SHADERS } // Restore modified state glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_env_mode)); +#if !ENABLE_GL_IMGUI_SHADERS glsafe(::glDisableClientState(GL_COLOR_ARRAY)); glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); +#endif // !ENABLE_GL_IMGUI_SHADERS glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); +#if !ENABLE_GL_IMGUI_SHADERS glsafe(::glMatrixMode(GL_MODELVIEW)); glsafe(::glPopMatrix()); glsafe(::glMatrixMode(GL_PROJECTION)); glsafe(::glPopMatrix()); +#endif // !ENABLE_GL_IMGUI_SHADERS glsafe(::glPopAttrib()); glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1])); glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3])); glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); + +#if ENABLE_GL_IMGUI_SHADERS + if (curr_shader != nullptr) + curr_shader->start_using(); +#endif // ENABLE_GL_IMGUI_SHADERS } bool ImGuiWrapper::display_initialized() const From 5586fd92f2c32a7bb71a31fb5b6a31d540d32e20 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 09:50:25 +0100 Subject: [PATCH 12/22] Follow-up of d0d89a4d5bc02a87f417a2f2c73f5f91db0da5d6 - Fixed warnings --- src/slic3r/GUI/ImGuiWrapper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 819d6141e0..622f3b3907 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1551,13 +1551,13 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glGenBuffers(1, &vbo_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); glsafe(::glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, nullptr, GL_STREAM_DRAW)); - glsafe(::glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)cmd_list->VtxBuffer.Data)); + glsafe(::glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)vtx_buffer)); GLuint ibo_id; glsafe(::glGenBuffers(1, &ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id)); glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, nullptr, GL_STREAM_DRAW)); - glsafe(::glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)cmd_list->IdxBuffer.Data)); + glsafe(::glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)idx_buffer)); const int position_id = shader->get_attrib_location("Position"); if (position_id != -1) { From 4eee0d05f3367c9b05f195ec2e4e4ada41ba5b94 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 09:50:42 +0100 Subject: [PATCH 13/22] Tech ENABLE_GL_SHADERS_ATTRIBUTES - Use shader's vertex attributes and matrices in GLMmSegmentationGizmo3DScene --- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index 13c8a71c62..49eb8cb95b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -600,11 +600,17 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) return; #if ENABLE_GL_SHADERS_ATTRIBUTES assert(shader->get_name() == "mm_gouraud_attr"); + + const Camera& camera = wxGetApp().plater()->get_camera(); + const Transform3d view_model_matrix = camera.get_view_matrix() * matrix; + shader->set_uniform("view_model_matrix", view_model_matrix); + shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("normal_matrix", (Matrix3d)view_model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); #else assert(shader->get_name() == "mm_gouraud"); #endif // ENABLE_GL_SHADERS_ATTRIBUTES - for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) + for (size_t color_idx = 0; color_idx < m_gizmo_scene.triangle_indices.size(); ++color_idx) { if (m_gizmo_scene.has_VBOs(color_idx)) { if (color_idx > m_colors.size()) // Seed fill VBO shader->set_uniform("uniform_color", TriangleSelectorGUI::get_seed_fill_color(color_idx == (m_colors.size() + 1) ? m_default_volume_color : m_colors[color_idx - (m_colors.size() + 1) - 1])); @@ -613,6 +619,7 @@ void TriangleSelectorMmGui::render(ImGuiWrapper *imgui) m_gizmo_scene.render(color_idx); } + } #if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_GL_SHADERS_ATTRIBUTES @@ -724,19 +731,41 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); - glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); +#if ENABLE_GL_SHADERS_ATTRIBUTES + GLShaderProgram* shader = wxGetApp().get_current_shader(); + if (shader == nullptr) + return; +#endif // ENABLE_GL_SHADERS_ATTRIBUTES + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); +#if ENABLE_GL_SHADERS_ATTRIBUTES + const GLint position_id = shader->get_attrib_location("v_position"); + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (GLvoid*)0)); + glsafe(::glEnableVertexAttribArray(position_id)); + } + + // Render using the Vertex Buffer Objects. + if (this->triangle_indices_VBO_ids[triangle_indices_idx] != 0 && + this->triangle_indices_sizes[triangle_indices_idx] > 0) { +#else + glsafe(::glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), (const void*)(0 * sizeof(float)))); glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); // Render using the Vertex Buffer Objects. if (this->triangle_indices_sizes[triangle_indices_idx] > 0) { +#endif // ENABLE_GL_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[triangle_indices_idx])); glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_sizes[triangle_indices_idx]), GL_UNSIGNED_INT, nullptr)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } +#if ENABLE_GL_SHADERS_ATTRIBUTES + if (position_id != -1) + glsafe(::glDisableVertexAttribArray(position_id)); +#else glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); } From f0bad14748f12ec758248627fd7a047c13f089e5 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 09:59:38 +0100 Subject: [PATCH 14/22] Tech ENABLE_GL_SHADERS_ATTRIBUTES - Small refactoring into GCodeViewer::render_toolpaths() --- src/slic3r/GUI/GCodeViewer.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index cb54376357..d174f781c6 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -3194,15 +3194,13 @@ void GCodeViewer::render_toolpaths() shader->start_using(); #if ENABLE_GL_SHADERS_ATTRIBUTES - int position_id = -1; - int normal_id = -1; const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - position_id = shader->get_attrib_location("v_position"); - normal_id = shader->get_attrib_location("v_normal"); + const int position_id = shader->get_attrib_location("v_position"); + const int normal_id = shader->get_attrib_location("v_normal"); #endif // ENABLE_GL_SHADERS_ATTRIBUTES if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { @@ -3319,16 +3317,14 @@ void GCodeViewer::render_toolpaths() shader->start_using(); #if ENABLE_GL_SHADERS_ATTRIBUTES - int position_id = -1; - int normal_id = -1; const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - position_id = shader->get_attrib_location("v_position"); - normal_id = shader->get_attrib_location("v_normal"); + const int position_id = shader->get_attrib_location("v_position"); + const int normal_id = shader->get_attrib_location("v_normal"); #endif // ENABLE_GL_SHADERS_ATTRIBUTES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo)); From 2ab8469cb64bc7f8c37d5f7f583275510c68116b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 13:34:08 +0100 Subject: [PATCH 15/22] Refactoring in ImGuiWrapper::render_draw_data() --- src/slic3r/GUI/ImGuiWrapper.cpp | 46 ++++++++++++++------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 622f3b3907..613b168415 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1458,7 +1458,7 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); - const int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x); + const int fb_width = (int)(draw_data->DisplaySize.x * io.DisplayFramebufferScale.x); const int fb_height = (int)(draw_data->DisplaySize.y * io.DisplayFramebufferScale.y); if (fb_width == 0 || fb_height == 0) return; @@ -1469,9 +1469,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) curr_shader->stop_using(); shader->start_using(); -#endif // ENABLE_GL_IMGUI_SHADERS - +#else draw_data->ScaleClipRects(io.DisplayFramebufferScale); +#endif // ENABLE_GL_IMGUI_SHADERS // We are using the OpenGL fixed pipeline to make the example code simpler to read! // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. @@ -1479,15 +1479,16 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) GLint last_polygon_mode[2]; glsafe(::glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode)); GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport)); GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box)); + GLint last_texture_env_mode; glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_texture_env_mode)); glsafe(::glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT)); glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glDisable(GL_CULL_FACE)); glsafe(::glDisable(GL_DEPTH_TEST)); - glsafe(::glDisable(GL_LIGHTING)); - glsafe(::glDisable(GL_COLOR_MATERIAL)); glsafe(::glEnable(GL_SCISSOR_TEST)); #if !ENABLE_GL_IMGUI_SHADERS + glsafe(::glDisable(GL_LIGHTING)); + glsafe(::glDisable(GL_COLOR_MATERIAL)); glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); glsafe(::glEnableClientState(GL_COLOR_ARRAY)); @@ -1495,9 +1496,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glEnable(GL_TEXTURE_2D)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); - GLint texture_env_mode = GL_MODULATE; - glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texture_env_mode)); - glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); #if ENABLE_GL_IMGUI_SHADERS // Setup viewport, orthographic projection matrix @@ -1550,29 +1548,27 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) GLuint vbo_id; glsafe(::glGenBuffers(1, &vbo_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, nullptr, GL_STREAM_DRAW)); - glsafe(::glBufferSubData(GL_ARRAY_BUFFER, 0, vtx_buffer_size, (const GLvoid*)vtx_buffer)); + glsafe(::glBufferData(GL_ARRAY_BUFFER, vtx_buffer_size, vtx_buffer, GL_STATIC_DRAW)); GLuint ibo_id; glsafe(::glGenBuffers(1, &ibo_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_id)); - glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, nullptr, GL_STREAM_DRAW)); - glsafe(::glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, idx_buffer_size, (const GLvoid*)idx_buffer)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, idx_buffer_size, idx_buffer, GL_STATIC_DRAW)); const int position_id = shader->get_attrib_location("Position"); if (position_id != -1) { - glVertexAttribPointer(position_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); - glEnableVertexAttribArray(position_id); + glsafe(::glVertexAttribPointer(position_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, pos))); + glsafe(::glEnableVertexAttribArray(position_id)); } const int uv_id = shader->get_attrib_location("UV"); if (uv_id != -1) { - glVertexAttribPointer(uv_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); - glEnableVertexAttribArray(uv_id); + glsafe(::glVertexAttribPointer(uv_id, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, uv))); + glsafe(::glEnableVertexAttribArray(uv_id)); } const int color_id = shader->get_attrib_location("Color"); if (color_id != -1) { - glVertexAttribPointer(color_id, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col)); - glEnableVertexAttribArray(color_id); + glsafe(::glVertexAttribPointer(color_id, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(ImDrawVert), (GLvoid*)IM_OFFSETOF(ImDrawVert, col))); + glsafe(::glEnableVertexAttribArray(color_id)); } #else glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)))); @@ -1594,7 +1590,7 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) continue; // Apply scissor/clipping rectangle (Y is inverted in OpenGL) - glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y)); + glsafe(::glScissor((int)clip_min.x, (int)(fb_height - clip_max.y), (int)(clip_max.x - clip_min.x), (int)(clip_max.y - clip_min.y))); // Bind texture, Draw glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->GetTexID())); @@ -1616,11 +1612,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) #if ENABLE_GL_IMGUI_SHADERS if (position_id != -1) - glDisableVertexAttribArray(position_id); + glsafe(::glDisableVertexAttribArray(position_id)); if (uv_id != -1) - glDisableVertexAttribArray(uv_id); + glsafe(::glDisableVertexAttribArray(uv_id)); if (color_id != -1) - glDisableVertexAttribArray(color_id); + glsafe(::glDisableVertexAttribArray(color_id)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); @@ -1631,14 +1627,12 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) } // Restore modified state - glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_env_mode)); + glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_texture_env_mode)); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); #if !ENABLE_GL_IMGUI_SHADERS glsafe(::glDisableClientState(GL_COLOR_ARRAY)); glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); -#endif // !ENABLE_GL_IMGUI_SHADERS - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); -#if !ENABLE_GL_IMGUI_SHADERS glsafe(::glMatrixMode(GL_MODELVIEW)); glsafe(::glPopMatrix()); glsafe(::glMatrixMode(GL_PROJECTION)); From 9174fc487211d3434e2029a8136cda0b3b091591 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 14:25:09 +0100 Subject: [PATCH 16/22] Removed obsolete tech ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS --- src/libslic3r/Technologies.hpp | 2 -- src/slic3r/GUI/GCodeViewer.cpp | 8 -------- 2 files changed, 10 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index b90769541c..5a1e2dc7d3 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -34,8 +34,6 @@ #define ENABLE_ENVIRONMENT_MAP 0 // Enable smoothing of objects normals #define ENABLE_SMOOTH_NORMALS 0 -// Enable rendering markers for options in preview as fixed screen size points -#define ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS 1 //================ diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index d174f781c6..fcff51d37d 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2968,11 +2968,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool void GCodeViewer::render_toolpaths() { -#if ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS - const float point_size = 20.0f; -#else const float point_size = 0.8f; -#endif // ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS #if !ENABLE_GL_SHADERS_ATTRIBUTES const std::array light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f }; #endif // !ENABLE_GL_SHADERS_ATTRIBUTES @@ -2983,11 +2979,7 @@ void GCodeViewer::render_toolpaths() static_cast(viewport[3]) * 0.0005; auto shader_init_as_points = [zoom, point_size, near_plane_height](GLShaderProgram& shader) { -#if ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS - shader.set_uniform("use_fixed_screen_size", 1); -#else shader.set_uniform("use_fixed_screen_size", 0); -#endif // ENABLE_FIXED_SCREEN_SIZE_POINT_MARKERS shader.set_uniform("zoom", zoom); shader.set_uniform("percent_outline_radius", 0.0f); shader.set_uniform("percent_center_radius", 0.33f); From 033bee64311d7645a581020dde77b028aac9dbc2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 14:55:25 +0100 Subject: [PATCH 17/22] Removed obsolete code from GCodeViewer --- src/slic3r/GUI/GCodeViewer.cpp | 75 +++------------------------------- src/slic3r/GUI/GCodeViewer.hpp | 7 ---- 2 files changed, 6 insertions(+), 76 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index fcff51d37d..84175e8033 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1310,18 +1310,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) log_memory_used(label, vertices_size + indices_size); }; - // format data into the buffers to be rendered as points - auto add_vertices_as_point = [](const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { - vertices.push_back(curr.position.x()); - vertices.push_back(curr.position.y()); - vertices.push_back(curr.position.z()); - }; - auto add_indices_as_point = [](const GCodeProcessorResult::MoveVertex& curr, TBuffer& buffer, - unsigned int ibuffer_id, IndexBuffer& indices, size_t move_id) { - buffer.add_path(curr, ibuffer_id, indices.size(), move_id); - indices.push_back(static_cast(indices.size())); - }; - // format data into the buffers to be rendered as lines auto add_vertices_as_line = [](const GCodeProcessorResult::MoveVertex& prev, const GCodeProcessorResult::MoveVertex& curr, VertexBuffer& vertices) { #if !ENABLE_GL_SHADERS_ATTRIBUTES @@ -1816,7 +1804,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) switch (t_buffer.render_primitive_type) { - case TBuffer::ERenderPrimitiveType::Point: { add_vertices_as_point(curr, v_buffer); break; } case TBuffer::ERenderPrimitiveType::Line: { add_vertices_as_line(prev, curr, v_buffer); break; } #if ENABLE_VOLUMETRIC_RATE_TOOLPATHS_RECALC case TBuffer::ERenderPrimitiveType::Triangle: { add_vertices_as_solid(prev, curr, t_buffer, static_cast(v_multibuffer.size()) - 1, v_buffer, move_id, account_for_volumetric_rate); break; } @@ -2152,8 +2139,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) if (i_multibuffer.back().size() * sizeof(IBufferType) >= IBUFFER_THRESHOLD_BYTES - indiced_size_to_add) { i_multibuffer.push_back(IndexBuffer()); vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::Point && - t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { + if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { Path& last_path = t_buffer.paths.back(); last_path.add_sub_path(prev, static_cast(i_multibuffer.size()) - 1, 0, move_id - 1); } @@ -2169,8 +2155,7 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) curr_vertex_buffer.second = 0; vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]); - if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::Point && - t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { + if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) { Path& last_path = t_buffer.paths.back(); last_path.add_sub_path(prev, static_cast(i_multibuffer.size()) - 1, 0, move_id - 1); } @@ -2180,11 +2165,6 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result) switch (t_buffer.render_primitive_type) { - case TBuffer::ERenderPrimitiveType::Point: { - add_indices_as_point(curr, t_buffer, static_cast(i_multibuffer.size()) - 1, i_buffer, move_id); - curr_vertex_buffer.second += t_buffer.max_vertices_per_segment(); - break; - } case TBuffer::ERenderPrimitiveType::Line: { #if ENABLE_VOLUMETRIC_RATE_TOOLPATHS_RECALC add_indices_as_line(prev, curr, t_buffer, static_cast(i_multibuffer.size()) - 1, i_buffer, move_id, account_for_volumetric_rate); @@ -2732,10 +2712,6 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool unsigned int size_in_indices = 0; switch (buffer.render_primitive_type) { - case TBuffer::ERenderPrimitiveType::Point: { - size_in_indices = buffer.indices_per_segment(); - break; - } case TBuffer::ERenderPrimitiveType::Line: case TBuffer::ERenderPrimitiveType::Triangle: { unsigned int segments_count = std::min(m_sequential_view.current.last, sub_path.last.s_id) - std::max(m_sequential_view.current.first, sub_path.first.s_id); @@ -2978,39 +2954,6 @@ void GCodeViewer::render_toolpaths() const float near_plane_height = camera.get_type() == Camera::EType::Perspective ? static_cast(viewport[3]) / (2.0f * static_cast(2.0 * std::tan(0.5 * Geometry::deg2rad(camera.get_fov())))) : static_cast(viewport[3]) * 0.0005; - auto shader_init_as_points = [zoom, point_size, near_plane_height](GLShaderProgram& shader) { - shader.set_uniform("use_fixed_screen_size", 0); - shader.set_uniform("zoom", zoom); - shader.set_uniform("percent_outline_radius", 0.0f); - shader.set_uniform("percent_center_radius", 0.33f); - shader.set_uniform("point_size", point_size); - shader.set_uniform("near_plane_height", near_plane_height); - }; - - auto render_as_points = [ -#if ENABLE_GCODE_VIEWER_STATISTICS - this -#endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { - glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)); - glsafe(::glEnable(GL_POINT_SPRITE)); - - for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { - const RenderPath& path = *it; - // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. - assert(! path.sizes.empty()); - assert(! path.offsets.empty()); - shader.set_uniform(uniform_color, path.color); - glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_SHORT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); -#if ENABLE_GCODE_VIEWER_STATISTICS - ++m_statistics.gl_multi_points_calls_count; -#endif // ENABLE_GCODE_VIEWER_STATISTICS - } - - glsafe(::glDisable(GL_POINT_SPRITE)); - glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE)); - }; - #if !ENABLE_GL_SHADERS_ATTRIBUTES auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { shader.set_uniform("light_intensity", light_intensity); @@ -3190,9 +3133,6 @@ void GCodeViewer::render_toolpaths() shader->set_uniform("view_model_matrix", view_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("normal_matrix", (Matrix3d)view_matrix.matrix().block(0, 0, 3, 3).inverse().transpose()); - - const int position_id = shader->get_attrib_location("v_position"); - const int normal_id = shader->get_attrib_location("v_normal"); #endif // ENABLE_GL_SHADERS_ATTRIBUTES if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::InstancedModel) { @@ -3203,6 +3143,8 @@ void GCodeViewer::render_toolpaths() else if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::BatchedModel) { shader->set_uniform("emission_factor", 0.25f); #if ENABLE_GL_SHADERS_ATTRIBUTES + const int position_id = shader->get_attrib_location("v_position"); + const int normal_id = shader->get_attrib_location("v_normal"); render_as_batched_model(buffer, *shader, position_id, normal_id); #else render_as_batched_model(buffer, *shader); @@ -3211,8 +3153,8 @@ void GCodeViewer::render_toolpaths() } else { #if ENABLE_GL_SHADERS_ATTRIBUTES - if (buffer.render_primitive_type == TBuffer::ERenderPrimitiveType::Point) - shader_init_as_points(*shader); + const int position_id = shader->get_attrib_location("v_position"); + const int normal_id = shader->get_attrib_location("v_normal"); #else switch (buffer.render_primitive_type) { case TBuffer::ERenderPrimitiveType::Point: shader_init_as_points(*shader); break; @@ -3259,10 +3201,6 @@ void GCodeViewer::render_toolpaths() // Render all elements with it_path->ibuffer_id == ibuffer_id, possible with varying colors. switch (buffer.render_primitive_type) { - case TBuffer::ERenderPrimitiveType::Point: { - render_as_points(it_path, buffer.render_paths.end(), *shader, uniform_color); - break; - } case TBuffer::ERenderPrimitiveType::Line: { glsafe(::glLineWidth(static_cast(line_width(zoom)))); render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); @@ -4670,7 +4608,6 @@ void GCodeViewer::render_statistics() } if (ImGui::CollapsingHeader("OpenGL calls")) { - add_counter(std::string("Multi GL_POINTS:"), m_statistics.gl_multi_points_calls_count); add_counter(std::string("Multi GL_LINES:"), m_statistics.gl_multi_lines_calls_count); add_counter(std::string("Multi GL_TRIANGLES:"), m_statistics.gl_multi_triangles_calls_count); add_counter(std::string("GL_TRIANGLES:"), m_statistics.gl_triangles_calls_count); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 438fc55fd1..e2ee6dcd0d 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -284,7 +284,6 @@ class GCodeViewer { enum class ERenderPrimitiveType : unsigned char { - Point, Line, Triangle, InstancedModel, @@ -325,7 +324,6 @@ class GCodeViewer unsigned int max_vertices_per_segment() const { switch (render_primitive_type) { - case ERenderPrimitiveType::Point: { return 1; } case ERenderPrimitiveType::Line: { return 2; } case ERenderPrimitiveType::Triangle: { return 8; } default: { return 0; } @@ -337,7 +335,6 @@ class GCodeViewer unsigned int indices_per_segment() const { switch (render_primitive_type) { - case ERenderPrimitiveType::Point: { return 1; } case ERenderPrimitiveType::Line: { return 2; } case ERenderPrimitiveType::Triangle: { return 30; } // 3 indices x 10 triangles default: { return 0; } @@ -347,7 +344,6 @@ class GCodeViewer unsigned int max_indices_per_segment() const { switch (render_primitive_type) { - case ERenderPrimitiveType::Point: { return 1; } case ERenderPrimitiveType::Line: { return 2; } case ERenderPrimitiveType::Triangle: { return 36; } // 3 indices x 12 triangles default: { return 0; } @@ -358,7 +354,6 @@ class GCodeViewer bool has_data() const { switch (render_primitive_type) { - case ERenderPrimitiveType::Point: case ERenderPrimitiveType::Line: case ERenderPrimitiveType::Triangle: { return !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0; @@ -585,7 +580,6 @@ class GCodeViewer int64_t refresh_time{ 0 }; int64_t refresh_paths_time{ 0 }; // opengl calls - int64_t gl_multi_points_calls_count{ 0 }; int64_t gl_multi_lines_calls_count{ 0 }; int64_t gl_multi_triangles_calls_count{ 0 }; int64_t gl_triangles_calls_count{ 0 }; @@ -628,7 +622,6 @@ class GCodeViewer } void reset_opengl() { - gl_multi_points_calls_count = 0; gl_multi_lines_calls_count = 0; gl_multi_triangles_calls_count = 0; gl_triangles_calls_count = 0; From 0a2001ed1c862553ff9d1229cf09be8b9bdbf8c8 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 14 Mar 2022 15:21:00 +0100 Subject: [PATCH 18/22] #8032 - GCodeProcessor - Fixed parsing of LAYER_CHANGE tag for spiral vase mode --- src/libslic3r/GCode/GCodeProcessor.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 50c0ce4a54..3bf7c4ffd3 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1952,12 +1952,15 @@ void GCodeProcessor::process_tags(const std::string_view comment, bool producers ++m_layer_id; #if ENABLE_SPIRAL_VASE_LAYERS if (m_spiral_vase_active) { - assert(!m_result.moves.empty()); - size_t move_id = m_result.moves.size() - 1; - if (!m_result.spiral_vase_layers.empty() && m_end_position[Z] == m_result.spiral_vase_layers.back().first) - m_result.spiral_vase_layers.back().second.second = move_id; - else - m_result.spiral_vase_layers.push_back({ static_cast(m_end_position[Z]), { move_id, move_id } }); + if (m_result.moves.empty()) + m_result.spiral_vase_layers.push_back({ m_first_layer_height, { 0, 0 } }); + else { + const size_t move_id = m_result.moves.size() - 1; + if (!m_result.spiral_vase_layers.empty() && m_end_position[Z] == m_result.spiral_vase_layers.back().first) + m_result.spiral_vase_layers.back().second.second = move_id; + else + m_result.spiral_vase_layers.push_back({ static_cast(m_end_position[Z]), { move_id, move_id } }); + } } #endif // ENABLE_SPIRAL_VASE_LAYERS return; From 887ce895580686f87693dbe8a59800950a9b767e Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Mar 2022 08:50:00 +0100 Subject: [PATCH 19/22] Limit width of GCodeViewer::SequentialView::GCodeWindow --- src/slic3r/GUI/GCodeViewer.cpp | 73 +++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 84175e8033..2a63a30049 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -459,6 +459,7 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, u static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f }; static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f }; static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f }; + static const ImVec4 ELLIPSIS_COLOR = { 0.0f, 0.7f, 0.0f, 1.0f }; if (!m_visible || m_filename.empty() || m_lines_ends.empty() || curr_line_id == 0) return; @@ -503,6 +504,35 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, u ImGuiWrapper& imgui = *wxGetApp().imgui(); + auto add_item_to_line = [&imgui](const std::string& txt, const ImVec4& color, float spacing, size_t& current_length) { + static const size_t LENGTH_THRESHOLD = 60; + + if (txt.empty()) + return false; + + std::string out_text = txt; + bool reduced = false; + if (current_length + out_text.length() > LENGTH_THRESHOLD) { + out_text = out_text.substr(0, LENGTH_THRESHOLD - current_length); + reduced = true; + } + + current_length += out_text.length(); + + ImGui::SameLine(0.0f, spacing); + ImGui::PushStyleColor(ImGuiCol_Text, color); + imgui.text(out_text); + ImGui::PopStyleColor(); + if (reduced) { + ImGui::SameLine(0.0f, 0.0f); + ImGui::PushStyleColor(ImGuiCol_Text, ELLIPSIS_COLOR); + imgui.text("..."); + ImGui::PopStyleColor(); + } + + return reduced; + }; + imgui.set_next_window_pos(0.0f, top, ImGuiCond_Always, 0.0f, 0.0f); imgui.set_next_window_size(0.0f, wnd_height, ImGuiCond_Always); ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); @@ -527,41 +557,22 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, u ImGui::GetColorU32(SELECTION_RECT_COLOR)); } - // render line number const std::string id_str = std::to_string(id); // spacer to right align text ImGui::Dummy({ id_width - ImGui::CalcTextSize(id_str.c_str()).x, text_height }); - ImGui::SameLine(0.0f, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, LINE_NUMBER_COLOR); - imgui.text(id_str); - ImGui::PopStyleColor(); - if (!line.command.empty() || !line.comment.empty()) - ImGui::SameLine(); - - // render command - if (!line.command.empty()) { - ImGui::PushStyleColor(ImGuiCol_Text, COMMAND_COLOR); - imgui.text(line.command); - ImGui::PopStyleColor(); - } - - // render parameters - if (!line.parameters.empty()) { - ImGui::SameLine(0.0f, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, PARAMETERS_COLOR); - imgui.text(line.parameters); - ImGui::PopStyleColor(); - } - - // render comment - if (!line.comment.empty()) { - if (!line.command.empty()) - ImGui::SameLine(0.0f, 0.0f); - ImGui::PushStyleColor(ImGuiCol_Text, COMMENT_COLOR); - imgui.text(line.comment); - ImGui::PopStyleColor(); - } + size_t line_length = 0; + // render line number + bool stop_adding = add_item_to_line(id_str, LINE_NUMBER_COLOR, 0.0f, line_length); + if (!stop_adding && !line.command.empty()) + // render command + stop_adding = add_item_to_line(line.command, COMMAND_COLOR, -1.0f, line_length); + if (!stop_adding && !line.parameters.empty()) + // render parameters + stop_adding = add_item_to_line(line.parameters, PARAMETERS_COLOR, 0.0f, line_length); + if (!stop_adding && !line.comment.empty()) + // render comment + stop_adding = add_item_to_line(line.comment, COMMENT_COLOR, line.command.empty() ? -1.0f : 0.0f, line_length); } imgui.end(); From 58701b237d233f2b0517106c7ce3a4f10db55873 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Mar 2022 09:05:16 +0100 Subject: [PATCH 20/22] Tech ENABLE_GL_SHADERS_ATTRIBUTES - Fixed rendering of bed texture in thumbnails --- src/slic3r/GUI/3DBed.cpp | 15 +++++++++++---- src/slic3r/GUI/3DBed.hpp | 8 +++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 177c508ad3..f3176d2c73 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -515,7 +515,7 @@ void Bed3D::render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, co render_model(view_matrix, projection_matrix); if (show_texture) - render_texture(bottom, canvas); + render_texture(bottom, canvas, view_matrix, projection_matrix); } #else void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) @@ -528,7 +528,11 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom, bool show_texture) } #endif // ENABLE_GL_SHADERS_ATTRIBUTES +#if ENABLE_GL_SHADERS_ATTRIBUTES +void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix) +#else void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) +#endif // ENABLE_GL_SHADERS_ATTRIBUTES { if (m_texture_filename.empty()) { m_texture.reset(); @@ -600,9 +604,8 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (shader != nullptr) { shader->start_using(); #if ENABLE_GL_SHADERS_ATTRIBUTES - const Camera& camera = wxGetApp().plater()->get_camera(); - shader->set_uniform("view_model_matrix", camera.get_view_matrix()); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", projection_matrix); #endif // ENABLE_GL_SHADERS_ATTRIBUTES shader->set_uniform("transparent_background", bottom); shader->set_uniform("svg_source", boost::algorithm::iends_with(m_texture.get_source(), ".svg")); @@ -766,7 +769,11 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo #endif // ENABLE_GL_SHADERS_ATTRIBUTES if (show_texture) +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_texture(bottom, canvas, view_matrix, projection_matrix); +#else render_texture(bottom, canvas); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES } void Bed3D::render_default(bool bottom, bool picking) diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index de4fa99cfc..167577882a 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -168,14 +168,12 @@ private: void render_axes(); #if ENABLE_GL_SHADERS_ATTRIBUTES void render_system(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture); -#else - void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); -#endif // ENABLE_GL_SHADERS_ATTRIBUTES - void render_texture(bool bottom, GLCanvas3D& canvas); -#if ENABLE_GL_SHADERS_ATTRIBUTES + void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); #else + void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); + void render_texture(bool bottom, GLCanvas3D& canvas); void render_model(); void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); #endif // ENABLE_GL_SHADERS_ATTRIBUTES From 568bd39c5ab3ea4ed43b8f43f14e2c746b289087 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Mar 2022 09:16:06 +0100 Subject: [PATCH 21/22] Tech ENABLE_GL_SHADERS_ATTRIBUTES - Fixed rendering of default bed in thumbnails --- src/slic3r/GUI/3DBed.cpp | 37 ++++++++++++++++++++++++++++++++++--- src/slic3r/GUI/3DBed.hpp | 4 +++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index f3176d2c73..3cbebfff8c 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -536,7 +536,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) { if (m_texture_filename.empty()) { m_texture.reset(); +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -549,7 +553,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (!m_temp_texture.load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } canvas.request_extra_frame(); @@ -557,7 +565,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_svg_file(m_texture_filename, true, true, true, max_tex_size)) { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } } @@ -565,7 +577,11 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // generate a temporary lower resolution texture to show while no main texture levels have been compressed if (m_temp_texture.get_id() == 0 || m_temp_texture.get_source() != m_texture_filename) { if (!m_temp_texture.load_from_file(m_texture_filename, false, GLTexture::None, false)) { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } canvas.request_extra_frame(); @@ -573,12 +589,20 @@ void Bed3D::render_texture(bool bottom, GLCanvas3D& canvas) // starts generating the main texture, compression will run asynchronously if (!m_texture.load_from_file(m_texture_filename, true, GLTexture::MultiThreaded, true)) { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } } else { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, false, view_matrix, projection_matrix); +#else render_default(bottom, false); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } } @@ -757,7 +781,11 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo #endif // ENABLE_GL_SHADERS_ATTRIBUTES { if (m_texture_filename.empty() && m_model_filename.empty()) { +#if ENABLE_GL_SHADERS_ATTRIBUTES + render_default(bottom, picking, view_matrix, projection_matrix); +#else render_default(bottom, picking); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES return; } @@ -776,7 +804,11 @@ void Bed3D::render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bo #endif // ENABLE_GL_SHADERS_ATTRIBUTES } +#if ENABLE_GL_SHADERS_ATTRIBUTES +void Bed3D::render_default(bool bottom, bool picking, const Transform3d& view_matrix, const Transform3d& projection_matrix) +#else void Bed3D::render_default(bool bottom, bool picking) +#endif // ENABLE_GL_SHADERS_ATTRIBUTES { m_texture.reset(); @@ -793,9 +825,8 @@ void Bed3D::render_default(bool bottom, bool picking) shader->start_using(); #if ENABLE_GL_SHADERS_ATTRIBUTES - const Camera& camera = wxGetApp().plater()->get_camera(); - shader->set_uniform("view_model_matrix", camera.get_view_matrix()); - shader->set_uniform("projection_matrix", camera.get_projection_matrix()); + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", projection_matrix); #endif // ENABLE_GL_SHADERS_ATTRIBUTES glsafe(::glEnable(GL_DEPTH_TEST)); diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index 167577882a..7c334cb939 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -171,13 +171,15 @@ private: void render_texture(bool bottom, GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_model(const Transform3d& view_matrix, const Transform3d& projection_matrix); void render_custom(GLCanvas3D& canvas, const Transform3d& view_matrix, const Transform3d& projection_matrix, bool bottom, bool show_texture, bool picking); + void render_default(bool bottom, bool picking, const Transform3d& view_matrix, const Transform3d& projection_matrix); #else void render_system(GLCanvas3D& canvas, bool bottom, bool show_texture); void render_texture(bool bottom, GLCanvas3D& canvas); void render_model(); void render_custom(GLCanvas3D& canvas, bool bottom, bool show_texture, bool picking); -#endif // ENABLE_GL_SHADERS_ATTRIBUTES void render_default(bool bottom, bool picking); +#endif // ENABLE_GL_SHADERS_ATTRIBUTES + #if !ENABLE_LEGACY_OPENGL_REMOVAL void release_VBOs(); #endif // !ENABLE_LEGACY_OPENGL_REMOVAL From 9701d3b01d2d64c3e45d7357c645f8664990f6d2 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 15 Mar 2022 10:31:30 +0100 Subject: [PATCH 22/22] Follow-up of 033bee64311d7645a581020dde77b028aac9dbc2 - Fixed warnings --- src/slic3r/GUI/GCodeViewer.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 2a63a30049..d33004f494 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -2955,15 +2955,11 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool void GCodeViewer::render_toolpaths() { - const float point_size = 0.8f; #if !ENABLE_GL_SHADERS_ATTRIBUTES const std::array light_intensity = { 0.25f, 0.70f, 0.75f, 0.75f }; #endif // !ENABLE_GL_SHADERS_ATTRIBUTES const Camera& camera = wxGetApp().plater()->get_camera(); const double zoom = camera.get_zoom(); - const std::array& viewport = camera.get_viewport(); - const float near_plane_height = camera.get_type() == Camera::EType::Perspective ? static_cast(viewport[3]) / (2.0f * static_cast(2.0 * std::tan(0.5 * Geometry::deg2rad(camera.get_fov())))) : - static_cast(viewport[3]) * 0.0005; #if !ENABLE_GL_SHADERS_ATTRIBUTES auto shader_init_as_lines = [light_intensity](GLShaderProgram &shader) { @@ -3245,9 +3241,9 @@ void GCodeViewer::render_toolpaths() } #if ENABLE_GCODE_VIEWER_STATISTICS - auto render_sequential_range_cap = [this] + auto render_sequential_range_cap = [this, &camera] #else - auto render_sequential_range_cap = [] + auto render_sequential_range_cap = [&camera] #endif // ENABLE_GCODE_VIEWER_STATISTICS (const SequentialRangeCap& cap) { const TBuffer* buffer = cap.buffer; @@ -3258,7 +3254,6 @@ void GCodeViewer::render_toolpaths() shader->start_using(); #if ENABLE_GL_SHADERS_ATTRIBUTES - const Camera& camera = wxGetApp().plater()->get_camera(); const Transform3d& view_matrix = camera.get_view_matrix(); shader->set_uniform("view_model_matrix", view_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix());