Merge branch 'et_gcode_viewer' of https://github.com/prusa3d/PrusaSlicer into et_gcode_viewer
This commit is contained in:
commit
5d1e851218
@ -59,7 +59,6 @@
|
||||
// Enable G-Code viewer
|
||||
#define ENABLE_GCODE_VIEWER (1 && ENABLE_2_3_0_ALPHA1)
|
||||
#define ENABLE_GCODE_VIEWER_DEBUG_OUTPUT (0 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_VIEWER_GL_OPTIMIZATION (1 && ENABLE_GCODE_VIEWER)
|
||||
#define ENABLE_GCODE_VIEWER_STATISTICS (0 && ENABLE_GCODE_VIEWER)
|
||||
|
||||
|
||||
|
@ -214,10 +214,8 @@ void GCodeViewer::refresh(const GCodeProcessor::Result& gcode_result, const std:
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
// update buffers' render paths
|
||||
refresh_render_paths();
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
m_statistics.refresh_time = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start_time).count();
|
||||
@ -533,7 +531,6 @@ void GCodeViewer::load_shells(const Print& print, bool initialized)
|
||||
}
|
||||
}
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
void GCodeViewer::refresh_render_paths() const
|
||||
{
|
||||
auto extrusion_color = [this](const Path& path) {
|
||||
@ -589,35 +586,9 @@ void GCodeViewer::refresh_render_paths() const
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
|
||||
void GCodeViewer::render_toolpaths() const
|
||||
{
|
||||
#if !ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
auto extrusion_color = [this](const Path& path) {
|
||||
std::array<float, 3> color;
|
||||
switch (m_view_type)
|
||||
{
|
||||
case EViewType::FeatureType: { color = Extrusion_Role_Colors[static_cast<unsigned int>(path.role)]; break; }
|
||||
case EViewType::Height: { color = m_extrusions.ranges.height.get_color_at(path.height); break; }
|
||||
case EViewType::Width: { color = m_extrusions.ranges.width.get_color_at(path.width); break; }
|
||||
case EViewType::Feedrate: { color = m_extrusions.ranges.feedrate.get_color_at(path.feedrate); break; }
|
||||
case EViewType::FanSpeed: { color = m_extrusions.ranges.fan_speed.get_color_at(path.fan_speed); break; }
|
||||
case EViewType::VolumetricRate: { color = m_extrusions.ranges.volumetric_rate.get_color_at(path.volumetric_rate); break; }
|
||||
case EViewType::Tool: { color = m_tool_colors[path.extruder_id]; break; }
|
||||
case EViewType::ColorPrint: { color = m_tool_colors[path.cp_color_id]; break; }
|
||||
default: { color = { 1.0f, 1.0f, 1.0f }; break; }
|
||||
}
|
||||
return color;
|
||||
};
|
||||
|
||||
auto travel_color = [this](const Path& path) {
|
||||
return (path.delta_extruder < 0.0f) ? Travel_Colors[2] /* Retract */ :
|
||||
((path.delta_extruder > 0.0f) ? Travel_Colors[1] /* Extrude */ :
|
||||
Travel_Colors[0] /* Move */);
|
||||
};
|
||||
#endif // !ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
|
||||
auto set_color = [](GLint current_program_id, const std::array<float, 3>& color) {
|
||||
if (current_program_id > 0) {
|
||||
GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1;
|
||||
@ -661,7 +632,6 @@ void GCodeViewer::render_toolpaths() const
|
||||
{
|
||||
case GCodeProcessor::EMoveType::Tool_change:
|
||||
{
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
std::array<float, 3> color = { 1.0f, 1.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -674,27 +644,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 1.0f, 1.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++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<float, 3> color = { 1.0f, 0.0f, 0.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -707,27 +660,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 1.0f, 0.0f, 0.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++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<float, 3> color = { 0.0f, 1.0f, 0.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -740,27 +676,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 0.0f, 1.0f, 0.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++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<float, 3> color = { 0.0f, 0.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -773,27 +692,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 0.0f, 0.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++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<float, 3> color = { 1.0f, 0.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -806,27 +708,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 1.0f, 0.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++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<float, 3> color = { 0.0f, 1.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
@ -839,27 +724,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
++m_statistics.gl_multi_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#else
|
||||
std::array<float, 3> color = { 0.0f, 1.0f, 1.0f };
|
||||
set_color(current_program_id, color);
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
|
||||
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.gl_points_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
break;
|
||||
}
|
||||
case GCodeProcessor::EMoveType::Extrude:
|
||||
{
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
{
|
||||
set_color(current_program_id, path.color);
|
||||
@ -869,24 +737,10 @@ void GCodeViewer::render_toolpaths() const
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
}
|
||||
#else
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_visible(path) || !is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
set_color(current_program_id, extrusion_color(path));
|
||||
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.gl_line_strip_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
break;
|
||||
}
|
||||
case GCodeProcessor::EMoveType::Travel:
|
||||
{
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
for (const RenderPath& path : buffer.render_paths)
|
||||
{
|
||||
set_color(current_program_id, path.color);
|
||||
@ -896,19 +750,6 @@ void GCodeViewer::render_toolpaths() const
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
|
||||
}
|
||||
#else
|
||||
for (const Path& path : buffer.paths) {
|
||||
if (!is_in_z_range(path))
|
||||
continue;
|
||||
|
||||
set_color(current_program_id, (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path));
|
||||
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.gl_line_strip_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
}
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1021,10 +862,8 @@ void GCodeViewer::render_legend() const
|
||||
if (role < erCount)
|
||||
{
|
||||
m_extrusions.role_visibility_flags = is_visible(role) ? m_extrusions.role_visibility_flags & ~(1 << role) : m_extrusions.role_visibility_flags | (1 << role);
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
// update buffers' render paths
|
||||
refresh_render_paths();
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
wxGetApp().plater()->get_current_canvas3D()->set_as_dirty();
|
||||
wxGetApp().plater()->update_preview_bottom_toolbar();
|
||||
}
|
||||
@ -1193,19 +1032,6 @@ void GCodeViewer::render_statistics() const
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
||||
imgui.text(std::string("GL_POINTS calls:"));
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SameLine(offset);
|
||||
imgui.text(std::to_string(m_statistics.gl_points_calls_count));
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
||||
imgui.text(std::string("GL_LINE_STRIP calls:"));
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SameLine(offset);
|
||||
imgui.text(std::to_string(m_statistics.gl_line_strip_calls_count));
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ORANGE);
|
||||
imgui.text(std::string("Multi GL_POINTS calls:"));
|
||||
ImGui::PopStyleColor();
|
||||
@ -1217,7 +1043,6 @@ void GCodeViewer::render_statistics() const
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SameLine(offset);
|
||||
imgui.text(std::to_string(m_statistics.gl_multi_line_strip_calls_count));
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
|
@ -61,7 +61,6 @@ class GCodeViewer
|
||||
}
|
||||
};
|
||||
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
// Used to batch the indices needed to render paths
|
||||
struct RenderPath
|
||||
{
|
||||
@ -69,7 +68,6 @@ class GCodeViewer
|
||||
std::vector<unsigned int> sizes;
|
||||
std::vector<size_t> offsets; // use size_t because we need the pointer's size (used in the call glMultiDrawElements())
|
||||
};
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
|
||||
// buffer containing indices data and shader for a specific toolpath type
|
||||
struct IBuffer
|
||||
@ -79,9 +77,7 @@ class GCodeViewer
|
||||
std::vector<unsigned int> data;
|
||||
size_t data_size{ 0 };
|
||||
std::vector<Path> paths;
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
std::vector<RenderPath> render_paths;
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
bool visible{ false };
|
||||
|
||||
void reset();
|
||||
@ -154,12 +150,8 @@ class GCodeViewer
|
||||
{
|
||||
long long load_time{ 0 };
|
||||
long long refresh_time{ 0 };
|
||||
long long gl_points_calls_count{ 0 };
|
||||
long long gl_line_strip_calls_count{ 0 };
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
long long gl_multi_points_calls_count{ 0 };
|
||||
long long gl_multi_line_strip_calls_count{ 0 };
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
long long results_size{ 0 };
|
||||
long long vertices_size{ 0 };
|
||||
long long vertices_gpu_size{ 0 };
|
||||
@ -178,12 +170,8 @@ class GCodeViewer
|
||||
}
|
||||
|
||||
void reset_opengl() {
|
||||
gl_points_calls_count = 0;
|
||||
gl_line_strip_calls_count = 0;
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
gl_multi_points_calls_count = 0;
|
||||
gl_multi_line_strip_calls_count = 0;
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
}
|
||||
|
||||
void reset_sizes() {
|
||||
@ -262,15 +250,11 @@ 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<double, 2>& layers_z_range)
|
||||
{
|
||||
m_layers_z_range = layers_z_range;
|
||||
refresh_render_paths();
|
||||
}
|
||||
#else
|
||||
void set_layers_z_range(const std::array<double, 2>& 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; }
|
||||
@ -279,9 +263,7 @@ private:
|
||||
bool init_shaders();
|
||||
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
|
||||
void load_shells(const Print& print, bool initialized);
|
||||
#if ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
void refresh_render_paths() const;
|
||||
#endif // ENABLE_GCODE_VIEWER_GL_OPTIMIZATION
|
||||
void render_toolpaths() const;
|
||||
void render_shells() const;
|
||||
void render_legend() const;
|
||||
|
Loading…
Reference in New Issue
Block a user