From 3ca6278ac9bf53f9521bee15b7989b1e97bd652a Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 17 Sep 2020 08:59:36 +0200 Subject: [PATCH] Refactoring in GCodeViewer initialization --- src/slic3r/GUI/GCodeViewer.cpp | 28 +++++----------------------- src/slic3r/GUI/GCodeViewer.hpp | 1 - 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 16d929122..16bb27157 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -287,6 +287,8 @@ const std::vector GCodeViewer::Range_Colors {{ bool GCodeViewer::init() { + bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20); + for (size_t i = 0; i < m_buffers.size(); ++i) { TBuffer& buffer = m_buffers[i]; @@ -302,18 +304,21 @@ bool GCodeViewer::init() { buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point; buffer.vertices.format = VBuffer::EFormat::Position; + buffer.shader = is_glsl_120 ? "options_120" : "options_110"; break; } 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; } } @@ -321,7 +326,6 @@ bool GCodeViewer::init() set_toolpath_move_type_visible(EMoveType::Extrude, true); m_sequential_view.marker.init(); - init_shaders(); std::array point_sizes; ::glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_sizes.data()); @@ -847,28 +851,6 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const fclose(fp); } -void GCodeViewer::init_shaders() -{ - unsigned char begin_id = buffer_id(EMoveType::Retract); - unsigned char end_id = buffer_id(EMoveType::Count); - - bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20); - for (unsigned char i = begin_id; i < end_id; ++i) { - switch (buffer_type(i)) - { - case EMoveType::Tool_change: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Color_change: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Pause_Print: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Custom_GCode: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Retract: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Unretract: { m_buffers[i].shader = is_glsl_120 ? "options_120" : "options_110"; break; } - case EMoveType::Extrude: { m_buffers[i].shader = "gouraud_light"; break; } - case EMoveType::Travel: { m_buffers[i].shader = "toolpaths_lines"; break; } - default: { break; } - } - } -} - void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result) { #if ENABLE_GCODE_VIEWER_STATISTICS diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 73c4ad7b2..8c5d8b743 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -459,7 +459,6 @@ public: void export_toolpaths_to_obj(const char* filename) const; private: - void init_shaders(); void load_toolpaths(const GCodeProcessor::Result& gcode_result); void load_shells(const Print& print, bool initialized); void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;