Files
sbox-public/engine/Sandbox.Engine/Systems/UI/Render/PanelRenderer.Background.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

41 lines
1.1 KiB
C#

using Sandbox.Rendering;
namespace Sandbox.UI;
partial class PanelRenderer
{
private void AddBackgroundDescriptor( Panel panel, ref RenderState state, RenderLayer target )
{
if ( panel.HasBackground && panel.ComputedStyle is { } style )
{
panel.BackgroundBlendMode = ParseBlendMode( style.BackgroundBlendMode );
var opacity = state.RenderOpacity;
var desc = CreateBoxDescriptor( panel, style, opacity );
desc.BackgroundBlendMode = panel.BackgroundBlendMode;
var texture = style.BackgroundImage;
if ( texture is not null && texture != Texture.Invalid )
{
desc.BackgroundImage = texture;
desc.BackgroundRect = ImageRect.Calculate( new ImageRect.Input
{
ScaleToScreen = panel.ScaleToScreen,
Image = texture,
PanelRect = panel.Box.Rect,
DefaultSize = Length.Auto,
ImagePositionX = style.BackgroundPositionX,
ImagePositionY = style.BackgroundPositionY,
ImageSizeX = style.BackgroundSizeX,
ImageSizeY = style.BackgroundSizeY,
} ).Rect;
if ( texture.IsDirty )
texture.IsDirty = false;
}
target.AddBox( desc );
}
}
}