diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index ea3d87888..45f04b1df 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 0 //==================== diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 43e91064f..50fdb70bf 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -52,6 +52,9 @@ #include <float.h> #include <algorithm> #include <cmath> +#if ENABLE_RENDER_STATISTICS +#include <chrono> +#endif // ENABLE_RENDER_STATISTICS static const float TRACKBALLSIZE = 0.8f; static const float GROUND_Z = -0.02f; @@ -1565,6 +1568,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 @@ -1643,9 +1650,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<std::chrono::milliseconds>(end_time - start_time).count(); +#endif // ENABLE_RENDER_STATISTICS } void GLCanvas3D::select_all() diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index e81d46f11..f24a6717b 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -319,7 +319,6 @@ class GLCanvas3D } }; -private: struct SlaCap { struct Triangles @@ -392,6 +391,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 + wxGLCanvas* m_canvas; wxGLContext* m_context; #if ENABLE_RETINA_GL @@ -447,6 +455,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();