PolylineRenderer class
#include <Jazz2/Rendering/PolylineRenderer.h>
Draws thick antialiased polylines.
A polyline is drawn as a triangle strip across its thickness, sampling a feather texture whose edges fade out, so it has smooth edges at any angle. The commands and the vertices are kept from frame to frame, BeginFrame() starts over. The direct rendering tier has no program to draw the strip with, a polyline has to be rasterized there instead.
The race minimap draws its track this way, and the level editor the path the player took.
Public static functions
-
static auto GetMaxVerticesPerCommand() -> std::
int32_t - Returns the most vertices a single command can draw.
-
static void SmoothCatmullRom(ArrayView<const Vector2f> controlPoints,
std::
int32_t subdivisions, SmallVectorImpl<Vector2f>& out, std:: int32_t maxPoints = INT32_MAX) - Appends a Catmull-Rom spline through the control points to
out. - static void SimplifyRdp(ArrayView<const Vector2f> points, float tolerance, SmallVectorImpl<Vector2f>& out)
- Appends a simplified polyline to
out.
Constructors, destructors, conversion operators
-
PolylineRenderer(std::
int32_t maxVertexFloats = 65536) explicit - Creates a new instance that can draw up to
maxVertexFloatsfloats of vertices a frame, 4 per vertex. - PolylineRenderer(const PolylineRenderer&) deleted
Public functions
- auto operator=(const PolylineRenderer&) -> PolylineRenderer& deleted
- void BeginFrame()
- Starts drawing a new frame, the vertices and commands of the previous one are reused.
- auto GetFeatherTexture() -> Texture&
- Returns the texture that gives the lines their soft edges.
-
auto Draw(ArrayView<const Vector2f> points,
Vector2f offset,
float halfThickness,
std::
uint16_t z, const Colorf& color) -> RenderCommand* - Prepares a command that draws a polyline.
-
auto Draw(ArrayView<const Vector2f> points,
Vector2f offset,
ArrayView<const float> halfThicknesses,
std::
uint16_t z, const Colorf& color) -> RenderCommand* - Prepares a command that draws a polyline of a half-thickness for each of its points.
-
void DrawRange(ArrayView<const Vector2f> points,
std::
int32_t first, std:: int32_t last, ArrayView<const float> halfThicknesses, std:: uint16_t z, const Colorf& color, SmallVectorImpl<RenderCommand*>& commands) - Prepares commands that draw a part of a polyline, from its point
firsttolast, and appends them. -
void DrawMany(ArrayView<const Vector2f> points,
ArrayView<const std::
int32_t> ends, float halfThickness, std:: uint16_t z, const Colorf& color, SmallVectorImpl<RenderCommand*>& commands) - Prepares commands that draw many polylines of the same thickness and color, and appends them.
Function documentation
static std:: int32_t Jazz2:: Rendering:: PolylineRenderer:: GetMaxVerticesPerCommand()
Returns the most vertices a single command can draw.
The vertices of a command are copied into one buffer of the common vertex buffers, with one more float per vertex when it's batched with others, and a command that doesn't fit into one isn't drawn at all.
static void Jazz2:: Rendering:: PolylineRenderer:: SmoothCatmullRom(ArrayView<const Vector2f> controlPoints,
std:: int32_t subdivisions,
SmallVectorImpl<Vector2f>& out,
std:: int32_t maxPoints = INT32_MAX)
Appends a Catmull-Rom spline through the control points to out.
Every segment between two control points is divided into subdivisions points, the last control point is appended at the end. No more segments are started once out holds maxPoints points.
static void Jazz2:: Rendering:: PolylineRenderer:: SimplifyRdp(ArrayView<const Vector2f> points,
float tolerance,
SmallVectorImpl<Vector2f>& out)
Appends a simplified polyline to out.
Ramer-Douglas-Peucker: a point is dropped when it lies within tolerance of the line through its neighbours that are kept. The first and the last point are always kept.
Texture& Jazz2:: Rendering:: PolylineRenderer:: GetFeatherTexture()
Returns the texture that gives the lines their soft edges.
It's white, transparent at U 0 and 1, opaque from U 0.175 to 0.825, the V coordinate doesn't matter.
RenderCommand* Jazz2:: Rendering:: PolylineRenderer:: Draw(ArrayView<const Vector2f> points,
Vector2f offset,
float halfThickness,
std:: uint16_t z,
const Colorf& color)
Prepares a command that draws a polyline.
The points are moved by offset, which saves a copy when they are in another space. Returns the command to queue, or nullptr if there are fewer than two points, more than a command can draw (see GetMaxVerticesPerCommand()) or no room for the vertices left in this frame. The command stays valid until the next BeginFrame().
void Jazz2:: Rendering:: PolylineRenderer:: DrawRange(ArrayView<const Vector2f> points,
std:: int32_t first,
std:: int32_t last,
ArrayView<const float> halfThicknesses,
std:: uint16_t z,
const Colorf& color,
SmallVectorImpl<RenderCommand*>& commands)
Prepares commands that draw a part of a polyline, from its point first to last, and appends them.
The points around the part decide its directions at both ends, so parts drawn one after another, each in a color of its own, join without a seam. A part longer than a command can draw at once is split into several commands that join the same way.
void Jazz2:: Rendering:: PolylineRenderer:: DrawMany(ArrayView<const Vector2f> points,
ArrayView<const std:: int32_t> ends,
float halfThickness,
std:: uint16_t z,
const Colorf& color,
SmallVectorImpl<RenderCommand*>& commands)
Prepares commands that draw many polylines of the same thickness and color, and appends them.
A polyline ends before the point its entry of ends gives, the next one starts there. A polyline that ends where it starts is closed, it has no seam there. As many polylines as a command can draw go into each one.