From d39d4a91ece352d4e9b987564da31778e612051b Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 6 Aug 2020 16:02:45 +0200 Subject: [PATCH] Move error message hack outside of scene render loop Use std::string_view instead of std::string in more places --- ext/ghoul | 2 +- modules/base/rendering/renderablelabels.cpp | 2 +- modules/globebrowsing/src/tileprovider.cpp | 2 - src/rendering/renderengine.cpp | 42 +++++++++++---------- src/scene/rotation.cpp | 3 -- src/scene/scale.cpp | 3 -- src/scene/scene.cpp | 23 ++++++----- src/scene/translation.cpp | 3 -- 8 files changed, 35 insertions(+), 45 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 601a070c9e..0783e03124 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 601a070c9e3f1c3ee6fd783603fb229579e5d093 +Subproject commit 0783e031240168484dcf7e54c16da44caa60d153 diff --git a/modules/base/rendering/renderablelabels.cpp b/modules/base/rendering/renderablelabels.cpp index 87f64a2a3f..f9f9c4958c 100644 --- a/modules/base/rendering/renderablelabels.cpp +++ b/modules/base/rendering/renderablelabels.cpp @@ -719,7 +719,7 @@ void RenderableLabels::renderLabels(const RenderData& data, ghoul::fontrendering::FontRenderer::defaultProjectionRenderer().render( *_font, transformedPos, - _labelText, + _labelText.value(), textColor, labelInfo ); diff --git a/modules/globebrowsing/src/tileprovider.cpp b/modules/globebrowsing/src/tileprovider.cpp index 707731f83b..0ed15850d7 100644 --- a/modules/globebrowsing/src/tileprovider.cpp +++ b/modules/globebrowsing/src/tileprovider.cpp @@ -1293,8 +1293,6 @@ void reset(TileProvider& tp) { int maxLevel(TileProvider& tp) { - ZoneScoped - switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 3d1d20da25..d354f91796 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -1419,40 +1419,42 @@ void RenderEngine::renderScreenLog() { if (alpha <= 0.f) { break; } - - const std::string lvl = "(" + ghoul::to_string(e->level) + ")"; - const std::string& message = e->message.substr(0, MessageLength); + const std::string_view lvl = ghoul::to_string(e->level); + const std::string_view message = + std::string_view(e->message).substr(0, MessageLength); nr += std::count(message.begin(), message.end(), '\n'); const glm::vec4 white(0.9f, 0.9f, 0.9f, alpha); + std::string str = fmt::format( + "{:<15} {}{}", + e->timeString, + e->category.substr(0, CategoryLength), + e->category.length() > CategoryLength ? "..." : "" + ); + RenderFont( *_fontLog, glm::vec2( 10.f, _fontLog->pointSize() * nr * 2 + fontRes.y * _verticalLogOffset ), - fmt::format( - "{:<15} {}{}", - e->timeString, - e->category.substr(0, CategoryLength), - e->category.length() > CategoryLength ? "..." : "" - ), + str, white ); const glm::vec4 color = [alpha, white](ScreenLog::LogLevel level) { switch (level) { - case ghoul::logging::LogLevel::Debug: - return glm::vec4(0.f, 1.f, 0.f, alpha); - case ghoul::logging::LogLevel::Warning: - return glm::vec4(1.f, 1.f, 0.f, alpha); - case ghoul::logging::LogLevel::Error: - return glm::vec4(1.f, 0.f, 0.f, alpha); - case ghoul::logging::LogLevel::Fatal: - return glm::vec4(0.3f, 0.3f, 0.85f, alpha); - default: - return white; + case ghoul::logging::LogLevel::Debug: + return glm::vec4(0.f, 1.f, 0.f, alpha); + case ghoul::logging::LogLevel::Warning: + return glm::vec4(1.f, 1.f, 0.f, alpha); + case ghoul::logging::LogLevel::Error: + return glm::vec4(1.f, 0.f, 0.f, alpha); + case ghoul::logging::LogLevel::Fatal: + return glm::vec4(0.3f, 0.3f, 0.85f, alpha); + default: + return white; } }(e->level); @@ -1462,7 +1464,7 @@ void RenderEngine::renderScreenLog() { 10 + 30 * _fontLog->pointSize(), _fontLog->pointSize() * nr * 2 + fontRes.y * _verticalLogOffset ), - lvl, + fmt::format("({})", lvl), color ); diff --git a/src/scene/rotation.cpp b/src/scene/rotation.cpp index f3e9be3745..9c26296f87 100644 --- a/src/scene/rotation.cpp +++ b/src/scene/rotation.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include namespace { @@ -96,8 +95,6 @@ const glm::dmat3& Rotation::matrix() const { } void Rotation::update(const UpdateData& data) { - ZoneScoped - if (!_needsUpdate && (data.time.j2000Seconds() == _cachedTime)) { return; } diff --git a/src/scene/scale.cpp b/src/scene/scale.cpp index d2520066e7..2083dcb172 100644 --- a/src/scene/scale.cpp +++ b/src/scene/scale.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include namespace { @@ -91,8 +90,6 @@ glm::dvec3 Scale::scaleValue() const { } void Scale::update(const UpdateData& data) { - ZoneScoped - if (!_needsUpdate && data.time.j2000Seconds() == _cachedTime) { return; } diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 68b2b7f8d3..aa2e434579 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -341,20 +341,19 @@ void Scene::render(const RenderData& data, RendererTasks& tasks) { if (global::callback::webBrowserPerformanceHotfix) { (*global::callback::webBrowserPerformanceHotfix)(); } + } - { - ZoneScopedN("Get Error Hack") + { + ZoneScopedN("Get Error Hack") - // @TODO(abock 2019-08-19) This glGetError call is a hack to prevent the GPU - // thread and the CPU thread from diverging too much, particularly the - // uploading of a lot of textures for the globebrowsing planets can cause a - // hard stuttering effect. Asking for a glGetError after every rendering call - // will force the threads to implicitly synchronize and thus prevent the - // stuttering. The better solution would be to reduce the number of uploads - // per frame, use a staggered buffer, or something else like that preventing a - // large spike in uploads - glGetError(); - } + // @TODO(abock 2019-08-19) This glGetError call is a hack to prevent the GPU + // thread and the CPU thread from diverging too much, particularly the uploading + // of a lot of textures for the globebrowsing planets can cause a hard stuttering + // effect. Asking for a glGetError after every rendering call will force the + // threads to implicitly synchronize and thus prevent the stuttering. The better + // solution would be to reduce the number of uploads per frame, use a staggered + // buffer, or something else like that preventing a large spike in uploads + glGetError(); } } diff --git a/src/scene/translation.cpp b/src/scene/translation.cpp index 7acc7547cc..44fea72bfc 100644 --- a/src/scene/translation.cpp +++ b/src/scene/translation.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include namespace { @@ -84,8 +83,6 @@ bool Translation::initialize() { } void Translation::update(const UpdateData& data) { - ZoneScoped - if (!_needsUpdate && data.time.j2000Seconds() == _cachedTime) { return; }