Added PreformanceOverlayUiElement class
This commit is contained in:
101
openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.cpp
Normal file
101
openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "Scene/Ui/PerformanceOverlayUiElement.hpp"
|
||||
#include "Base/FrameMetadata.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include "Host/SystemInfo.hpp"
|
||||
#include "Math/ByteSize.hpp"
|
||||
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OpenVulkano::Scene::UI
|
||||
{
|
||||
namespace
|
||||
{
|
||||
float FloatValuesGetter(void *data, int index)
|
||||
{
|
||||
auto queue = reinterpret_cast<std::deque<float> *>(data);
|
||||
return (*queue)[index];
|
||||
}
|
||||
|
||||
float FPSValuesGetter(void *data, int index)
|
||||
{
|
||||
auto queue = reinterpret_cast<std::deque<float> *>(data);
|
||||
float value = (*queue)[index];
|
||||
if(value != 0)
|
||||
return 1 / value;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
float RamValuesGetter(void *data, int index)
|
||||
{
|
||||
auto queue = reinterpret_cast<std::deque<float> *>(data);
|
||||
float used = (*queue)[index];
|
||||
float max = SystemInfo::GetAppRamMax();
|
||||
float percentage = used / max * 100;
|
||||
return percentage;
|
||||
}
|
||||
}
|
||||
|
||||
void PerformanceOverlayUiElement::UpdateQueues()
|
||||
{
|
||||
m_frameTimes.push_back(static_cast<float>(CURRENT_FRAME.frameTime));
|
||||
while(m_frameTimes.size() > m_frameCount)
|
||||
m_frameTimes.pop_front();
|
||||
|
||||
m_ramUsed.push_back(static_cast<float>(SystemInfo::GetAppRamUsed()));
|
||||
while(m_ramUsed.size() > m_ramUsageCount)
|
||||
m_ramUsed.pop_front();
|
||||
}
|
||||
|
||||
void PerformanceOverlayUiElement::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void PerformanceOverlayUiElement::BeginDraw()
|
||||
{
|
||||
bool alwaysShow = true;
|
||||
ImGui::Begin("Debug Info", &alwaysShow);
|
||||
}
|
||||
|
||||
void PerformanceOverlayUiElement::Draw()
|
||||
{
|
||||
UpdateQueues();
|
||||
|
||||
ImVec2 availableSize = ImGui::GetContentRegionAvail();
|
||||
availableSize.y *= 1/3.;
|
||||
if(ImGui::CollapsingHeader("Frame Times/FPS"))
|
||||
{
|
||||
ImGui::Text("Last Frame Time: %f s", m_frameTimes.back());
|
||||
ImGui::SliderInt("Window Size", &m_frameCount, 10, 1000);
|
||||
ImGui::PlotLines("", &FloatValuesGetter, &m_frameTimes, (int)m_frameTimes.size(), 0, nullptr, FLT_MAX, FLT_MAX, availableSize);
|
||||
|
||||
ImGui::Text("Last FPS: %f", 1 / m_frameTimes.back());
|
||||
ImGui::PlotLines("", &FPSValuesGetter, &m_frameTimes, (int)m_frameTimes.size(), 0, nullptr, FLT_MAX, FLT_MAX, availableSize);
|
||||
}
|
||||
|
||||
if(ImGui::CollapsingHeader("RAM Usage"))
|
||||
{
|
||||
// NOTE(vb) used and max return unexpected values - used is bigger than max... Is it intended to do so?
|
||||
std::string used = Utils::PrettyBytes(SystemInfo::GetAppRamUsed());
|
||||
std::string max = Utils::PrettyBytes(SystemInfo::GetAppRamMax());
|
||||
std::string avail = Utils::PrettyBytes(SystemInfo::GetAppRamAvailable());
|
||||
ImGui::Text("RAM: %s / %s, Free: %s", used.c_str(), max.c_str(), avail.c_str());
|
||||
|
||||
ImGui::SliderInt("Window Size", &m_ramUsageCount, 10, 1000);
|
||||
float scaleMin = 0.01;
|
||||
float scaleMax = 100;
|
||||
ImGui::PlotLines("", &RamValuesGetter, &m_ramUsed, (int)m_ramUsed.size(), 0, nullptr, scaleMin, scaleMax, availableSize);
|
||||
}
|
||||
}
|
||||
|
||||
void PerformanceOverlayUiElement::EndDraw()
|
||||
{
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
31
openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.hpp
Normal file
31
openVulkanoCpp/Scene/UI/PerformanceOverlayUiElement.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Scene/Ui/Ui.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace OpenVulkano::Scene::UI
|
||||
{
|
||||
class PerformanceOverlayUiElement : public Ui
|
||||
{
|
||||
int m_frameCount = 200;
|
||||
std::deque<float> m_frameTimes;
|
||||
|
||||
int m_ramUsageCount = 200;
|
||||
std::deque<float> m_ramUsed;
|
||||
|
||||
void UpdateQueues();
|
||||
|
||||
protected:
|
||||
void Init() override;
|
||||
void BeginDraw() override;
|
||||
void Draw() override;
|
||||
void EndDraw() override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user