From 1df91ea93008eacc43b24a6b763bea482b2ae81b Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 29 Sep 2021 13:34:30 +0200 Subject: [PATCH] Follow-up of 67e519d3ab8f56d9ab5d6759d1b92ee9131ead8c - Use a platform-indipendent fix --- src/slic3r/GUI/GCodeViewer.cpp | 126 +++++++++++++++++++++++---------- src/slic3r/GUI/GCodeViewer.hpp | 4 ++ src/slic3r/GUI/GLCanvas3D.cpp | 5 ++ src/slic3r/GUI/GLCanvas3D.hpp | 3 + src/slic3r/GUI/Plater.cpp | 4 +- 5 files changed, 100 insertions(+), 42 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index e8a737957..4a3849af8 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -573,6 +573,89 @@ GCodeViewer::GCodeViewer() // m_sequential_view.skip_invisible_moves = true; } +#if ENABLE_SEAMS_USING_MODELS +void GCodeViewer::init() +{ + if (m_gl_data_initialized) + return; + + // initializes opengl data of TBuffers + for (size_t i = 0; i < m_buffers.size(); ++i) { + TBuffer& buffer = m_buffers[i]; + EMoveType type = buffer_type(i); + switch (type) + { + default: { break; } + case EMoveType::Tool_change: + case EMoveType::Color_change: + case EMoveType::Pause_Print: + case EMoveType::Custom_GCode: + case EMoveType::Retract: + case EMoveType::Unretract: + case EMoveType::Seam: { +#if ENABLE_SEAMS_USING_BATCHED_MODELS + if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::InstancedModel; + buffer.shader = "gouraud_light_instanced"; + buffer.model.model.init_from(diamond(16)); + buffer.model.color = option_color(type); + buffer.model.instances.format = InstanceVBuffer::EFormat::InstancedModel; + } + else { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::BatchedModel; + buffer.vertices.format = VBuffer::EFormat::PositionNormal3; + buffer.shader = "gouraud_light"; + + buffer.model.data = diamond(16); + buffer.model.color = option_color(type); + buffer.model.instances.format = InstanceVBuffer::EFormat::BatchedModel; + } + break; +#else + if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Model; + buffer.shader = "gouraud_light_instanced"; + buffer.model.model.init_from(diamond(16)); + buffer.model.color = option_color(type); + } + else { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; + buffer.vertices.format = VBuffer::EFormat::Position; + buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; + } + break; +#endif // ENABLE_SEAMS_USING_BATCHED_MODELS + } + case EMoveType::Wipe: + case EMoveType::Extrude: { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; + buffer.vertices.format = VBuffer::EFormat::PositionNormal3; + buffer.shader = "gouraud_light"; + break; + } + case EMoveType::Travel: { + buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; + buffer.vertices.format = VBuffer::EFormat::PositionNormal1; + buffer.shader = "toolpaths_lines"; + break; + } + } + + set_toolpath_move_type_visible(EMoveType::Extrude, true); + } + + // initializes tool marker + m_sequential_view.marker.init(); + + // initializes point sizes + std::array point_sizes; + ::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data()); + m_detected_point_sizes = { static_cast(point_sizes[0]), static_cast(point_sizes[1]) }; + + m_gl_data_initialized = true; +} +#endif // ENABLE_SEAMS_USING_MODELS + void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized) { // avoid processing if called with the same gcode_result @@ -756,6 +839,7 @@ void GCodeViewer::reset() void GCodeViewer::render() { +#if !ENABLE_SEAMS_USING_MODELS auto init_gl_data = [this]() { // initializes opengl data of TBuffers for (size_t i = 0; i < m_buffers.size(); ++i) { @@ -771,26 +855,6 @@ void GCodeViewer::render() case EMoveType::Retract: case EMoveType::Unretract: case EMoveType::Seam: { -#if ENABLE_SEAMS_USING_MODELS -#if ENABLE_SEAMS_USING_BATCHED_MODELS - if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::InstancedModel; - buffer.shader = "gouraud_light_instanced"; - buffer.model.model.init_from(diamond(16)); - buffer.model.color = option_color(type); - buffer.model.instances.format = InstanceVBuffer::EFormat::InstancedModel; - } - else { - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::BatchedModel; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; - buffer.shader = "gouraud_light"; - - buffer.model.data = diamond(16); - buffer.model.color = option_color(type); - buffer.model.instances.format = InstanceVBuffer::EFormat::BatchedModel; - } - break; -#else if (wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Model; buffer.shader = "gouraud_light_instanced"; @@ -803,36 +867,17 @@ void GCodeViewer::render() buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; } break; -#endif // ENABLE_SEAMS_USING_BATCHED_MODELS -#else - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; - buffer.vertices.format = VBuffer::EFormat::Position; - buffer.shader = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20) ? "options_120" : "options_110"; - break; -#endif // ENABLE_SEAMS_USING_MODELS } case EMoveType::Wipe: case EMoveType::Extrude: { -#if ENABLE_SEAMS_USING_MODELS - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle; - buffer.vertices.format = VBuffer::EFormat::PositionNormal3; -#endif // ENABLE_SEAMS_USING_MODELS buffer.shader = "gouraud_light"; break; } case EMoveType::Travel: { -#if ENABLE_SEAMS_USING_MODELS - buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line; - buffer.vertices.format = VBuffer::EFormat::PositionNormal1; -#endif // ENABLE_SEAMS_USING_MODELS buffer.shader = "toolpaths_lines"; break; } } - -#if ENABLE_SEAMS_USING_MODELS - set_toolpath_move_type_visible(EMoveType::Extrude, true); -#endif // ENABLE_SEAMS_USING_MODELS } // initializes tool marker @@ -844,6 +889,7 @@ void GCodeViewer::render() m_detected_point_sizes = { static_cast(point_sizes[0]), static_cast(point_sizes[1]) }; m_gl_data_initialized = true; }; +#endif // !ENABLE_SEAMS_USING_MODELS #if ENABLE_GCODE_VIEWER_STATISTICS m_statistics.reset_opengl(); @@ -852,10 +898,12 @@ void GCodeViewer::render() #endif // ENABLE_SEAMS_USING_MODELS #endif // ENABLE_GCODE_VIEWER_STATISTICS +#if !ENABLE_SEAMS_USING_MODELS // OpenGL data must be initialized after the glContext has been created. // This is ensured when this method is called by GLCanvas3D::_render_gcode(). if (!m_gl_data_initialized) init_gl_data(); +#endif // !ENABLE_SEAMS_USING_MODELS if (m_roles.empty()) return; diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 6c164f5e8..1b5a53f9d 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -808,6 +808,10 @@ public: GCodeViewer(); ~GCodeViewer() { reset(); } +#if ENABLE_SEAMS_USING_MODELS + void init(); +#endif // ENABLE_SEAMS_USING_MODELS + // extract rendering data from the given parameters void load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized); // recalculate ranges in dependence of what is visible and sets tool/print colors diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 5953c5660..869f48a01 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1400,6 +1400,11 @@ void GLCanvas3D::render() if (!is_initialized() && !init()) return; +#if ENABLE_SEAMS_USING_MODELS + if (!m_main_toolbar.is_enabled()) + m_gcode_viewer.init(); +#endif // ENABLE_SEAMS_USING_MODELS + if (wxGetApp().plater()->get_bed().get_shape().empty()) { // this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE post_event(SimpleEvent(EVT_GLCANVAS_UPDATE_BED_SHAPE)); diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index e03c4a71d..86ec5634f 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -617,6 +617,9 @@ public: void reset_volumes(); ModelInstanceEPrintVolumeState check_volumes_outside_state() const; +#if ENABLE_SEAMS_USING_MODELS + void init_gcode_viewer() { m_gcode_viewer.init(); } +#endif // ENABLE_SEAMS_USING_MODELS void reset_gcode_toolpaths() { m_gcode_viewer.reset(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6cef0933a..87b83ec24 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3801,9 +3801,7 @@ void Plater::priv::set_current_panel(wxPanel* panel) bool model_fits = view3D->get_canvas3d()->check_volumes_outside_state() != ModelInstancePVS_Partly_Outside; if (!model.objects.empty() && !export_in_progress && model_fits) { #if ENABLE_SEAMS_USING_MODELS - // the following call is needed to ensure that GCodeViewer buffers are initialized - // before calling reslice() when background processing is active - preview->SetFocusFromKbd(); + preview->get_canvas3d()->init_gcode_viewer(); #endif // ENABLE_SEAMS_USING_MODELS q->reslice(); }