Code/Internal/DrawState.cs
using System;
using System.Collections.Immutable;
using Sandbox;
using Sandbox.Rendering;
using Goo;
namespace Goo.Internal;
// Snapshot of a panel's resolved custom-draw state, written by the Applier and read by StatefulDrawPanel.Draw. All-default means no user custom draw.
internal readonly struct DrawState : IEquatable<DrawState>
{
public readonly Material? Material;
public readonly ImmutableArray<UniformValue> Uniforms;
public readonly Action<CommandList, Rect>? Draw;
public DrawState(Material? material, ImmutableArray<UniformValue> uniforms, Action<CommandList, Rect>? draw)
{
Material = material;
Uniforms = uniforms;
Draw = draw;
}
public static readonly DrawState Empty
= new(null, ImmutableArray<UniformValue>.Empty, null);
public bool IsEmpty => Material is null && Uniforms.IsDefaultOrEmpty && Draw is null;
public bool Equals(DrawState other)
{
if (!ReferenceEquals(Material, other.Material)) return false;
if (!ReferenceEquals(Draw, other.Draw)) return false;
return UniformValue.SequenceEqual(Uniforms, other.Uniforms);
}
public override bool Equals(object? obj) => obj is DrawState s && Equals(s);
public override int GetHashCode() => HashCode.Combine(Material, Uniforms.Length, Draw);
}