Cleanup UI code.

This commit is contained in:
Ottermandias 2025-01-11 13:46:08 +01:00
parent e8300fc5c8
commit 0758739666
3 changed files with 86 additions and 64 deletions

View file

@ -42,7 +42,6 @@ using Penumbra.Interop.Hooks.ResourceLoading;
using Penumbra.GameData.Files.StainMapStructs;
using Penumbra.String.Classes;
using Penumbra.UI.AdvancedWindow.Materials;
using CSGraphics = FFXIVClientStructs.FFXIV.Client.Graphics;
namespace Penumbra.UI.Tabs.Debug;
@ -105,7 +104,7 @@ public class DebugTab : Window, ITab, IUiService
private readonly RsfService _rsfService;
private readonly SchedulerResourceManagementService _schedulerService;
private readonly ObjectIdentification _objectIdentification;
private readonly RenderTargetHdrEnabler _renderTargetHdrEnabler;
private readonly RenderTargetDrawer _renderTargetDrawer;
public DebugTab(PerformanceTracker performance, Configuration config, CollectionManager collectionManager, ObjectManager objects,
IClientState clientState, IDataManager dataManager,
@ -116,7 +115,7 @@ public class DebugTab : Window, ITab, IUiService
TextureManager textureManager, ShaderReplacementFixer shaderReplacementFixer, RedrawService redraws, DictEmote emotes,
Diagnostics diagnostics, IpcTester ipcTester, CrashHandlerPanel crashHandlerPanel, TexHeaderDrawer texHeaderDrawer,
HookOverrideDrawer hookOverrides, RsfService rsfService, GlobalVariablesDrawer globalVariablesDrawer,
SchedulerResourceManagementService schedulerService, ObjectIdentification objectIdentification, RenderTargetHdrEnabler renderTargetHdrEnabler)
SchedulerResourceManagementService schedulerService, ObjectIdentification objectIdentification, RenderTargetDrawer renderTargetDrawer)
: base("Penumbra Debug Window", ImGuiWindowFlags.NoCollapse)
{
IsOpen = true;
@ -156,7 +155,7 @@ public class DebugTab : Window, ITab, IUiService
_globalVariablesDrawer = globalVariablesDrawer;
_schedulerService = schedulerService;
_objectIdentification = objectIdentification;
_renderTargetHdrEnabler = renderTargetHdrEnabler;
_renderTargetDrawer = renderTargetDrawer;
_objects = objects;
_clientState = clientState;
_dataManager = dataManager;
@ -192,7 +191,7 @@ public class DebugTab : Window, ITab, IUiService
DrawData();
DrawCrcCache();
DrawResourceProblems();
DrawRenderTargets();
_renderTargetDrawer.Draw();
_hookOverrides.Draw();
DrawPlayerModelInfo();
_globalVariablesDrawer.Draw();
@ -1139,54 +1138,6 @@ public class DebugTab : Window, ITab, IUiService
}
/// <summary> Draw information about render targets. </summary>
private unsafe void DrawRenderTargets()
{
if (!ImGui.CollapsingHeader("Render Targets"))
return;
var report = _renderTargetHdrEnabler.TextureReport;
if (report == null)
{
ImGui.TextUnformatted("The RenderTargetManager report has not been gathered.");
ImGui.TextUnformatted("Please restart the game with Debug Mode and Wait for Plugins on Startup enabled to fill this section.");
return;
}
using var table = Table("##RenderTargetTable", 5, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingFixedFit);
if (!table)
return;
ImUtf8.TableSetupColumn("Offset"u8, ImGuiTableColumnFlags.WidthStretch, 0.15f);
ImUtf8.TableSetupColumn("Creation Order"u8, ImGuiTableColumnFlags.WidthStretch, 0.15f);
ImUtf8.TableSetupColumn("Original Texture Format"u8, ImGuiTableColumnFlags.WidthStretch, 0.2f);
ImUtf8.TableSetupColumn("Current Texture Format"u8, ImGuiTableColumnFlags.WidthStretch, 0.2f);
ImUtf8.TableSetupColumn("Comment"u8, ImGuiTableColumnFlags.WidthStretch, 0.3f);
ImGui.TableHeadersRow();
foreach (var record in report)
{
ImGui.TableNextColumn();
ImUtf8.Text($"0x{record.Offset:X}");
ImGui.TableNextColumn();
ImUtf8.Text($"{record.CreationOrder}");
ImGui.TableNextColumn();
ImUtf8.Text($"{record.OriginalTextureFormat}");
ImGui.TableNextColumn();
var texture = *(CSGraphics.Kernel.Texture**)((nint)CSGraphics.Render.RenderTargetManager.Instance() + record.Offset);
if (texture != null)
{
using var color = ImRaii.PushColor(ImGuiCol.Text, ImGuiUtil.HalfBlendText(0xFF), texture->TextureFormat != record.OriginalTextureFormat);
ImUtf8.Text($"{texture->TextureFormat}");
}
ImGui.TableNextColumn();
var forcedConfig = RenderTargetHdrEnabler.GetForcedTextureConfig(record.CreationOrder);
if (forcedConfig.HasValue)
ImGui.TextUnformatted(forcedConfig.Value.Comment);
}
}
/// <summary> Draw information about IPC options and availability. </summary>
private void DrawDebugTabIpc()
{

View file

@ -0,0 +1,59 @@
using FFXIVClientStructs.FFXIV.Client.Graphics.Kernel;
using FFXIVClientStructs.FFXIV.Client.Graphics.Render;
using ImGuiNET;
using OtterGui;
using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Interop.Hooks.PostProcessing;
namespace Penumbra.UI.Tabs.Debug;
public class RenderTargetDrawer(RenderTargetHdrEnabler renderTargetHdrEnabler) : IUiService
{
/// <summary> Draw information about render targets. </summary>
public unsafe void Draw()
{
if (!ImUtf8.CollapsingHeader("Render Targets"u8))
return;
var report = renderTargetHdrEnabler.TextureReport;
if (report == null)
{
ImUtf8.Text("The RenderTargetManager report has not been gathered."u8);
ImUtf8.Text("Please restart the game with Debug Mode and Wait for Plugins on Startup enabled to fill this section."u8);
return;
}
using var table = ImUtf8.Table("##RenderTargetTable"u8, 5, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingFixedFit);
if (!table)
return;
ImUtf8.TableSetupColumn("Offset"u8, ImGuiTableColumnFlags.WidthStretch, 0.15f);
ImUtf8.TableSetupColumn("Creation Order"u8, ImGuiTableColumnFlags.WidthStretch, 0.15f);
ImUtf8.TableSetupColumn("Original Texture Format"u8, ImGuiTableColumnFlags.WidthStretch, 0.2f);
ImUtf8.TableSetupColumn("Current Texture Format"u8, ImGuiTableColumnFlags.WidthStretch, 0.2f);
ImUtf8.TableSetupColumn("Comment"u8, ImGuiTableColumnFlags.WidthStretch, 0.3f);
ImGui.TableHeadersRow();
foreach (var record in report)
{
ImUtf8.DrawTableColumn($"0x{record.Offset:X}");
ImUtf8.DrawTableColumn($"{record.CreationOrder}");
ImUtf8.DrawTableColumn($"{record.OriginalTextureFormat}");
ImGui.TableNextColumn();
var texture = *(Texture**)((nint)RenderTargetManager.Instance()
+ record.Offset);
if (texture != null)
{
using var color = Dalamud.Interface.Utility.Raii.ImRaii.PushColor(ImGuiCol.Text, ImGuiUtil.HalfBlendText(0xFF),
texture->TextureFormat != record.OriginalTextureFormat);
ImUtf8.Text($"{texture->TextureFormat}");
}
ImGui.TableNextColumn();
var forcedConfig = RenderTargetHdrEnabler.GetForcedTextureConfig(record.CreationOrder);
if (forcedConfig.HasValue)
ImUtf8.Text(forcedConfig.Value.Comment);
}
}
}

View file

@ -10,6 +10,7 @@ using OtterGui.Compression;
using OtterGui.Custom;
using OtterGui.Raii;
using OtterGui.Services;
using OtterGui.Text;
using OtterGui.Widgets;
using Penumbra.Api;
using Penumbra.Collections;
@ -905,18 +906,29 @@ public class SettingsTab : ITab, IUiService
private void DrawHdrRenderTargets()
{
var item = _config.HdrRenderTargets ? 1 : 0;
ImGui.SetNextItemWidth(ImGui.CalcTextSize("M").X * 5.0f + ImGui.GetFrameHeight());
var edited = ImGui.Combo("##hdrRenderTarget", ref item, "SDR\0HDR\0");
ImGui.SetNextItemWidth(ImUtf8.CalcTextSize("M"u8).X * 5.0f + ImGui.GetFrameHeight());
using (var combo = ImUtf8.Combo("##hdrRenderTarget"u8, _config.HdrRenderTargets ? "HDR"u8 : "SDR"u8))
{
if (combo)
{
if (ImUtf8.Selectable("HDR"u8, _config.HdrRenderTargets) && !_config.HdrRenderTargets)
{
_config.HdrRenderTargets = true;
_config.Save();
}
if (ImUtf8.Selectable("SDR"u8, !_config.HdrRenderTargets) && _config.HdrRenderTargets)
{
_config.HdrRenderTargets = false;
_config.Save();
}
}
}
ImGui.SameLine();
ImGuiUtil.LabeledHelpMarker("Diffuse Dynamic Range",
"Set the dynamic range that can be used for diffuse colors in materials without causing visual artifacts.\nChanging this setting requires a game restart. It also only works if Wait for Plugins on Startup is enabled.");
if (!edited)
return;
_config.HdrRenderTargets = item != 0;
_config.Save();
ImUtf8.LabeledHelpMarker("Diffuse Dynamic Range"u8,
"Set the dynamic range that can be used for diffuse colors in materials without causing visual artifacts.\n"u8
+ "Changing this setting requires a game restart. It also only works if Wait for Plugins on Startup is enabled."u8);
}
/// <summary> Draw a checkbox for the HTTP API that creates and destroys the web server when toggled. </summary>