Debug DrawList

Haiku provides a simple drawlist to display primitives using GL_POINTS and GL_LINES.

Here you can see an example of how to use the API:

/* Declarations (in IApplication attributes) */
DefaultCamera   m_camera;
DebugDrawList * m_drawlist;
...

/* Creation (in IApplication::Create) */
m_drawlist = DebugDraw::Create(true);
...

/* Rendering (in IApplication::Render) */
DebugDraw::PushSphereAxis(m_drawlist,1.f);
DebugDraw::PushPlaneAxis(m_drawlist);
DebugDraw::PushPoint(m_drawlist,vec3(1.f,1.f,1.f), vec3(1.f,0.f,0.f));
DebugDraw::PushLine(m_drawlist,vec3(0.f,0.f,0.f),vec3(0.f,0.f,0.f), vec3(1.f,0.f,0.f));
DebugDraw::Render(
    m_drawlist,
    Camera::View(&m_camera),
    Camera::Proj(&m_camera)
);

/* Cleanup (in IApplication::Destroy) */
DebugDraw::Destroy(m_drawlist);

As you can see, primitives are pushed and rendered in the drawloop. Internal implementation flushes all primitives each frame, to enable simple animations.

This choice was motivated by debugging reasons.

Drawlist creation/destruction

This drawlist API is one of the only ones that provides an opaque pointer that must be passed to the DebugDraw:: functions.

This opaque pointer is heap-allocated by the current implementation. Deallocation is performed when DebugDraw::Destroy is called.

Remember that during debugging, if the application quits unexpectedly (i.e. crashes), the OS will clean up the memory leak caused.

This choice was motivated by multiple changes of implementation.

DebugDrawList * m_drawlist = DebugDraw::Create();

If your hardware supports GL_LINE_SMOOTH, you can enable it using a boolean parameter to the creation function.

DebugDrawList *Haiku::Graphics::DebugDraw::Create(bool gl_smooth_line = false)

Creates a debug draw handle (performs 1 allocation)

void Haiku::Graphics::DebugDraw::Destroy(DebugDrawList *handle)

Destroy a debug draw handle (performs 1 deallocation)

Drawlist rendering

At the end of drawloop, you only have to call the DebugDraw::Render function by passing camera view and projection matrices.

void Haiku::Graphics::DebugDraw::Render(DebugDrawList *handle, float *view_matrix, float *proj_matrix)

Renders pushed primitives and reset the buffer for next frame.

Drawlist primitives

Points:

../_images/points.png
void Haiku::Graphics::DebugDraw::PushPoint(DebugDrawList *handle, const Maths::Vec3f &position, const Maths::Vec3f &color)

Pushes a point to render at position with the requested color.

Lines:

../_images/lines.png
void Haiku::Graphics::DebugDraw::PushLine(DebugDrawList *handle, const Maths::Vec3f &from, const Maths::Vec3f &to, const Maths::Vec3f &color1, const Maths::Vec3f &color2)

Pushes a line to render between two positions with the requested gradient.

void Haiku::Graphics::DebugDraw::PushLine(DebugDrawList *handle, const Maths::Vec3f &from, const Maths::Vec3f &to, const Maths::Vec3f &color)

Pushes a line to render between two positions with the requested color.

Frame/Axis:

../_images/axis.png
void Haiku::Graphics::DebugDraw::PushWorldAxis(DebugDrawList *handle)

Pushes the world axis to render.

void Haiku::Graphics::DebugDraw::PushAxis(DebugDrawList *handle, const float *transform)

Pushes an axis to render with the following transformation matrix.

void Haiku::Graphics::DebugDraw::PushFrame(DebugDrawList *handle, const Maths::Frame3f &frame, const Maths::Vec3f &origin, const float scale = 0.1f)

Pushes a frame to render.

World Spherical Axis:

../_images/sphere_axis.png
void Haiku::Graphics::DebugDraw::PushSphereAxis(DebugDrawList *handle, float radius, int nof_lines = 32)

Pushes a sphere axis to render.

void Haiku::Graphics::DebugDraw::PushSphere(DebugDrawList *handle, const Maths::Vec3f &center, float radius, const Maths::Vec3f &color, int nof_lines = 32)

Pushes a dummy sphere.

World Planar Axis:

../_images/plane_axis.png
void Haiku::Graphics::DebugDraw::PushPlaneAxis(DebugDrawList *handle)

Pushes a plane axis to render.

Bounding Box:

../_images/box.png
void Haiku::Graphics::DebugDraw::PushBox(DebugDrawList *handle, const Maths::AABB &box, const float *transform, const Maths::Vec3f &color)

Pushes a box to render.

Normal (with planar disk):

../_images/normal_disk.png
void Haiku::Graphics::DebugDraw::PushNormal(DebugDrawList *handle, const Maths::Vec3f &position, const Maths::Vec3f &normal, const Maths::Vec3f &color, float radius = 1.f)

Pushes a normal and a planar disk.

Normal (with planar square):

../_images/normal_square.png
void Haiku::Graphics::DebugDraw::PushNormal(DebugDrawList *handle, const Maths::Vec3f &position, const Maths::Vec3f &normal, const Maths::Vec3f &color, uint32_t seed, float alpha)

Pushes a normal and a planar square.

Circle:

../_images/circle.png
void Haiku::Graphics::DebugDraw::PushCircle(DebugDrawList *handle, float radius, const Maths::Vec3f &color, const float *model, int nof_lines = 32)

Pushes a circle to render.

void Haiku::Graphics::DebugDraw::PushCircle(DebugDrawList *handle, const Maths::Vec3f &center, const Maths::Vec3f &normal, float radius, const Maths::Vec3f &color, int nof_lines = 32)

Pushes a circle to render.

Spherical Arc:

../_images/arc.png

Warning

doxygenfunction: Cannot find function “Haiku::Graphics::DebugDraw::PushArc” in doxygen xml output for project “haiku” from directory: /builds/cavalier/haiku-hpp/build/docs//xml