Add named debug view selector
This commit is contained in:
parent
135404986b
commit
40d74a6a67
5 changed files with 181 additions and 4 deletions
|
|
@ -29,6 +29,21 @@ public sealed class D3D11Renderer : IDisposable
|
|||
private const int FroxelBufferElementCount = FroxelCountX * FroxelCountY * FroxelCountZ * FroxelSlotCount;
|
||||
private const int PlanetCount = 5;
|
||||
private const int FieldInstanceCount = PlanetCount + 5;
|
||||
private static readonly DebugUi.DebugUiOption[] RenderDebugOptions =
|
||||
[
|
||||
new(0, "Final"),
|
||||
new(1, "Raw Scene"),
|
||||
new(2, "History"),
|
||||
new(3, "History Age"),
|
||||
new(4, "History Weight"),
|
||||
new(5, "Temporal Control"),
|
||||
new(6, "Field Identity"),
|
||||
new(7, "Bloom"),
|
||||
new(8, "Exposed Luminance"),
|
||||
new(9, "Medium Density"),
|
||||
new(10, "Medium Transmittance"),
|
||||
];
|
||||
|
||||
private const float SunRadius = 1.12f;
|
||||
private const float FroxelMinZ = -2.0f;
|
||||
private const float FroxelMaxZ = 6.0f;
|
||||
|
|
@ -362,7 +377,7 @@ public sealed class D3D11Renderer : IDisposable
|
|||
return new DebugUi("Aquarium Debug")
|
||||
.Panel(panel => panel
|
||||
.Section("View")
|
||||
.Slider("Render Debug", () => RenderDebugMode, value => RenderDebugMode = Math.Clamp(value, GraphicsSettings.MinRenderDebugMode, GraphicsSettings.MaxRenderDebugMode), GraphicsSettings.MinRenderDebugMode, GraphicsSettings.MaxRenderDebugMode, "Selects the active renderer debug view.")
|
||||
.Options("Render Debug", () => RenderDebugMode, value => RenderDebugMode = Math.Clamp(value, GraphicsSettings.MinRenderDebugMode, GraphicsSettings.MaxRenderDebugMode), RenderDebugOptions, "Selects the active renderer debug view.")
|
||||
.Button("Reset View", () => RenderDebugMode = 0, "Returns to the final presented frame.")
|
||||
.Section("HDR")
|
||||
.Slider("Exposure", () => SceneExposure, value => SceneExposure = Math.Clamp(value, GraphicsSettings.MinSceneExposure, GraphicsSettings.MaxSceneExposure), GraphicsSettings.MinSceneExposure, GraphicsSettings.MaxSceneExposure, "0.###", "Manual scene exposure before display transform.")
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ internal sealed class DebugUi
|
|||
return;
|
||||
}
|
||||
|
||||
DebugUiControl? clickedControl = null;
|
||||
for (var index = controls.Count - 1; index >= 0; index--)
|
||||
{
|
||||
var control = controls[index];
|
||||
|
|
@ -120,8 +121,17 @@ internal sealed class DebugUi
|
|||
slider.Drag(mousePosition);
|
||||
}
|
||||
|
||||
clickedControl = control;
|
||||
break;
|
||||
}
|
||||
|
||||
foreach (var control in controls)
|
||||
{
|
||||
if (!ReferenceEquals(control, clickedControl))
|
||||
{
|
||||
control.DismissTransientState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(
|
||||
|
|
@ -211,7 +221,7 @@ internal sealed class DebugUi
|
|||
var y = PanelTop + HeaderHeight + 10.0f;
|
||||
foreach (var control in controls)
|
||||
{
|
||||
var height = control is SectionControl ? SectionHeight : RowHeight;
|
||||
var height = control.LayoutHeight;
|
||||
control.Bounds = RectFromEdges(PanelLeft + 10.0f, y, PanelLeft + PanelWidth - 10.0f, y + height);
|
||||
y += height + (control is SectionControl ? 2.0f : RowGap);
|
||||
}
|
||||
|
|
@ -324,8 +334,16 @@ internal sealed class DebugUi
|
|||
controls.Add(new IntSliderControl(label, read, write, min, max, tooltip));
|
||||
return this;
|
||||
}
|
||||
|
||||
public DebugUiPanel Options(string label, Func<int> read, Action<int> write, IReadOnlyList<DebugUiOption> options, string? tooltip = null)
|
||||
{
|
||||
controls.Add(new OptionControl(label, read, write, options, tooltip));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct DebugUiOption(int Value, string Label);
|
||||
|
||||
internal abstract class DebugUiControl(string label, string? tooltip = null)
|
||||
{
|
||||
private static int nextId;
|
||||
|
|
@ -344,6 +362,8 @@ internal sealed class DebugUi
|
|||
|
||||
public virtual bool IsInteractive => true;
|
||||
|
||||
public virtual float LayoutHeight => this is SectionControl ? SectionHeight : RowHeight;
|
||||
|
||||
public virtual bool HitTest(Vector2 mouse) => Contains(Bounds, mouse);
|
||||
|
||||
public virtual void UpdateHover(Vector2 mouse)
|
||||
|
|
@ -355,6 +375,10 @@ internal sealed class DebugUi
|
|||
{
|
||||
}
|
||||
|
||||
public virtual void DismissTransientState()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void Draw(
|
||||
ID2D1RenderTarget target,
|
||||
IDWriteTextFormat format,
|
||||
|
|
@ -487,6 +511,138 @@ internal sealed class DebugUi
|
|||
}
|
||||
}
|
||||
|
||||
private sealed class OptionControl(
|
||||
string label,
|
||||
Func<int> read,
|
||||
Action<int> write,
|
||||
IReadOnlyList<DebugUiOption> options,
|
||||
string? tooltip) : DebugUiControl(label, tooltip)
|
||||
{
|
||||
private bool isOpen;
|
||||
private int hoveredOptionIndex = -1;
|
||||
|
||||
public override float LayoutHeight => RowHeight + (isOpen ? options.Count * RowHeight : 0.0f);
|
||||
|
||||
public override void UpdateHover(Vector2 mouse)
|
||||
{
|
||||
hoveredOptionIndex = -1;
|
||||
IsHovered = HitTest(mouse);
|
||||
if (!isOpen || !IsHovered || Contains(MainBounds(), mouse))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var index = 0; index < options.Count; index++)
|
||||
{
|
||||
if (Contains(OptionBounds(index), mouse))
|
||||
{
|
||||
hoveredOptionIndex = index;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Click(Vector2 mouse)
|
||||
{
|
||||
if (!isOpen)
|
||||
{
|
||||
isOpen = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Contains(MainBounds(), mouse))
|
||||
{
|
||||
isOpen = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (hoveredOptionIndex >= 0 && hoveredOptionIndex < options.Count)
|
||||
{
|
||||
write(options[hoveredOptionIndex].Value);
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DismissTransientState()
|
||||
{
|
||||
isOpen = false;
|
||||
}
|
||||
|
||||
public override void Draw(
|
||||
ID2D1RenderTarget target,
|
||||
IDWriteTextFormat format,
|
||||
ID2D1SolidColorBrush rowBrush,
|
||||
ID2D1SolidColorBrush hoverRowBrush,
|
||||
ID2D1SolidColorBrush activeRowBrush,
|
||||
ID2D1SolidColorBrush outlineBrush,
|
||||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush)
|
||||
{
|
||||
var main = MainBounds();
|
||||
target.FillRectangle(main, IsActive ? activeRowBrush : IsHovered ? hoverRowBrush : rowBrush);
|
||||
target.DrawLine(new Vector2(main.Left, main.Bottom), new Vector2(main.Right, main.Bottom), outlineBrush, 1.0f);
|
||||
target.DrawText(Label.ToUpperInvariant(), format, RectFromEdges(main.Left + 8.0f, main.Top, main.Left + LabelWidth, main.Bottom), accentBrush, DrawTextOptions.Clip);
|
||||
target.DrawText(SelectedLabel(), format, RectFromEdges(main.Left + LabelWidth + 10.0f, main.Top, main.Right - 32.0f, main.Bottom), primaryBrush, DrawTextOptions.Clip);
|
||||
|
||||
var arrowBrush = IsActive ? accentActiveBrush : IsHovered ? accentHoverBrush : accentBrush;
|
||||
var cy = (main.Top + main.Bottom) * 0.5f;
|
||||
target.DrawLine(new Vector2(main.Right - 24.0f, cy - 3.0f), new Vector2(main.Right - 18.0f, cy + 3.0f), arrowBrush, 1.5f);
|
||||
target.DrawLine(new Vector2(main.Right - 18.0f, cy + 3.0f), new Vector2(main.Right - 12.0f, cy - 3.0f), arrowBrush, 1.5f);
|
||||
|
||||
if (!isOpen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var index = 0; index < options.Count; index++)
|
||||
{
|
||||
var bounds = OptionBounds(index);
|
||||
var selected = options[index].Value == read();
|
||||
var hovered = index == hoveredOptionIndex;
|
||||
target.FillRectangle(bounds, hovered ? hoverRowBrush : rowBrush);
|
||||
target.DrawLine(new Vector2(bounds.Left, bounds.Bottom), new Vector2(bounds.Right, bounds.Bottom), outlineBrush, 1.0f);
|
||||
var labelBrush = selected ? accentBrush : primaryBrush;
|
||||
target.DrawText(options[index].Label, format, RectFromEdges(bounds.Left + 18.0f, bounds.Top, bounds.Right - 12.0f, bounds.Bottom), labelBrush, DrawTextOptions.Clip);
|
||||
if (selected)
|
||||
{
|
||||
target.DrawLine(new Vector2(bounds.Left + 7.0f, bounds.Top + 16.0f), new Vector2(bounds.Left + 10.0f, bounds.Top + 20.0f), accentBrush, 1.75f);
|
||||
target.DrawLine(new Vector2(bounds.Left + 10.0f, bounds.Top + 20.0f), new Vector2(bounds.Left + 15.0f, bounds.Top + 10.0f), accentBrush, 1.75f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string SelectedLabel()
|
||||
{
|
||||
var value = read();
|
||||
foreach (var option in options)
|
||||
{
|
||||
if (option.Value == value)
|
||||
{
|
||||
return option.Label;
|
||||
}
|
||||
}
|
||||
|
||||
return value.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private Rect MainBounds()
|
||||
{
|
||||
return RectFromEdges(Bounds.Left, Bounds.Top, Bounds.Right, Bounds.Top + RowHeight);
|
||||
}
|
||||
|
||||
private Rect OptionBounds(int index)
|
||||
{
|
||||
var top = Bounds.Top + RowHeight + index * RowHeight;
|
||||
return RectFromEdges(Bounds.Left + 8.0f, top, Bounds.Right, top + RowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class SliderControl(string label, string? tooltip) : DebugUiControl(label, tooltip)
|
||||
{
|
||||
private const float ThumbRadius = 4.0f;
|
||||
|
|
|
|||
Loading…
Reference in a new issue