using System;
using System.Diagnostics;
using Robust.Client.Graphics.Shaders;
using Robust.Shared.Maths;
namespace Robust.Client.Graphics.Drawing
{
///
/// 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(Vector2 position, Angle rotation, Vector2 scale)
{
CheckDisposed();
var matrix = Matrix3.Identity;
(matrix.R0C0, matrix.R1C1) = scale;
matrix.Rotate(rotation);
matrix.R0C2 += position.X;
matrix.R1C2 += position.Y;
SetTransform(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;
}
}
}