Rendering Priority (glPolygonOffset ?)

I’m hoping this isn’t ‘Advanced’!

I’m writing a CAD/CAM application.
I want to prioritise the render order and I’m pretty sure that glPolygonOffset isn’t the answer.
Imagine a solid model cylinder being rendered with facets for the faces and thick lines for the edges; the user selects the curved face on the cylinder and asks for a Surface Object to be created from it. The Surface Object will be Z-fighting the Solid Model and the Edges will be fighting the Faces. Additionally, they may want the edges of the cube to be turned into Line Objects. There are many other depth-types too.

I need the Lines to be visible over the Surface Object and the Surface to be visible over Solid Model Edges and the Solid Model Edges to be visible over the Solid Model Faces when they are at the same Depth-Z.

This isn’t a Depth-Buffer problem, I don’t want to see through anything.

I had some success with glPolygonOffset but there must be a simpler way. I can’t use it for the final release because it breaks the rendering of the solid models (faces vanish near the edges).

Thanks for any help!

Instead of using glPolygonOffset, you can try to modify the projection matrix. This has some advantages. Eric Lengyel offers some nice slides from GDC07:
http://www.terathon.com/pubs.html (see “Projection Matrix Tricks”)

The third method is to play with glDepthRange.

CatDog

I think you can use the stencil buffer to do that with proper mask.

I’m so glad I asked that, modifying the projection matrix seems to fix it with no side-effects!

Needs more testing but looks good.

Thanks, folks!