mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 08:18:20 -04:00
Panel can record custom commandlist like so:
```csharp
public class GlowPanel : Panel, IPanelDraw
{
static Material GlowMat = Material.FromShader( "shaders/ui_glow.shader" );
public void Draw( CommandList cl )
{
cl.Attributes.Set( "GlowColor", Color.Cyan );
cl.DrawQuad( Box.Rect, GlowMat, Color.White );
}
}```
55 lines
1.3 KiB
C#
55 lines
1.3 KiB
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;
|
|
|
|
/// <summary>
|
|
/// The scale factor from logical to physical pixels for the current panel. Set before OnDraw().
|
|
/// </summary>
|
|
public float ScaleToScreen = 1f;
|
|
|
|
/// <summary>
|
|
/// Accumulated CSS opacity for the current panel. Set before OnDraw().
|
|
/// </summary>
|
|
public float Opacity = 1f;
|
|
|
|
/// <summary>
|
|
/// Active blend mode override for the current panel. Set before OnDraw().
|
|
/// </summary>
|
|
public BlendMode OverrideBlendMode = BlendMode.Normal;
|
|
|
|
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 );
|
|
}
|
|
}
|