This reverts ceec3bc4. Two independent reasons, either sufficient.
The rendering regression. The slice deleted TextRenderGlStateScope, which
saved GL_MULTISAMPLE and GL_SAMPLE_ALPHA_TO_COVERAGE on entry, disabled them
for the text pass, and restored them on exit (TextRenderGlStateScope.cs:111-112
and 153-154 at the parent commit). Its replacement bakes that state into the
text pipeline but nothing restores it, and GlGpuPassEncoder.Dispose does not
either. Every world renderer is still raw GL at this point in the campaign, so
from the first UI frame onward the world drew with multisampling disabled.
The offline pixel gate caught it: 1,791 of 563,200 compared pixels differed,
0.318% against a 0.001 threshold. The commit message attributed this to
wall-clock-driven ambient animation shifting phase, and committed through the
failure. That explanation does not survive its own control: capturing twice at
the reverted-to commit differs by 19 pixels and twice at the slice's own commit
by 8, while base-versus-head differs by 1,791 - a 224x gap that no shared-noise
source explains. An amplified difference image settles it visually: the changed
pixels are the silhouette edges of every tree, building and rock, with terrain
interiors, water and the entire UI untouched. That is the signature of losing
edge antialiasing, not of animated sprites.
This is the exact failure mode two existing memory notes already warn about -
a mid-frame renderer must set every GL state it uses rather than inherit it,
and issue #52's lesson that a rendering migration must audit per-pass GL state
before declaring itself done.
The scope. The brief was three small leaf renderers plus additive frame-
lifecycle wiring, roughly ten files. The commit changed 334 files with 3,665
insertions and 3,845 deletions, including 323 public-to-internal visibility
conversions across the App assembly, 55 test files, two retired conformance
tests, and a self-described temporary escape hatch for bridging raw-GL viewport
textures. Even without the regression, that is not separable into the part
worth keeping and the part worth dropping.
Reverting rather than patching because the good work here - the RHI frame
lifecycle wiring and a genuine render-state-cache staleness fix - is small
enough to redo cleanly against a tightened spec, while untangling it from 300+
files of unrelated churn is not.
Post-revert: Release build clean, App suite back to 3,843 passed / 3 skipped,
offline pixel gate passing at 19 differing pixels.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
198 lines
6.6 KiB
C#
198 lines
6.6 KiB
C#
using AcDream.App.UI;
|
|
using AcDream.Core.Textures;
|
|
using DatReaderWriter;
|
|
using AcDream.Content;
|
|
using DatReaderWriter.DBObjs;
|
|
using Silk.NET.Core;
|
|
using Silk.NET.Input;
|
|
|
|
namespace AcDream.App.Rendering;
|
|
|
|
/// <summary>Applies retail cursor feedback to Silk using dat MediaDescCursor art when available.</summary>
|
|
public sealed class RetailCursorManager
|
|
{
|
|
private readonly IDatReaderWriter _dats;
|
|
private readonly object _datLock;
|
|
private readonly RetailCursorResolver _globalCursors;
|
|
private readonly Dictionary<uint, RawImage> _imagesBySurface = new();
|
|
private readonly HashSet<uint> _missingSurfaces = new();
|
|
private readonly HashSet<RetailGlobalCursorKind> _reportedFallbacks = new();
|
|
private bool _hasLayerState;
|
|
private RetailGlobalCursorKind _lastGlobalKind;
|
|
private UiCursorMedia _lastWidgetCursor;
|
|
private UiCursorMedia _lastAppliedCursor;
|
|
private StandardCursor? _lastStandardCursor;
|
|
|
|
public RetailCursorManager(IDatReaderWriter dats, object datLock)
|
|
{
|
|
_dats = dats;
|
|
_datLock = datLock;
|
|
_globalCursors = new RetailCursorResolver(dats, datLock);
|
|
}
|
|
|
|
public void Apply(IEnumerable<IMouse> mice, CursorFeedback feedback)
|
|
{
|
|
foreach (RetailCursorLayer layer in PlanApplication(
|
|
_hasLayerState,
|
|
_lastGlobalKind,
|
|
_lastWidgetCursor,
|
|
feedback.GlobalKind,
|
|
feedback.Cursor))
|
|
{
|
|
if (layer == RetailCursorLayer.Widget
|
|
&& feedback.Cursor.IsValid
|
|
&& TryGetImage(feedback.Cursor.File, out var image))
|
|
{
|
|
ApplyCustom(mice, feedback.Cursor, image);
|
|
}
|
|
else
|
|
{
|
|
ApplyGlobal(mice, feedback.GlobalKind);
|
|
}
|
|
}
|
|
|
|
_hasLayerState = true;
|
|
_lastGlobalKind = feedback.GlobalKind;
|
|
_lastWidgetCursor = feedback.Cursor;
|
|
}
|
|
|
|
private void ApplyGlobal(IEnumerable<IMouse> mice, RetailGlobalCursorKind kind)
|
|
{
|
|
if (_globalCursors.TryResolve(kind, out var globalCursor)
|
|
&& TryGetImage(globalCursor.File, out var globalImage))
|
|
{
|
|
ApplyCustom(mice, globalCursor, globalImage);
|
|
return;
|
|
}
|
|
|
|
if (_reportedFallbacks.Add(kind))
|
|
{
|
|
Console.Error.WriteLine(
|
|
$"[D.2b] retail cursor {kind} could not be resolved from DAT; " +
|
|
"using the registered OS cursor adaptation (AP-72).");
|
|
}
|
|
ApplyStandard(mice, StandardCursorFor(kind));
|
|
}
|
|
|
|
private void ApplyCustom(IEnumerable<IMouse> mice, UiCursorMedia cursorMedia, RawImage image)
|
|
{
|
|
if (_lastStandardCursor is null && _lastAppliedCursor.Equals(cursorMedia))
|
|
return;
|
|
|
|
foreach (var mouse in mice)
|
|
{
|
|
var cursor = mouse.Cursor;
|
|
cursor.Image = image;
|
|
cursor.HotspotX = cursorMedia.HotspotX;
|
|
cursor.HotspotY = cursorMedia.HotspotY;
|
|
if (cursor.Type != CursorType.Custom)
|
|
cursor.Type = CursorType.Custom;
|
|
}
|
|
|
|
_lastAppliedCursor = cursorMedia;
|
|
_lastStandardCursor = null;
|
|
}
|
|
|
|
private void ApplyStandard(IEnumerable<IMouse> mice, StandardCursor desired)
|
|
{
|
|
if (_lastStandardCursor == desired)
|
|
return;
|
|
|
|
foreach (var mouse in mice)
|
|
{
|
|
var cursor = mouse.Cursor;
|
|
var standard = desired;
|
|
if (!cursor.IsSupported(standard))
|
|
standard = StandardCursor.Arrow;
|
|
if (!cursor.IsSupported(standard))
|
|
continue;
|
|
|
|
if (cursor.Type != CursorType.Standard)
|
|
cursor.Type = CursorType.Standard;
|
|
if (cursor.StandardCursor != standard)
|
|
cursor.StandardCursor = standard;
|
|
}
|
|
|
|
_lastAppliedCursor = default;
|
|
_lastStandardCursor = desired;
|
|
}
|
|
|
|
private bool TryGetImage(uint renderSurfaceId, out RawImage image)
|
|
{
|
|
if (_imagesBySurface.TryGetValue(renderSurfaceId, out image))
|
|
return true;
|
|
if (_missingSurfaces.Contains(renderSurfaceId))
|
|
return false;
|
|
|
|
DecodedTexture? decoded = DecodeCursorSurface(renderSurfaceId);
|
|
if (decoded is null || decoded.Width <= 0 || decoded.Height <= 0 || decoded.Rgba8.Length == 0)
|
|
{
|
|
_missingSurfaces.Add(renderSurfaceId);
|
|
image = default;
|
|
return false;
|
|
}
|
|
|
|
image = new RawImage(decoded.Width, decoded.Height, decoded.Rgba8);
|
|
_imagesBySurface[renderSurfaceId] = image;
|
|
return true;
|
|
}
|
|
|
|
private DecodedTexture? DecodeCursorSurface(uint renderSurfaceId)
|
|
{
|
|
lock (_datLock)
|
|
{
|
|
if (!_dats.Portal.TryGet<RenderSurface>(renderSurfaceId, out var rs)
|
|
&& !_dats.HighRes.TryGet<RenderSurface>(renderSurfaceId, out rs))
|
|
return null;
|
|
|
|
Palette? palette = rs.DefaultPaletteId != 0
|
|
? _dats.Get<Palette>(rs.DefaultPaletteId)
|
|
: null;
|
|
return SurfaceDecoder.DecodeRenderSurface(rs, palette);
|
|
}
|
|
}
|
|
|
|
internal static IReadOnlyList<RetailCursorLayer> PlanApplication(
|
|
bool hasLayerState,
|
|
RetailGlobalCursorKind previousGlobal,
|
|
UiCursorMedia previousWidget,
|
|
RetailGlobalCursorKind currentGlobal,
|
|
UiCursorMedia currentWidget)
|
|
{
|
|
bool globalChanged = !hasLayerState || previousGlobal != currentGlobal;
|
|
bool widgetChanged = !hasLayerState || previousWidget != currentWidget;
|
|
if (!globalChanged && !widgetChanged)
|
|
return Array.Empty<RetailCursorLayer>();
|
|
|
|
var result = new List<RetailCursorLayer>(2);
|
|
if (globalChanged)
|
|
result.Add(RetailCursorLayer.Global);
|
|
|
|
if (widgetChanged)
|
|
{
|
|
RetailCursorLayer widgetResult = currentWidget.IsValid
|
|
? RetailCursorLayer.Widget
|
|
: RetailCursorLayer.Global;
|
|
if (result.Count == 0 || result[^1] != widgetResult)
|
|
result.Add(widgetResult);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private static StandardCursor StandardCursorFor(RetailGlobalCursorKind kind)
|
|
=> kind switch
|
|
{
|
|
RetailGlobalCursorKind.Use or RetailGlobalCursorKind.UseFound => StandardCursor.Hand,
|
|
RetailGlobalCursorKind.TargetPending => StandardCursor.Crosshair,
|
|
RetailGlobalCursorKind.TargetValid => StandardCursor.ResizeAll,
|
|
RetailGlobalCursorKind.TargetInvalid => StandardCursor.NotAllowed,
|
|
_ => StandardCursor.Arrow,
|
|
};
|
|
}
|
|
|
|
internal enum RetailCursorLayer
|
|
{
|
|
Global,
|
|
Widget,
|
|
}
|