From 6337b8e5aabb36e4449d5191346db597050b5dd3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Wed, 17 Jul 2024 13:17:03 +0200 Subject: [PATCH] Move the statistics and frame info rendering from the RenderEngine into the debugging module (closes #1248) --- include/openspace/rendering/renderengine.h | 4 - modules/debugging/debuggingmodule.cpp | 94 +++++++++++++++++++++- modules/debugging/debuggingmodule.h | 12 +++ src/rendering/renderengine.cpp | 70 ---------------- 4 files changed, 105 insertions(+), 75 deletions(-) diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index 032efebf69..6047fbc961 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -186,10 +186,7 @@ private: properties::IntListProperty _screenshotWindowIds; properties::BoolProperty _applyWarping; - properties::BoolProperty _showStatistics; - properties::FloatProperty _statisticsScale; properties::BoolProperty _screenshotUseDate; - properties::BoolProperty _showFrameInformation; properties::BoolProperty _disableMasterRendering; properties::FloatProperty _globalBlackOutFactor; @@ -218,7 +215,6 @@ private: std::vector _programs; - std::shared_ptr _fontFrameInfo; std::shared_ptr _fontCameraInfo; std::shared_ptr _fontVersionInfo; std::shared_ptr _fontShutdown; diff --git a/modules/debugging/debuggingmodule.cpp b/modules/debugging/debuggingmodule.cpp index 93add8f04f..5781dc60f2 100644 --- a/modules/debugging/debuggingmodule.cpp +++ b/modules/debugging/debuggingmodule.cpp @@ -26,7 +26,10 @@ #include #include +#include #include +#include +#include #include #include #include @@ -38,15 +41,99 @@ #include #include #include +#include +#include #include #include #include #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* fRenderable = @@ -56,6 +143,11 @@ void DebuggingModule::internalInitialize(const ghoul::Dictionary&) { fRenderable->registerClass("RenderableDebugPlane"); } +void DebuggingModule::internalInitializeGL() { + const Configuration::FontSizes fontSize = global::configuration->fontSize; + _fontFrameInfo = global::fontManager->font(KeyFontMono, fontSize.frameInfo); +} + std::vector DebuggingModule::documentations() const { return { RenderableDebugPlane::Documentation() diff --git a/modules/debugging/debuggingmodule.h b/modules/debugging/debuggingmodule.h index 4dcc34d075..ccd7439d88 100644 --- a/modules/debugging/debuggingmodule.h +++ b/modules/debugging/debuggingmodule.h @@ -27,6 +27,10 @@ #include +#include +#include +#include + 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 _fontFrameInfo; }; } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index db8bf2ea75..60d8b580d2 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -139,22 +139,6 @@ namespace { openspace::properties::Property::Visibility::AdvancedUser }; - 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 ScreenshotUseDateInfo = { "ScreenshotUseDate", "Screenshot Folder uses Date", @@ -163,14 +147,6 @@ namespace { 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 - }; - constexpr openspace::properties::Property::PropertyInfo DisableMasterInfo = { "DisableMasterRendering", "Disable Master Rendering", @@ -321,10 +297,7 @@ RenderEngine::RenderEngine() , _showCameraInfo(ShowCameraInfo, true) , _screenshotWindowIds(ScreenshotWindowIdsInfo) , _applyWarping(ApplyWarpingInfo, false) - , _showStatistics(ShowStatisticsInfo, false) - , _statisticsScale(StatisticsScaleInfo, 1.f, 0.f, 1.f) , _screenshotUseDate(ScreenshotUseDateInfo, false) - , _showFrameInformation(ShowFrameNumberInfo, false) , _disableMasterRendering(DisableMasterInfo, false) , _globalBlackOutFactor(GlobalBlackoutFactorInfo, 1.f, 0.f, 1.f) , _applyBlackoutToMaster(ApplyBlackoutToMasterInfo, true) @@ -395,19 +368,6 @@ RenderEngine::RenderEngine() addProperty(_screenshotWindowIds); addProperty(_applyWarping); - _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); - _screenshotUseDate.onChange([this]() { // If there is no screenshot folder, don't bother with handling the change if (!FileSys.hasRegisteredToken("${STARTUP_SCREENSHOT}")) { @@ -453,7 +413,6 @@ RenderEngine::RenderEngine() }); addProperty(_horizFieldOfView); - addProperty(_showFrameInformation); addProperty(_framerateLimit); addProperty(_globalRotation); @@ -540,7 +499,6 @@ void RenderEngine::initializeGL() { { ZoneScopedN("Fonts"); TracyGpuZone("Fonts"); - _fontFrameInfo = global::fontManager->font(KeyFontMono, fontSize.frameInfo); _fontShutdown = global::fontManager->font(KeyFontMono, fontSize.shutdown); _fontCameraInfo = global::fontManager->font(KeyFontMono, fontSize.cameraInfo); _fontVersionInfo = global::fontManager->font(KeyFontMono, fontSize.versionInfo); @@ -721,35 +679,7 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat (*global::callback::webBrowserPerformanceHotfix)(); } - if (_showFrameInformation) { - ZoneScopedN("Show Frame Information"); - glm::vec2 penPosition = glm::vec2( - fontResolution().x / 2 - 50, - fontResolution().y / 3 - ); - - std::string fn = std::to_string(_frameNumber); - const WindowDelegate::Frustum frustum = global::windowDelegate->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(global::windowDelegate->swapGroupFrameNumber()); - std::string dt = std::to_string(global::windowDelegate->deltaTime()); - std::string avgDt = std::to_string(global::windowDelegate->averageDeltaTime()); - - const std::string res = std::format( - "Frame: {} {}\nSwap group frame: {}\nDt: {}\nAvg Dt: {}", - fn, fr, sgFn, dt, avgDt - ); - RenderFont(*_fontFrameInfo, penPosition, res); - } if (renderingEnabled && !delegate.isGuiWindow()) { ZoneScopedN("Render ScreenSpace Renderable");