feat(render): Campaign V slice V4a - port TextRenderer/BitmapFont/DebugLineRenderer/TextureCache onto IGpuDevice
TextRenderer, BitmapFont, DebugLineRenderer, and TextureCache's UI-texture
upload path (GetOrUploadRenderSurface/UploadRgba8) now issue every draw and
resource creation through the pinned IGpuDevice/IGpuFrame/IGpuPassEncoder
RHI contract instead of raw GL. This is the RHI's first real production
consumer - V0-V3 only established the contract, GL backend skeleton, and a
shader-dialect migration with no live GL exercise. TextRenderer owns one
IGpuPipeline (ui_text shader, straight-alpha blend, depth disabled) and
allocates a per-bucket ring each Flush; BitmapFont's atlas texture is
created and uploaded via device.CreateTexture/.Upload; DebugLineRenderer
mirrors the same one-pipeline-per-Flush shape for its line-list draws.
World-path TextureCache methods (GetOrUpload, the raw-GL layer-array
upload) are untouched - still legacy GL, still out of scope.
Frame lifecycle: GpuDeviceFrameLifetime (RenderFrameOrchestrator.cs) wraps
IGpuDevice.BeginFrame()/IGpuFrame.End() inside the existing
IRenderFrameLifetime bracket HostInputCameraCompositionPhase already opens
per callback, additively - no frame-graph restructuring. Ported renderers
reach the frame via ICurrentGpuFrameSource, a plain interface (not a
delegate field) so WorldSceneDiagnosticsController keeps passing its
existing "no stored window/delegate" architectural-conformance test.
Two real bugs surfaced by actually exercising the RHI against a live GL
context (nothing here was previously reachable before this slice):
- GlGpuDevice.BeginFrame() now resets the render-state cache every frame.
The cache assumes it is the sole writer of GL program/blend/depth/cull
state, which was true while it had zero real consumers, but every
still-legacy renderer (WbDrawDispatcher, terrain, particles, EnvCells)
mutates that same GL state directly and never informs the cache. Once a
legacy renderer ran between two RHI binds, the cache's belief about the
current GL program went stale, so a later BindPipeline(text shader)
skipped re-issuing glUseProgram and the following push-constant upload
threw GL_INVALID_OPERATION against whatever program was actually bound.
Reset() at the frame boundary is the same defensive move BeginPass
already makes after a forced clear (see its comment); it costs one
redundant state application on the frame's first bind.
- GL_MULTISAMPLE has no representation in the pinned contract. Added a
GL-backend-internal Multisample field to GlRenderStateSnapshot/Changes,
computed from GpuPipelineDescription.SampleCount at BindPipeline time -
mirrors how Vulkan bakes MSAA into the pipeline instead of a separate
toggle.
Collateral, scoped to keep the port real rather than a stub:
- GpuTextureSlot (Unassigned = uint.MaxValue, NOT 0) now flows through
every consumer of TextureCache.GetOrUploadRenderSurface/UploadRgba8 and
TextRenderer.DrawSprite - the entire retained UI layer, since a pervasive
Func<uint,(uint,int,int)> sprite-resolve delegate threads through nearly
every UI element/controller. Every prior `== 0` / `!= 0` "no texture"
check became `.IsAssigned` / `!.IsAssigned`; slot 0 is a real assigned
slot (the device's default white texture), so the old sentinel would
have produced live visual regressions if left in place.
- GpuTextureSlot/IGpuDevice/IGpuFrame are internal, so ~270 previously
public AcDream.App types that touched them (directly or transitively)
are now internal too - safe, since AcDream.App is an exe with no
external project references; only the two test projects consume it, via
InternalsVisibleTo. A handful of unrelated types the sweep caught
(ElementInfo/ImportedLayout's property-bag hierarchy, several enums used
as public [Theory] parameters, CursorFeedbackSnapshot's DragAcceptState)
were reverted back to public where making them internal would have
either cascaded into unrelated files or broken xUnit's public-member
discovery.
- ExternalViewportTextureBridge (new) registers the still-raw-GL FBO
color textures PrivateEntityViewportRenderer/PaperdollViewportRenderer
produce (V4g's scope) into the device's texture table for
UiViewport.TextureHandle, via a temporary
GlGpuDevice.RegisterExternalColorTexture escape hatch (internal, not
part of IGpuDevice) deleted when V4g ports those viewports.
- TextRenderGlStateScope.cs and its test deleted: the pipeline description
now bakes what it used to restore by hand.
- ResourceCleanupGroupTests/GlTextureOwnershipTests: the two source-text
conformance tests keyed to TextRenderer's old multi-resource
construction shape (Shader + per-flight FrameBufferSet array + white
texture + tracked VAO/VBO, all via ResourceCleanupGroup) no longer apply
- that shape is gone, replaced by one IGpuPipeline created through
IGpuDevice. The construction-order test is deleted; the checked-commit
texture-creation check now targets GlGpuTexture (which already used
the same GlResourceCommand.CreateName primitive before this slice).
Gates:
- dotnet build -c Release: 0 warnings, 0 errors (AcDream.App has
TreatWarningsAsErrors).
- dotnet test tests/AcDream.App.Tests -c Release: 3,840 passed / 3
skipped (was 3,843/3 entering this slice - net 3 fewer tests:
TextRendererFailureSafetyTests.cs deleted (2, tested the now-deleted
TextRenderGlStateScope) plus the one retired ResourceCleanupGroupTests
method). Full solution: 8,908 passed / 5 skipped across all nine test
projects.
- Offline pixel gate (tools/run-offline-pixel-gate.ps1, parent ec414d60
vs this commit): differing fraction 0.318% (1,791/563,200 compared
pixels), above the 0.001 threshold. Investigated pixel-by-pixel rather
than waved through: a diff heatmap plus 4x crops at the differing
clusters show zero differences anywhere in the retained UI, terrain,
scenery, or static meshes - every differing pixel sits on continuously-
animated ambient content (flying-insect sprites over the swamp, foliage
sparkle/dew glints) whose exact phase depends on elapsed wall-clock
time, the same category the gate's own sky-masking rationale already
documents and the campaign doc's coverage table explicitly excludes
("Not covered - particles"). Confirming evidence: two same-commit
captures at HEAD compare clean against each other (0.0025%), and two
same-commit captures at the parent compare clean against each other
(0.0044%) - only base-vs-head is consistently elevated, which is what
frame-pacing drift from genuinely new per-frame RHI work (BeginFrame,
ring resets, the render-state reset above) would produce against a
fixed wall-clock capture deadline, not a rendering defect. Recommend a
quick user visual check of this capture pair alongside the automated
result, matching how V2c's particle work was already handled in this
campaign (flagged for user visual confirmation rather than blocked on
an automated gate that cannot cover animated content).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
ec414d60cd
commit
ceec3bc440
334 changed files with 3660 additions and 3840 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
namespace AcDream.App.UI;
|
||||
|
|
@ -22,7 +22,7 @@ public enum ResizeEdges { None = 0, Left = 1, Right = 2, Top = 4, Bottom = 8 }
|
|||
/// or <see cref="WorldKeyFallThrough"/> event fires so the game world
|
||||
/// (camera, player controller) still receives input.
|
||||
/// </summary>
|
||||
public sealed class UiRoot : UiElement
|
||||
internal sealed class UiRoot : UiElement
|
||||
{
|
||||
public UiRoot()
|
||||
{
|
||||
|
|
@ -32,7 +32,7 @@ public sealed class UiRoot : UiElement
|
|||
/// <summary>Single owner for named retained-window lifecycle and raise policy.</summary>
|
||||
public RetailWindowManager WindowManager { get; }
|
||||
|
||||
// ── Device-level state ───────────────────────────────────────────────
|
||||
// ── Device-level state ───────────────────────────────────────────────
|
||||
public int MouseX { get; private set; }
|
||||
public int MouseY { get; private set; }
|
||||
public bool LeftButtonDown { get; private set; }
|
||||
|
|
@ -42,7 +42,7 @@ public sealed class UiRoot : UiElement
|
|||
/// <summary>Widget currently receiving keyboard events.</summary>
|
||||
public UiElement? KeyboardFocus { get; private set; }
|
||||
|
||||
/// <summary>The edit control activated by Tab/Enter when nothing is focused — retail's
|
||||
/// <summary>The edit control activated by Tab/Enter when nothing is focused — retail's
|
||||
/// chat input "write mode" toggle. Set by the host once the chat window is built.</summary>
|
||||
public UiElement? DefaultTextInput { get; set; }
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ public sealed class UiRoot : UiElement
|
|||
/// True when the pointer is over a widget OR a widget holds mouse capture.
|
||||
/// The host ORs this into the InputDispatcher's WantCaptureMouse gate so game
|
||||
/// actions (movement, world-pick) are suppressed while the user interacts with
|
||||
/// a retail window — mirrors ImGui's WantCaptureMouse.
|
||||
/// a retail window — mirrors ImGui's WantCaptureMouse.
|
||||
/// </summary>
|
||||
public bool WantsMouse => Captured is not null || HitTestTopDown(MouseX, MouseY).element is not null;
|
||||
|
||||
|
|
@ -111,9 +111,9 @@ public sealed class UiRoot : UiElement
|
|||
&& !target.HandlesClick;
|
||||
}
|
||||
}
|
||||
private (uint tex, int w, int h)? _dragGhost;
|
||||
private (GpuTextureSlot tex, int w, int h)? _dragGhost;
|
||||
/// <summary>Snapshotted drag-ghost (tex,w,h), exposed for tests. See BeginDrag.</summary>
|
||||
internal (uint tex, int w, int h)? DragGhostForTest => _dragGhost;
|
||||
internal (GpuTextureSlot tex, int w, int h)? DragGhostForTest => _dragGhost;
|
||||
private UiElement? _lastDragHoverTarget;
|
||||
private int _pressX, _pressY;
|
||||
private bool _dragCandidate;
|
||||
|
|
@ -272,7 +272,7 @@ public sealed class UiRoot : UiElement
|
|||
return false;
|
||||
}
|
||||
|
||||
// ── Per-frame pumping ────────────────────────────────────────────────
|
||||
// ── Per-frame pumping ────────────────────────────────────────────────
|
||||
|
||||
public void Tick(double dt, long nowMs)
|
||||
{
|
||||
|
|
@ -303,7 +303,7 @@ public sealed class UiRoot : UiElement
|
|||
|
||||
public void Draw(UiRenderContext ctx)
|
||||
{
|
||||
// Render children (panels) sorted by z-order — modal last so it
|
||||
// Render children (panels) sorted by z-order — modal last so it
|
||||
// sits on top.
|
||||
DrawSelfAndChildren(ctx);
|
||||
// Second pass: open popups/menus draw ON TOP of the whole tree (so e.g. the
|
||||
|
|
@ -324,12 +324,12 @@ public sealed class UiRoot : UiElement
|
|||
/// never intercepts hit-tests.</summary>
|
||||
private void DrawDragGhost(UiRenderContext ctx)
|
||||
{
|
||||
if (_dragGhost is not { } g || g.tex == 0) return;
|
||||
if (_dragGhost is not { } g || !g.tex.IsAssigned) return;
|
||||
ctx.DrawSprite(g.tex, MouseX - g.w / 2f, MouseY - g.h / 2f, g.w, g.h,
|
||||
0f, 0f, 1f, 1f, new Vector4(1f, 1f, 1f, GhostAlpha));
|
||||
}
|
||||
|
||||
// ── Input entry points (called from GameWindow's Silk.NET handlers) ──
|
||||
// ── Input entry points (called from GameWindow's Silk.NET handlers) ──
|
||||
|
||||
public void OnMouseMove(int x, int y)
|
||||
{
|
||||
|
|
@ -426,7 +426,7 @@ public sealed class UiRoot : UiElement
|
|||
if (target is null)
|
||||
{
|
||||
// Clicking the 3D world exits write mode (no submit) and returns control to
|
||||
// the character — retail blurs the chat input on an outside click.
|
||||
// the character — retail blurs the chat input on an outside click.
|
||||
if (btn == UiMouseButton.Left) SetKeyboardFocus(null);
|
||||
WorldMouseFallThrough?.Invoke(btn, x, y, flags);
|
||||
return;
|
||||
|
|
@ -473,7 +473,7 @@ public sealed class UiRoot : UiElement
|
|||
}
|
||||
else if (target.CapturesPointerDrag || target.HandlesClick)
|
||||
{
|
||||
// The pressed widget owns its pointer interaction — either an interior drag (e.g. text
|
||||
// The pressed widget owns its pointer interaction — either an interior drag (e.g. text
|
||||
// selection, CapturesPointerDrag) or a click it must receive (e.g. a UiButton,
|
||||
// HandlesClick). Either way do NOT move the ancestor window. The already-dispatched
|
||||
// MouseDown + SetCapture(target) let the target handle it; on release OnMouseUp emits
|
||||
|
|
@ -513,7 +513,7 @@ public sealed class UiRoot : UiElement
|
|||
// Deliver TARGET-LOCAL coords (consistent with MouseMove/MouseUp, which use
|
||||
// target.ScreenPosition). HitTestTopDown's lx/ly are relative to the TOP-LEVEL
|
||||
// child, so for a nested target (e.g. the chat view inset inside its window)
|
||||
// they'd be offset by the child's position — which mis-anchored drag-select.
|
||||
// they'd be offset by the child's position — which mis-anchored drag-select.
|
||||
var sp = target.ScreenPosition;
|
||||
var e = new UiEvent(target.EventId, target, rawType,
|
||||
Data0: (int)flags, Data1: (int)(x - sp.X), Data2: (int)(y - sp.Y));
|
||||
|
|
@ -615,7 +615,7 @@ public sealed class UiRoot : UiElement
|
|||
return;
|
||||
}
|
||||
|
||||
// No capture — give the world a chance.
|
||||
// No capture — give the world a chance.
|
||||
WorldMouseFallThrough?.Invoke(btn, x, y, flags);
|
||||
}
|
||||
|
||||
|
|
@ -687,7 +687,7 @@ public sealed class UiRoot : UiElement
|
|||
BubbleEvent(KeyboardFocus, in e);
|
||||
}
|
||||
|
||||
// ── Focus + capture ─────────────────────────────────────────────────
|
||||
// ── Focus + capture ─────────────────────────────────────────────────
|
||||
|
||||
public void SetKeyboardFocus(UiElement? e)
|
||||
{
|
||||
|
|
@ -726,12 +726,12 @@ public sealed class UiRoot : UiElement
|
|||
PointerCaptureChanged?.Invoke(previous, null);
|
||||
}
|
||||
|
||||
// ── Window manager (named top-level windows: Show / Hide / Toggle) ───
|
||||
// ── Window manager (named top-level windows: Show / Hide / Toggle) ───
|
||||
|
||||
// Registry state lives in RetailWindowManager; methods below are compatibility forwarders.
|
||||
|
||||
/// <summary>Register a top-level window under a name for Show/Hide/Toggle.
|
||||
/// Does NOT add it to the tree — the caller mounts via AddChild and controls
|
||||
/// Does NOT add it to the tree — the caller mounts via AddChild and controls
|
||||
/// initial Visible. Idempotent registration returns the existing typed handle;
|
||||
/// replacement performs full lifecycle teardown of the prior registration.</summary>
|
||||
public RetailWindowHandle RegisterWindow(
|
||||
|
|
@ -788,7 +788,7 @@ public sealed class UiRoot : UiElement
|
|||
WindowResized?.Invoke(handle.Name, window);
|
||||
}
|
||||
|
||||
// ── Drag-drop (retail event chain 0x15 → 0x21 → 0x1C → 0x3E) ────────
|
||||
// ── Drag-drop (retail event chain 0x15 → 0x21 → 0x1C → 0x3E) ────────
|
||||
|
||||
private void BeginDrag(UiElement source)
|
||||
{
|
||||
|
|
@ -796,7 +796,7 @@ public sealed class UiRoot : UiElement
|
|||
if (payload is null) { _dragCandidate = false; return; }
|
||||
DragSource = source;
|
||||
DragPayload = payload;
|
||||
_dragGhost = source.GetDragGhost(); // snapshot NOW — the DragBegin handler may empty the source cell
|
||||
_dragGhost = source.GetDragGhost(); // snapshot NOW — the DragBegin handler may empty the source cell
|
||||
var e = new UiEvent(source.EventId, source, UiEventType.DragBegin, Payload: payload);
|
||||
source.OnEvent(in e);
|
||||
// Retail UIElement_ItemList::ItemList_BeginDrag @ 0x004E32D0 selects an
|
||||
|
|
@ -843,7 +843,7 @@ public sealed class UiRoot : UiElement
|
|||
var (t, lx, ly) = HitTestTopDown(x, y);
|
||||
if (t is not null)
|
||||
{
|
||||
// Dropped on a real element — deliver DropReleased; the hit cell's handler places.
|
||||
// Dropped on a real element — deliver DropReleased; the hit cell's handler places.
|
||||
// A non-item target's OnEvent ignores it, so an off-bar drop leaves the lift's removal.
|
||||
var e = new UiEvent(source!.EventId, t, UiEventType.DropReleased,
|
||||
Data1: (int)lx, Data2: (int)ly, Payload: payload);
|
||||
|
|
@ -859,7 +859,7 @@ public sealed class UiRoot : UiElement
|
|||
_lastDragHoverTarget = null;
|
||||
}
|
||||
|
||||
// ── Hover / tooltip ─────────────────────────────────────────────────
|
||||
// ── Hover / tooltip ─────────────────────────────────────────────────
|
||||
|
||||
private void UpdateHover(int x, int y)
|
||||
{
|
||||
|
|
@ -892,7 +892,7 @@ public sealed class UiRoot : UiElement
|
|||
}
|
||||
}
|
||||
|
||||
// ── Helpers ─────────────────────────────────────────────────────────
|
||||
// ── Helpers ─────────────────────────────────────────────────────────
|
||||
|
||||
public void FireEvent(int type, UiElement target, object? payload = null)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue