Although I’m sure a lot of people just grab the basic line-drawing debug renderer from XNA to use, here’s one for dealing with a lot more.
It’s drop in, draws both triangles and lines, works with BasicEffect
, and you can decide under what depth conditions to draw.
Should be really useful to anyone whose trying to figure out how 3d space/math works without fighting with models and textures.
- Doesn’t mess with GPU state until you call
Render()
- Clear it with
Begin()
at the start of a frame and go,Render()
whenever you’re ready (probably the very last thing you do)
- Clear it with
- Little Hassle, slap it in - read and start drawing
- See the example in the XML-comments on setting up for stock
BasicEffect
(relies on BasicEffect naming convention of WorldViewProj for other effects to work)
- See the example in the XML-comments on setting up for stock
- Configurable depth mode
-
DebugDrawDepth.Pass
= regular old depth test -
DebugDrawDepth.Always
= no depth test or write -
DebugDrawDepth.Fail
= depth test for Greater-Equal - Effects can be set for each mode
- You might want some screenspace hatching for depth Fail, UE4 style - Trivial to expand if necessary (stencil, etc), it’s just arrays indexed by an enum
-
- Draws triangles too
- Trivial to add additional drawing functions
- Doesn’t bother with indices, does mean the vertex-buffers are fatter
- Most shapes just call the basic
DrawLine
andDrawTriangle
functions, easy
- Most shapes just call the basic
- Helper
DrawWireShape
for working with indexed points (Frustum, BoundingBox, etc) - Helper for parametric (stack/slice) mesh shapes
- Doesn’t bother with indices, does mean the vertex-buffers are fatter
- Recording
- Capture clones of the generated data to reuse later
- Can use throwaway DebugRenderer instances just to build cached data, if a DebugRenderer doesn’t get rendered then graphics resources aren’t created
- Useful for debugging ephemeral things, record some draw data and keep it around for a while
Cyan triangle drawn as depth-pass, dark portion drawn as depth-fail, and similar with the curve