Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Render/UIDrawBuffer.cs
Matt Stevens a7a30ec6c7 Deferred UI batching and blendmode fixes (#4563)
* Deferred UI batching: collect everything first, sort by z, pass, blend mode (things that break batches) and flush as normal

  Before: https://files.facepunch.com/matt/1b2211b1/Discord_9fs860ZoeI.png
  After: https://files.facepunch.com/matt/1b2211b1/sbox_4vRV3zteqM.png
* Various blend mode fixes with the new UI batcher
* OverrideBlendMode in descriptors was ignored
* Panel.Draw.Text was missing PremultiplyAlpha = true
* UIBatcher flushes batch when blend mode changes (this is a bit wanky)
* ui_cssbox_batched.shader did not handle premultiplied backgrounds
* handle z-depth properly for text

---------

Co-authored-by: antopilo <mail@antopilo.dev>
2026-04-22 20:35:05 +01:00

40 lines
885 B
C#

using Sandbox.Rendering;
namespace Sandbox.UI;
/// <summary>
/// Thread-local buffer for collecting UI draw descriptors during panel.OnDraw().
/// Descriptors are routed directly to the active RenderLayer.
/// </summary>
internal class UIDrawBuffer
{
[ThreadStatic] static UIDrawBuffer _current;
internal static UIDrawBuffer Current => _current ??= new();
/// <summary>
/// The target layer for draw calls. Set by the renderer before OnDraw().
/// </summary>
public RenderLayer ActiveLayer;
public void AddBox( in BoxDrawDescriptor desc )
{
ActiveLayer.AddBox( desc );
}
public void AddShadow( in ShadowDrawDescriptor desc )
{
ActiveLayer.AddShadow( desc );
}
public void AddOutline( in OutlineDrawDescriptor desc )
{
ActiveLayer.AddOutline( desc );
}
public void AddBackdrop( in BackdropDrawDescriptor desc )
{
ActiveLayer.Backdrops.Add( desc );
}
}