Finality Engine
Loading...
Searching...
No Matches
ViewportStatistics.h
Go to the documentation of this file.
1
6#pragma once
7#include <Core/RenderTarget.h>
8#include <sstream>
9#include <iomanip>
10#include <imgui.h>
11
12namespace FINALITY
13{
14 inline std::string FormatViewportStatistics(const RenderTarget& target)
15 {
16 const auto& s = target.Statistics;
17 std::ostringstream text; text << std::fixed << std::setprecision(2);
18 text << "Resolution: " << target.Width << " x " << target.Height << '\n';
19 text << "Objects: " << s.Visible << " visible / " << s.Candidates << " candidates (" << s.Culled << " culled)\n";
20 text << "Batches: " << s.DrawCalls << " Instances: " << s.Instances << '\n';
21 text << "Culled: frustum " << s.FrustumCulled << " LOD " << s.LODCulled << " occlusion " << s.OcclusionCulled << '\n';
22 text << "LOD groups: " << s.LODGroups << " transitions: " << s.LODTransitions << '\n';
23 text << "CPU occlusion: " << s.OcclusionMS << " ms occluder triangles: " << s.OccluderTriangles << '\n';
24 text << "Triangles: " << s.Triangles << " Vertices: " << s.Vertices << '\n';
25 text << "Pipeline binds: " << s.PipelineBinds << " Descriptor binds: " << s.DescriptorBinds << '\n';
26 text << "CPU visibility: " << s.VisibilityMS << " ms\nCPU recording: " << s.RecordMS << " ms\nGPU view: ";
27 if (s.GpuValid) text << s.GpuMS << " ms (delayed sample)"; else text << "pending / unsupported";
28 return text.str();
29 }
30
31 inline void DrawViewportStatsOverlay(const RenderTarget& target, const ImVec2& minimum, const ImVec2& maximum)
32 {
33 const auto text = FormatViewportStatistics(target);
34 const auto size = ImGui::CalcTextSize(text.c_str());
35 const ImVec2 origin{std::max(minimum.x+8,maximum.x-size.x-20),minimum.y+8};
36 auto* draw = ImGui::GetWindowDrawList();
37 draw->PushClipRect(minimum,maximum,true);
38 auto background = ImGui::GetStyleColorVec4(ImGuiCol_PopupBg); background.w = 0.94f;
39 draw->AddRectFilled(origin,{origin.x+size.x+12,origin.y+size.y+12},ImGui::GetColorU32(background),4);
40 draw->AddText({origin.x+6,origin.y+6},ImGui::GetColorU32(ImGuiCol_Text),text.c_str());
41 draw->PopClipRect();
42 }
43}
void DrawViewportStatsOverlay(const RenderTarget &target, const ImVec2 &minimum, const ImVec2 &maximum)
std::string FormatViewportStatistics(const RenderTarget &target)
RenderStatistics Statistics