From fcaafe52b40a30ebd8f04f51b354789f0e2592c4 Mon Sep 17 00:00:00 2001 From: Andrew Copland Date: Wed, 20 Nov 2024 16:34:51 +0000 Subject: [PATCH] Functioning Terrain tab in perfinfo with debug toggles --- src/GeoSphere.cpp | 35 ++++++++++++++++++++++++++++++----- src/GeoSphere.h | 10 ++++++++++ src/pigui/PerfInfo.cpp | 26 +++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/GeoSphere.cpp b/src/GeoSphere.cpp index fa3a46ec20..cccba4a357 100644 --- a/src/GeoSphere.cpp +++ b/src/GeoSphere.cpp @@ -39,6 +39,7 @@ static const int detail_edgeLen[5] = { static const double gs_targetPatchTriLength(100.0); static std::vector s_allGeospheres; +static Uint32 s_debugFlags = GeoSphere::DebugFlags::DEBUG_NONE; void GeoSphere::InitGeoSphere() { @@ -127,6 +128,18 @@ bool GeoSphere::OnAddSingleSplitResult(const SystemPath &path, SSingleSplitResul return false; } +//static +void GeoSphere::SetDebugFlags(Uint32 flags) +{ + s_debugFlags = flags; +} + +//static +Uint32 GeoSphere::GetDebugFlags() +{ + return s_debugFlags; +} + void GeoSphere::Reset() { { @@ -195,6 +208,12 @@ GeoSphere::GeoSphere(const SystemBody *body) : m_visiblePatches.reserve(1024); + if (Pi::config->Int("SortGeoPatches") == 0) { + SetDebugFlags(GetDebugFlags() & ~DebugFlags::DEBUG_SORTGEOPATCHES); + } else { + SetDebugFlags(GetDebugFlags() | DebugFlags::DEBUG_SORTGEOPATCHES); + } + //SetUpMaterials is not called until first Render since light count is zero :) } @@ -443,11 +462,10 @@ void GeoSphere::Render(Graphics::Renderer *renderer, const matrix4x4d &modelView renderer->SetTransform(matrix4x4f(modelView)); - if (Pi::config->Int("SortGeoPatches") == 0) { - for (int i = 0; i < NUM_PATCHES; i++) { - m_patches[i]->Render(renderer, campos, modelView, frustum); - } - } else { + if (s_debugFlags & GeoSphere::DebugFlags::DEBUG_WIREFRAME) + renderer->SetWireFrameMode(true); + + if (s_debugFlags & GeoSphere::DebugFlags::DEBUG_SORTGEOPATCHES) { // Gather the patches that could be rendered for (int i = 0; i < NUM_PATCHES; i++) { m_patches[i]->GatherRenderablePatches(m_visiblePatches, renderer, campos, frustum); @@ -468,8 +486,15 @@ void GeoSphere::Render(Graphics::Renderer *renderer, const matrix4x4d &modelView // must clear this after each render otherwise it just accumulates every patch ever drawn! m_visiblePatches.clear(); + } else { + for (int i = 0; i < NUM_PATCHES; i++) { + m_patches[i]->Render(renderer, campos, modelView, frustum); + } } + if (s_debugFlags & GeoSphere::DebugFlags::DEBUG_WIREFRAME) + renderer->SetWireFrameMode(false); + renderer->SetAmbientColor(oldAmbient); renderer->GetStats().AddToStatCount(Graphics::Stats::STAT_PLANETS, 1); diff --git a/src/GeoSphere.h b/src/GeoSphere.h index 0f3ad03a8c..b74b459a70 100644 --- a/src/GeoSphere.h +++ b/src/GeoSphere.h @@ -57,6 +57,16 @@ class GeoSphere : public BaseSphere { static void OnChangeGeoSphereDetailLevel(); static bool OnAddQuadSplitResult(const SystemPath &path, SQuadSplitResult *res); static bool OnAddSingleSplitResult(const SystemPath &path, SSingleSplitResult *res); + + enum DebugFlags : uint32_t { // + DEBUG_NONE = 0x0, + DEBUG_SORTGEOPATCHES = 0x1, + DEBUG_WIREFRAME = 0x2, + DEBUG_FACELABELS = 0x4 + }; + static void SetDebugFlags(Uint32 flags); + static Uint32 GetDebugFlags(); + // in sbody radii virtual double GetMaxFeatureHeight() const override final { return m_terrain->GetMaxHeight(); } diff --git a/src/pigui/PerfInfo.cpp b/src/pigui/PerfInfo.cpp index 6cf427d317..fe9799fbdb 100644 --- a/src/pigui/PerfInfo.cpp +++ b/src/pigui/PerfInfo.cpp @@ -5,6 +5,7 @@ #include "Frame.h" #include "Game.h" #include "GameConfig.h" +#include "GeoSphere.h" #include "Input.h" #include "LuaPiGui.h" #include "Pi.h" @@ -629,10 +630,29 @@ void PerfInfo::DrawInputDebug() void PiGui::PerfInfo::DrawTerrainDebug() { - bool sortGeoPatches = Pi::config->Int("SortGeoPatches") == 1; - if (ImGui::Checkbox("Distance Sort GeoPatches", &sortGeoPatches)) { - Pi::config->SetInt("SortGeoPatches", sortGeoPatches ? 1 : 0); + ImGui::SeparatorText("Terrain Debug"); + + using Flags = GeoSphere::DebugFlags; + uint32_t debugFlags = GeoSphere::GetDebugFlags(); + bool showSort = debugFlags & Flags::DEBUG_SORTGEOPATCHES; + bool showWire = debugFlags & Flags::DEBUG_WIREFRAME; + //bool showFace = debugFlags & Flags::DEBUG_FACELABELS; + + bool changed = ImGui::Checkbox("Distance Sort GeoPatches", &showSort); + changed |= ImGui::Checkbox("Show Wireframe", &showWire); + //changed |= ImGui::Checkbox("Show Face IDs", &showFace); + + /* clang-format off */ + if (changed) { + debugFlags = (showSort ? Flags::DEBUG_SORTGEOPATCHES : 0) + | (showWire ? Flags::DEBUG_WIREFRAME : 0); + //| (showFace ? Flags::DEBUG_FACELABELS : 0); + GeoSphere::SetDebugFlags(debugFlags); + Pi::config->SetInt("SortGeoPatches", showSort ? 1 : 0); + + Pi::config->Save(); } + /* clang-format on */ } void PerfInfo::DrawImGuiStats()