Files
sbox-public/engine/Sandbox.Engine/Systems/Render/Debug/DebugOverlay.cs
Antoine Pilote a582fd6f7a UI Batching (#4372)
New UI rendering that groups multiple panels to be grouped into a single draw call when possible.

New custom rendering API for custom panels using `Panel.Draw.XX` to emit drawing commands.
2026-04-14 16:06:41 -07:00

126 lines
3.2 KiB
C#

using Sandbox.Rendering;
namespace Sandbox;
internal static partial class DebugOverlay
{
static CommandList _overlay = new( "Engine Overlay" );
private const float OverlaySpacing = 16f;
public static CommandList CommandList => _overlay;
public static HudPainter Hud => new HudPainter( CommandList );
public static void Reset()
{
_overlay.Reset();
}
public static void Render()
{
_overlay.ExecuteOnRenderThread();
}
[ConVar( "overlay_profile", Help = "Draws an overlay showing timings from the main profile categories" )]
internal static int overlay_profile { get; set; } = 0;
[ConVar( "overlay_alloc", Help = "Draws an overlay showing allocations and garbage collection" )]
internal static int overlay_alloc { get; set; } = 0;
[ConVar( "overlay_frame", Help = "Draws an overlay render frame stats" )]
internal static int overlay_frame { get; set; } = 0;
[ConVar( "overlay_network_graph", Help = "Draws an overlay showing a network usage summary" )]
internal static int overlay_network_graph { get; set; } = 0;
[ConVar( "overlay_network_calls", Help = "Draws an overlay showing most received network calls" )]
internal static int overlay_network_calls { get; set; } = 0;
[ConVar( "overlay_pp", Help = "Draws an overlay showing current post process stack" )]
internal static int overlay_pp { get; set; } = 0;
[ConVar( "overlay_gpu", Help = "Draws an overlay showing GPU timing for render passes" )]
internal static int overlay_gpu { get; set; } = 0;
[ConVar( "overlay_resources", Help = "Draws an overlay showing registered resources and native cache" )]
internal static int overlay_resources { get; set; } = 0;
public static void Draw()
{
Vector2 pos = new Vector2( 64, 64 );
var activeScene = Application.GetActiveScene();
// Show current render debug mode on screen when not default
if ( ToolsVisualization.mat_toolsvis != SceneCameraDebugMode.Normal )
{
DebugOverlay.ToolsVisualization.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_network_calls == 1 )
{
DebugOverlay.NetworkCalls.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_network_graph == 1 )
{
DebugOverlay.NetworkGraph.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_profile == 1 )
{
DebugOverlay.Profiler.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_frame == 1 )
{
DebugOverlay.Frame.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_pp == 1 )
{
activeScene?.Camera?.PrintPostProcessDebugOverlay( ref pos, Hud );
pos.y += OverlaySpacing;
}
if ( overlay_alloc == 1 )
{
DebugOverlay.Allocations.Draw( ref pos );
pos.y += OverlaySpacing;
}
else
{
DebugOverlay.Allocations.Disabled();
}
// GPU Profiler
Diagnostics.GpuProfilerStats.Enabled = overlay_gpu == 1;
Diagnostics.GpuProfilerStats.Update();
if ( overlay_gpu == 1 )
{
DebugOverlay.GpuProfiler.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_resources == 1 )
{
DebugOverlay.Resources.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( overlay_ui == 1 )
{
DebugOverlay.UI.Draw( ref pos );
pos.y += OverlaySpacing;
}
if ( ShadowMapper.DebugEnabled )
ShadowMapper.Draw( ref pos, Hud );
}
}