From d2597482e0233e33c1e09dae927049b53dc528f4 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Thu, 25 Apr 2019 11:10:01 +0200 Subject: [PATCH] Added imgui debug dialog for render statistics --- src/libslic3r/Technologies.hpp | 2 ++ src/slic3r/GUI/GLCanvas3D.cpp | 25 ++++++++++++++++++++++++- src/slic3r/GUI/GLCanvas3D.hpp | 14 +++++++++++++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index ea3d87888..afd8ee026 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -11,6 +11,8 @@ #define ENABLE_SELECTION_DEBUG_OUTPUT 0 // Renders a small sphere in the center of the bounding box of the current selection when no gizmo is active #define ENABLE_RENDER_SELECTION_CENTER 0 +// Shows an imgui dialog with render related data +#define ENABLE_RENDER_STATISTICS 1 //==================== diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 9798efecb..d58b40fdf 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -52,6 +52,9 @@ #include #include #include +#if ENABLE_RENDER_STATISTICS +#include +#endif // ENABLE_RENDER_STATISTICS static const float TRACKBALLSIZE = 0.8f; static const float GROUND_Z = -0.02f; @@ -1581,6 +1584,10 @@ void GLCanvas3D::render() if (!_set_current() || !_3DScene::init(m_canvas)) return; +#if ENABLE_RENDER_STATISTICS + auto start_time = std::chrono::high_resolution_clock::now(); +#endif // ENABLE_RENDER_STATISTICS + if (m_bed.get_shape().empty()) { // this happens at startup when no data is still saved under <>\AppData\Roaming\Slic3rPE @@ -1666,9 +1673,26 @@ void GLCanvas3D::render() if ((m_layers_editing.last_object_id >= 0) && (m_layers_editing.object_max_z() > 0.0f)) m_layers_editing.render_overlay(*this); +#if ENABLE_RENDER_STATISTICS + ImGuiWrapper& imgui = *wxGetApp().imgui(); + imgui.set_next_window_bg_alpha(0.5f); + imgui.begin(std::string("Render statistics"), ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); + imgui.text("Last frame: "); + ImGui::SameLine(); + imgui.text(std::to_string(m_render_stats.last_frame)); + ImGui::SameLine(); + imgui.text(" ms"); + imgui.end(); +#endif // ENABLE_RENDER_STATISTICS + wxGetApp().imgui()->render(); m_canvas->SwapBuffers(); + +#if ENABLE_RENDER_STATISTICS + auto end_time = std::chrono::high_resolution_clock::now(); + m_render_stats.last_frame = std::chrono::duration_cast(end_time - start_time).count(); +#endif // ENABLE_RENDER_STATISTICS } void GLCanvas3D::select_all() @@ -2751,7 +2775,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_regenerate_volumes = false; m_selection.translate(cur_pos - m_mouse.drag.start_position_3D); wxGetApp().obj_manipul()->update_settings_value(m_selection); - m_dirty = true; } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index bae9f0b5e..9e2d87bdb 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -319,7 +319,6 @@ class GLCanvas3D } }; -private: struct SlaCap { struct Triangles @@ -399,6 +398,15 @@ private: void render(const GLCanvas3D& canvas) const; }; +#if ENABLE_RENDER_STATISTICS + struct RenderStats + { + long long last_frame; + + RenderStats() : last_frame(0) {} + }; +#endif // ENABLE_RENDER_STATISTICS + public: enum ECursorType : unsigned char { @@ -464,6 +472,10 @@ private: GCodePreviewVolumeIndex m_gcode_preview_volume_index; +#if ENABLE_RENDER_STATISTICS + RenderStats m_render_stats; +#endif // ENABLE_RENDER_STATISTICS + public: GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar& view_toolbar); ~GLCanvas3D();