Added imgui debug dialog for render statistics

This commit is contained in:
Enrico Turri 2019-04-25 11:10:01 +02:00
parent d2d06c9f73
commit d2597482e0
3 changed files with 39 additions and 2 deletions

View file

@ -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
//====================

View file

@ -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;
@ -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<std::chrono::milliseconds>(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;
}
}

View file

@ -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();