From d8f6a9179f096f4c495da269c015be34cd5bcfbb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 28 Apr 2020 15:49:01 +0200 Subject: [PATCH] GCodeViewer -> Use glMultiDrawElements() in place of glDrawElements() to draw all entities --- src/slic3r/GUI/GCodeViewer.cpp | 92 +++++++++++++++++++++++++++++++++- src/slic3r/GUI/GCodeViewer.hpp | 8 +++ 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 64c027a7b..4b2784df9 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -661,6 +661,20 @@ void GCodeViewer::render_toolpaths() const { case GCodeProcessor::EMoveType::Tool_change: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 1.0f, 1.0f, 1.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 1.0f, 1.0f, 1.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -675,10 +689,25 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Color_change: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 1.0f, 0.0f, 0.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 1.0f, 0.0f, 0.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -693,10 +722,25 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Pause_Print: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 0.0f, 1.0f, 0.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 0.0f, 1.0f, 0.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -711,10 +755,25 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Custom_GCode: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 0.0f, 0.0f, 1.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 0.0f, 0.0f, 1.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -729,10 +788,25 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Retract: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 1.0f, 0.0f, 1.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 1.0f, 0.0f, 1.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -747,10 +821,25 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Unretract: { +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + std::array color = { 0.0f, 1.0f, 1.0f }; + set_color(current_program_id, color); + for (const RenderPath& path : buffer.render_paths) + { + glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); + glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size())); + glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); + +#if ENABLE_GCODE_VIEWER_STATISTICS + ++m_statistics.gl_multi_points_calls_count; +#endif // ENABLE_GCODE_VIEWER_STATISTICS + } +#else std::array color = { 0.0f, 1.0f, 1.0f }; set_color(current_program_id, color); for (const Path& path : buffer.paths) { @@ -765,6 +854,7 @@ void GCodeViewer::render_toolpaths() const ++m_statistics.gl_points_calls_count; #endif // ENABLE_GCODE_VIEWER_STATISTICS } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION break; } case GCodeProcessor::EMoveType::Extrude: @@ -1132,7 +1222,7 @@ void GCodeViewer::render_statistics() const ImGui::Separator(); ImGui::PushStyleColor(ImGuiCol_Text, ORANGE); - imgui.text(std::string("Results:")); + imgui.text(std::string("GCodeProcessor results:")); ImGui::PopStyleColor(); ImGui::SameLine(offset); imgui.text(std::to_string(m_statistics.results_size) + " bytes"); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index ec3bfc9a6..0f90be5d7 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -262,7 +262,15 @@ public: void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; } unsigned int get_options_visibility_flags() const; void set_options_visibility_from_flags(unsigned int flags); +#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION + void set_layers_z_range(const std::array& layers_z_range) + { + m_layers_z_range = layers_z_range; + refresh_render_paths(); + } +#else void set_layers_z_range(const std::array& layers_z_range) { m_layers_z_range = layers_z_range; } +#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION bool is_legend_enabled() const { return m_legend_enabled; } void enable_legend(bool enable) { m_legend_enabled = enable; }