using System;
using System.Diagnostics;
using Robust.Shared.Maths;
namespace Robust.Client.Graphics
{
///
/// Used for doing direct drawing without sprite components, existing GUI controls, etc...
///
public abstract class DrawingHandleBase : IDisposable
{
//private protected IRenderHandle _renderHandle;
private protected readonly int _handleId;
public bool Disposed { get; private set; }
public Color Modulate { get; set; } = Color.White;
public void Dispose()
{
Disposed = true;
}
public void SetTransform(in Vector2 position, in Angle rotation, in Vector2 scale)
{
CheckDisposed();
var matrix = Matrix3.CreateTransform(in position, in rotation, in scale);
SetTransform(in matrix);
}
public void SetTransform(in Vector2 position, in Angle rotation)
{
var matrix = Matrix3.CreateTransform(in position, in rotation);
SetTransform(in matrix);
}
public abstract void SetTransform(in Matrix3 matrix);
public abstract void UseShader(ShaderInstance? shader);
///
/// Draws arbitrary geometry primitives with a flat color.
///
/// The topology of the primitives to draw.
/// The set of vertices to render.
/// The color to draw with.
public abstract void DrawPrimitives(DrawPrimitiveTopology primitiveTopology, ReadOnlySpan vertices,
Color color);
///
/// Draws arbitrary indexed geometry primitives with a flat color.
///
/// The topology of the primitives to draw.
/// The indices into to render.
/// The set of vertices to render.
/// The color to draw with.
public abstract void DrawPrimitives(DrawPrimitiveTopology primitiveTopology, ReadOnlySpan indices,
ReadOnlySpan vertices, Color color);
///
/// Draws arbitrary geometry primitives with a texture.
///
/// The topology of the primitives to draw.
/// The texture to render with.
/// The set of vertices to render.
/// The color to draw with.
public abstract void DrawPrimitives(DrawPrimitiveTopology primitiveTopology, Texture texture,
ReadOnlySpan vertices, Color? color = null);
///
/// Draws arbitrary geometry primitives with a flat color.
///
/// The topology of the primitives to draw.
/// The texture to render with.
/// The indices into to render.
/// The set of vertices to render.
/// The color to draw with.
public abstract void DrawPrimitives(DrawPrimitiveTopology primitiveTopology, Texture texture,
ReadOnlySpan indices,
ReadOnlySpan vertices, Color? color = null);
[DebuggerStepThrough]
protected void CheckDisposed()
{
if (Disposed)
{
throw new ObjectDisposedException(nameof(DrawingHandleBase));
}
}
public abstract void DrawCircle(Vector2 position, float radius, Color color, bool filled = true);
public abstract void DrawLine(Vector2 from, Vector2 to, Color color);
}
///
/// 2D Vertex that contains both position and UV coordinates.
///
public struct DrawVertexUV2D
{
public Vector2 Position;
public Vector2 UV;
public DrawVertexUV2D(Vector2 position, Vector2 uv)
{
Position = position;
UV = uv;
}
}
}