For every shape we check whether the shape was detected as "visible" by occlusion query in the previous frame.
-
If the shape was visible in the previous frame, then we render it as usual in the current frame.
-
If the shape was not visible in the previous frame, we render merely the bounding box of the shape (but this box is not actually visible in the color buffer — we render it only for the "occlusion query").
In both cases (rendering actual shape, rendering bounding box) we surround the render call with a special commands such that the visibility flag in updated based on whether the shape (or it’s bounding box) is visible, i.e. some pixels pass the depth test.
Note that this algorithm happens after the frustum culling has eliminated shapes that are definitely not visible because they are not within the viewing frustum. That is, frustum culling (that we do both per-scene and per-shape, by default) works as it did, and it remains a very useful algorithm — eliminating things earlier, with less hassle. The primary job of occlusion query is to eliminate shapes that are within the frustum, but are obscured by something else.