VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Classes | Public Member Functions | List of all members

A class with helper methods for rendering primitives like lines, for debug visualization. More...

Public Member Functions

 DebugRenderer ()
 Constructs a DebugRenderer. More...
 
const Matrix4getProjectionMatrix () 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 &center, float radius, int segments, unsigned int colorRgba)
 Queues a circle centered about a point. More...
 
void queueFilledCircle (const Vector2 &center, 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...
 

Detailed Description

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.

Note
While queuing and rendering can happen on different threads, methods themselves are not thread safe.

Constructor & Destructor Documentation

DebugRenderer::DebugRenderer ( )

Constructs a DebugRenderer.

Member Function Documentation

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.

const Matrix4& DebugRenderer::getProjectionMatrix ( ) const
inline

Gets the current projection matrix.

Returns
The current projection matrix
void DebugRenderer::queueCircle ( const Vector2 center,
float  radius,
int  segments,
unsigned int  colorRgba 
)

Queues a circle centered about a point.

Parameters
centerCenter of circle
radiusRadius of circle
segmentsNumber of segments to draw
colorRgbaColor of the shape
void DebugRenderer::queueFilledCircle ( const Vector2 center,
float  radius,
int  segments,
unsigned int  colorRgba 
)

Queues a filled circle centered about a point.

Parameters
centerCenter of circle
radiusRadius of circle
segmentsNumber of segments to draw
colorRgbaColor of the shape
void DebugRenderer::queueFilledPolygon ( const Vector2 points,
int  count,
unsigned int  colorRgba 
)

Queue a filled convex polygon shape.

Note
The polygon is rendered as a triangle fan, and must be convex to render correctly.
Parameters
pointsList of points forming the polygon
countLength of points
colorRgbaColor of the shape
void DebugRenderer::queueLine ( const Vector2 pos1,
const Vector2 pos2,
unsigned int  colorRgba 
)

Queue a colored line segment.

Parameters
pos1First endpoint
pos2Second endpoint
colorRgbaColor of the segment
void DebugRenderer::queuePolygon ( const Vector2 points,
int  count,
unsigned int  colorRgba 
)

Queue a colored polygon line.

Parameters
pointsList of points forming the polygon
countLength of points
colorRgbaColor 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.

Parameters
matrixThe 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.