Is there a GLSL command similar to the discard, but it discards the whole mesh and not just a fragment?

I also think there is no way how to "discard" whole mesh, but you can transform every vertex of the mesh to the same output vertex, so whole mesh will "implode" into one point in space. If you place it behind camera, it will be clipped and not processed.

• Indeed I considered making an edit to suggest that. However, you'd still have to tell the vertex shader which mesh it was processing at the time. Then assuming your trigger to "discard" the mesh is found somewhere along the way during vertex processing, it wouldn't transform the vertices that have already been processed, that's a problem. The counter assumption being that you know ahead of time which mesh is going to be discarded, then why even tell the vertex shader to process it just to transform it to a point? Since you know beforehand, you can just skip the drawing altogether. – MichaelHouse May 22 '12 at 15:26

Well, I'm pretty sure, the fragment shader doesn't have a concept of a mesh. I'm mostly sure the vertex shader doesn't either. You could update the vertex shader to let it know which mesh it's processing via a uniform variable, but I assume you want something all GPU side.

So I believe the answer is, no, it does not. However, I'd love to be wrong, I think that would be pretty useful.

No. Object culling (discarding a whole mesh) must be done before submitting your drawing commands to the GPU.

Remember that the shaders are running at various stages of the pipeline. The vertex shader is run after submitting objects to the GPU. And operates on the vertex level only - it has no cinder of any other vertices, primitives, or the rendered object at all.

The fragment shader runs on fragments only, and has no concept of other fragments, the primitive that created the fragment, the vertices that made the primitive, or the original object.

If you want to selectively disable a mesh based on some kind of GPU processing, you will need to do multiple passes. Things like occlusion queries can be used, or transform feedback.