VoltAir
|
A class with helper methods for rendering primitives like lines, for debug visualization. More...
Public Member Functions | |
DebugRenderer () | |
Constructs a DebugRenderer. More... | |
const Matrix4 & | getProjectionMatrix () const |
Gets the current projection matrix. More... | |
void | setProjectionMatrix (const Matrix4 &matrix) |
Sets the current projection matrix. More... | |
void | queueLine (const Vector2 &pos1, const Vector2 &pos2, unsigned int colorRgba) |
Queue a colored line segment. More... | |
void | queuePolygon (const Vector2 *points, int count, unsigned int colorRgba) |
Queue a colored polygon line. More... | |
void | queueFilledPolygon (const Vector2 *points, int count, unsigned int colorRgba) |
Queue a filled convex polygon shape. More... | |
void | queueCircle (const Vector2 ¢er, float radius, int segments, unsigned int colorRgba) |
Queues a circle centered about a point. More... | |
void | queueFilledCircle (const Vector2 ¢er, float radius, int segments, unsigned int colorRgba) |
Queues a filled circle centered about a point. More... | |
void | flush () |
Flushes the current shape being queued, preventing additional vertices from getting added to that draw call. More... | |
void | synchronizeForRendering () |
Flips double buffered data, and clears the current queue. More... | |
void | render () |
Renders draw calls in the render queue. More... | |
A class with helper methods for rendering primitives like lines, for debug visualization.
This class stores a list of draw calls and vertices, each double buffered. When shapes are queued for rendering, they are added to these lists. A call to synchronizeForRender() moves currently queued data into the double buffer for rendering. Calls to render() then render this data. This allows shapes to be queued at any time, and rendering to be performed safely on a separate render thread.
DebugRenderer::DebugRenderer | ( | ) |
Constructs a DebugRenderer.
void DebugRenderer::flush | ( | ) |
Flushes the current shape being queued, preventing additional vertices from getting added to that draw call.
This is done implicitly as necessary and is not normally necessary.
|
inline |
Gets the current projection matrix.
void DebugRenderer::queueCircle | ( | const Vector2 & | center, |
float | radius, | ||
int | segments, | ||
unsigned int | colorRgba | ||
) |
Queues a circle centered about a point.
center | Center of circle |
radius | Radius of circle |
segments | Number of segments to draw |
colorRgba | Color of the shape |
void DebugRenderer::queueFilledCircle | ( | const Vector2 & | center, |
float | radius, | ||
int | segments, | ||
unsigned int | colorRgba | ||
) |
Queues a filled circle centered about a point.
center | Center of circle |
radius | Radius of circle |
segments | Number of segments to draw |
colorRgba | Color of the shape |
void DebugRenderer::queueFilledPolygon | ( | const Vector2 * | points, |
int | count, | ||
unsigned int | colorRgba | ||
) |
Queue a filled convex polygon shape.
points | List of points forming the polygon |
count | Length of points |
colorRgba | Color of the shape |
void DebugRenderer::queueLine | ( | const Vector2 & | pos1, |
const Vector2 & | pos2, | ||
unsigned int | colorRgba | ||
) |
Queue a colored line segment.
pos1 | First endpoint |
pos2 | Second endpoint |
colorRgba | Color of the segment |
void DebugRenderer::queuePolygon | ( | const Vector2 * | points, |
int | count, | ||
unsigned int | colorRgba | ||
) |
Queue a colored polygon line.
points | List of points forming the polygon |
count | Length of points |
colorRgba | Color of the shape |
void DebugRenderer::render | ( | ) |
Renders draw calls in the render queue.
This method renders shapes that were previously moved on to the render queue by a call to synchronizeForRendering().
void DebugRenderer::setProjectionMatrix | ( | const Matrix4 & | matrix | ) |
Sets the current projection matrix.
This matrix transforms all shapes queued while it is set. When the matrix changes, subsequent queued shapes will be transformed with the new matrix. This means that multiple matrices can be used within a single frame. This can be useful, for example, when rendering debug shapes for a camera relative scene and then a screen relative UI.
matrix | The matrix to set as current |
void DebugRenderer::synchronizeForRendering | ( | ) |
Flips double buffered data, and clears the current queue.
Draw data that was previous queued will be moved to the render queue, and subsequent calls to render() will draw those shapes. This method signals the end of debug drawing for the current frame. Draw calls issued after calling this method will get rendered in the next frame.