Skip to content

Commit

Permalink
Functioning Terrain tab in perfinfo with debug toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffyfreak committed Nov 20, 2024
1 parent 7a9bff7 commit fcaafe5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
35 changes: 30 additions & 5 deletions src/GeoSphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static const int detail_edgeLen[5] = {

static const double gs_targetPatchTriLength(100.0);
static std::vector<GeoSphere *> s_allGeospheres;
static Uint32 s_debugFlags = GeoSphere::DebugFlags::DEBUG_NONE;

void GeoSphere::InitGeoSphere()
{
Expand Down Expand Up @@ -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()
{
{
Expand Down Expand Up @@ -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 :)
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/GeoSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 { // <enum scope='GeoSphere' name=GeoSphereDebugFlags prefix=DEBUG_ public>
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(); }

Expand Down
26 changes: 23 additions & 3 deletions src/pigui/PerfInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fcaafe5

Please sign in to comment.