Getting vertices/polygons after depth buffer test?

I am looking for a way to retrieve all remaining and visible vertices or polygons (better both) after the depth test has been performed. What I require is the amount of vertices that are visible to the view with the current settings in form of vector data(and not as an image)
Is this possible at all with opengl?

No.

Why ? Because depth test is a fragment operation. It does not operates on triangles nor vertices.

But it is fairly easy to remesh a depthmap, if it is useful for you.

Suggestion:

Make one render pass of your scene including the colour buffers if required, which will create a depth image in the z buffer.

The render it again, not writing to any of the buffers, and using occlusion testing - use gl points, and draw a single pixel for each vertex; this should give you a pretty good idea of whether your vertices are hidden.

The render it again, not writing to any of the buffers, and using occlusion testing - this time use polygons, and any polygon where one of more pixels passes the depth test is visible.

Two provisos that I can think of:

  • you’d have to use a depth test that passed equality on the second and third passes, ie. [less than or equal], instead of just [less than].

  • you might have to include a z offset for the vertices testing pass, as I’m not sure whether the z values of a vertex at a given pixel are guaranteed to be the same as the z value of a polygon at that pixel.

There may very well be better ways to do this…

What’s remeshing a depthmap?