Table of Contents

Struct ShapeDrawOptions

Namespace
BSGameLib.Game.Rendering
Assembly
BSGameLib.Game.dll

Describes a shape draw call in a renderer-agnostic way.

public readonly record struct ShapeDrawOptions : IEquatable<ShapeDrawOptions>
Implements
Inherited Members

Constructors

ShapeDrawOptions(ShapePrimitive, ReadOnlyMemory<Vector2>, Rectangle, Vector2, float, int, int, Color, int, Material, ReadOnlyMemory<Color>)

Creates a shape draw from its parts. The static methods make the usual shapes.

public ShapeDrawOptions(ShapePrimitive primitive, ReadOnlyMemory<Vector2> points, Rectangle rectangle, Vector2 center, float radius, int segments, int thickness, Color color, int zIndex = 0, Material material = default, ReadOnlyMemory<Color> colors = default)

Parameters

primitive ShapePrimitive
points ReadOnlyMemory<Vector2>
rectangle Rectangle
center Vector2
radius float
segments int
thickness int
color Color
zIndex int
material Material
colors ReadOnlyMemory<Color>

Exceptions

ArgumentException

material is a sprite material, which draws nothing for a shape.

Properties

Center

The centre of a circle.

public Vector2 Center { get; }

Property Value

Vector2

Color

The colour of the shape. A triangle list uses Colors instead.

public Color Color { get; }

Property Value

Color

Colors

The colour of each vertex of a triangle list, parallel to Points. Empty for the other shapes.

public ReadOnlyMemory<Color> Colors { get; }

Property Value

ReadOnlyMemory<Color>

Material

The material the shape is drawn with. Shape when not given.

public Material Material { get; }

Property Value

Material

Points

The points the shape is built from: the two ends of a line, the corners of a triangle, the position of a point, or the vertices of a triangle list. Empty for the other shapes.

public ReadOnlyMemory<Vector2> Points { get; }

Property Value

ReadOnlyMemory<Vector2>

Primitive

The kind of shape to draw.

public ShapePrimitive Primitive { get; }

Property Value

ShapePrimitive

Radius

The radius of a circle, in pixels.

public float Radius { get; }

Property Value

float

Rectangle

The rectangle that a rectangle shape covers.

public Rectangle Rectangle { get; }

Property Value

Rectangle

Segments

The number of straight sides a circle is drawn with.

public int Segments { get; }

Property Value

int

Thickness

The thickness of a line or outline, or the size of a point, in pixels. Zero for filled shapes.

public int Thickness { get; }

Property Value

int

ZIndex

The order the shape is drawn in, lower values first, within its pass.

public int ZIndex { get; }

Property Value

int

Methods

CircleFilled(Vector2, float, Color, int, int, Material)

A filled circle of radius around center, drawn with segments straight sides.

public static ShapeDrawOptions CircleFilled(Vector2 center, float radius, Color color, int segments = 30, int zIndex = 0, Material material = default)

Parameters

center Vector2
radius float
color Color
segments int
zIndex int
material Material

Returns

ShapeDrawOptions

CircleOutline(Vector2, float, Color, int, int, int, Material)

An outline of a circle of radius around center, drawn with segments straight sides and thickness pixels wide.

public static ShapeDrawOptions CircleOutline(Vector2 center, float radius, Color color, int segments = 30, int thickness = 1, int zIndex = 0, Material material = default)

Parameters

center Vector2
radius float
color Color
segments int
thickness int
zIndex int
material Material

Returns

ShapeDrawOptions

Line(Vector2, Vector2, Color, int, int, Material)

A line from start to end, thickness pixels wide.

public static ShapeDrawOptions Line(Vector2 start, Vector2 end, Color color, int thickness = 1, int zIndex = 0, Material material = default)

Parameters

start Vector2
end Vector2
color Color
thickness int
zIndex int
material Material

Returns

ShapeDrawOptions

Point(Vector2, Color, int, int, Material)

A point at position, size pixels across.

public static ShapeDrawOptions Point(Vector2 position, Color color, int size = 1, int zIndex = 0, Material material = default)

Parameters

position Vector2
color Color
size int
zIndex int
material Material

Returns

ShapeDrawOptions

RectangleFilled(Rectangle, Color, int, Material)

A filled rectangle.

public static ShapeDrawOptions RectangleFilled(Rectangle rectangle, Color color, int zIndex = 0, Material material = default)

Parameters

rectangle Rectangle
color Color
zIndex int
material Material

Returns

ShapeDrawOptions

RectangleOutline(Rectangle, Color, int, int, Material)

An outline of rectangle, thickness pixels wide.

public static ShapeDrawOptions RectangleOutline(Rectangle rectangle, Color color, int thickness = 1, int zIndex = 0, Material material = default)

Parameters

rectangle Rectangle
color Color
thickness int
zIndex int
material Material

Returns

ShapeDrawOptions

TriangleList(ReadOnlyMemory<Vector2>, ReadOnlyMemory<Color>, int, Material)

A triangle list carrying a color per vertex. points is taken three at a time, and colors must be the same length.

public static ShapeDrawOptions TriangleList(ReadOnlyMemory<Vector2> points, ReadOnlyMemory<Color> colors, int zIndex = 0, Material material = default)

Parameters

points ReadOnlyMemory<Vector2>
colors ReadOnlyMemory<Color>
zIndex int
material Material

Returns

ShapeDrawOptions

Remarks

The GPU interpolates color across each triangle, so tessellating a region and evaluating a function per vertex draws any smooth fill with no texture or shader. Callers are expected to reuse their buffers so this costs nothing per frame.

TriangleOutline(Vector2, Vector2, Vector2, Color, int, int, Material)

An outline of the triangle with corners point1, point2 and point3, thickness pixels wide.

public static ShapeDrawOptions TriangleOutline(Vector2 point1, Vector2 point2, Vector2 point3, Color color, int thickness = 1, int zIndex = 0, Material material = default)

Parameters

point1 Vector2
point2 Vector2
point3 Vector2
color Color
thickness int
zIndex int
material Material

Returns

ShapeDrawOptions