Move the statistics and frame info rendering from the RenderEngine into the debugging module (closes #1248)

This commit is contained in:
Alexander Bock
2024-07-17 13:17:03 +02:00
parent babbb4f97c
commit 6337b8e5aa
4 changed files with 105 additions and 75 deletions

View File

@@ -26,7 +26,10 @@
#include <modules/debugging/rendering/renderabledebugplane.h>
#include <openspace/documentation/documentation.h>
#include <openspace/engine/configuration.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/engine/windowdelegate.h>
#include <openspace/navigation/navigationhandler.h>
#include <openspace/navigation/path.h>
#include <openspace/navigation/pathnavigator.h>
@@ -38,15 +41,99 @@
#include <openspace/scripting/lualibrary.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/font/fontmanager.h>
#include <ghoul/font/fontrenderer.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/templatefactory.h>
#include "debuggingmodule_lua.inl"
namespace {
constexpr std::string_view KeyFontMono = "Mono";
constexpr openspace::properties::Property::PropertyInfo ShowStatisticsInfo = {
"ShowStatistics",
"Show Statistics",
"Show updating, rendering, and network statistics on all rendering nodes.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo StatisticsScaleInfo = {
"StatisticsScale",
"Statistics Scale",
"This value is scaling the statatistics window by the provided amount. For flat "
"projections this is rarely necessary, but it is important when using a setup "
"where the cornders of the image are masked out.",
openspace::properties::Property::Visibility::AdvancedUser
};
constexpr openspace::properties::Property::PropertyInfo ShowFrameNumberInfo = {
"ShowFrameInformation",
"Show Frame Information",
"If this value is enabled, the current frame number and frame times are rendered "
"into the window.",
openspace::properties::Property::Visibility::AdvancedUser
};
} // namespace
namespace openspace {
DebuggingModule::DebuggingModule() : OpenSpaceModule(Name) {}
DebuggingModule::DebuggingModule()
: OpenSpaceModule(Name)
, _showStatistics(ShowStatisticsInfo, false)
, _statisticsScale(StatisticsScaleInfo, 1.f, 0.f, 1.f)
, _showFrameInformation(ShowFrameNumberInfo, false)
{
_showStatistics.onChange([this]() {
global::windowDelegate->showStatistics(_showStatistics);
// We need to reset the scale as it is not updated when the statistics window is
// not currently shown
global::windowDelegate->setStatisticsGraphScale(_statisticsScale);
});
addProperty(_showStatistics);
_statisticsScale.onChange([this]() {
global::windowDelegate->setStatisticsGraphScale(_statisticsScale);
});
addProperty(_statisticsScale);
addProperty(_showFrameInformation);
global::callback::render->push_back([this]() {
if (_showFrameInformation) {
ZoneScopedN("Show Frame Information");
WindowDelegate* del = global::windowDelegate;
glm::vec2 penPosition = glm::vec2(
global::renderEngine->fontResolution().x / 2 - 50,
global::renderEngine->fontResolution().y / 3
);
std::string fn = std::to_string(global::renderEngine->frameNumber());
const WindowDelegate::Frustum frustum = del->frustumMode();
std::string fr = [](WindowDelegate::Frustum f) -> std::string {
switch (f) {
case WindowDelegate::Frustum::Mono: return "";
case WindowDelegate::Frustum::LeftEye: return "(left)";
case WindowDelegate::Frustum::RightEye: return "(right)";
default: throw ghoul::MissingCaseException();
}
}(frustum);
std::string sgFn = std::to_string(del->swapGroupFrameNumber());
std::string dt = std::to_string(del->deltaTime());
std::string avgDt = std::to_string(del->averageDeltaTime());
const std::string res = std::format(
"Frame: {} {}\nSwap group frame: {}\nDt: {}\nAvg Dt: {}",
fn, fr, sgFn, dt, avgDt
);
RenderFont(*_fontFrameInfo, penPosition, res);
}
});
}
void DebuggingModule::internalInitialize(const ghoul::Dictionary&) {
ghoul::TemplateFactory<Renderable>* fRenderable =
@@ -56,6 +143,11 @@ void DebuggingModule::internalInitialize(const ghoul::Dictionary&) {
fRenderable->registerClass<RenderableDebugPlane>("RenderableDebugPlane");
}
void DebuggingModule::internalInitializeGL() {
const Configuration::FontSizes fontSize = global::configuration->fontSize;
_fontFrameInfo = global::fontManager->font(KeyFontMono, fontSize.frameInfo);
}
std::vector<documentation::Documentation> DebuggingModule::documentations() const {
return {
RenderableDebugPlane::Documentation()

View File

@@ -27,6 +27,10 @@
#include <openspace/util/openspacemodule.h>
#include <openspace/properties/scalar/boolproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <ghoul/font/font.h>
namespace openspace {
class DebuggingModule : public OpenSpaceModule {
@@ -41,6 +45,14 @@ public:
protected:
void internalInitialize(const ghoul::Dictionary&) override;
void internalInitializeGL() override;
private:
properties::BoolProperty _showStatistics;
properties::FloatProperty _statisticsScale;
properties::BoolProperty _showFrameInformation;
std::shared_ptr<ghoul::fontrendering::Font> _fontFrameInfo;
};
} // namespace openspace