using OpenTK.Mathematics;
namespace Dashboard.Drawing.OpenGL
{
///
/// The current stack of transformations.
///
public class TransformStack
{
private Matrix4 _top = Matrix4.Identity;
private readonly Stack _stack = new Stack();
///
/// The top-most transform matrix.
///
public ref readonly Matrix4 Top => ref _top;
///
/// The number of matrices in the stack.
///
public int Count => _stack.Count;
///
/// Push a transform.
///
/// The transform to push.
public void Push(in Matrix4 transform)
{
_stack.Push(_top);
_top = transform * _top;
}
///
/// Pop a transform.
///
public void Pop()
{
if (!_stack.TryPop(out _top))
_top = Matrix4.Identity;
}
///
/// Clear the stack of transformations.
///
public void Clear()
{
_stack.Clear();
_top = Matrix4.Identity;
}
}
}