occlusion_query does not count as expected

I’m rendering into a multi-window environment, and am implementing occlusion_query for lens flare effects. I’ve found that if part of a higher lever window covers the occlusion target, the fragment count comes back zero. Occlusion_query is including the effect of the window being covered, not just z-testing in the bounds of the frustum.

Does this make sense? Seems wrong to me. I can effectively eliminate sun glare within a scene by positioning a toolbar over the sun. :confused:

The pixel ownership test is done before the depth test (OpenGL 1.5 spec p171: Per-Fragment Operations).

Based on the diagram on this page, if either one of the pixel ownership , scissor, alpha or stencil test fails, the occlusion query counter will not be increased for those fragments. The spec is not clear what happens for occlusion queries when the depth test is disabled (I would expect it not to count fragments).

The first Per-Fragment Operation is the Pixel Ownership Test. If a pixel is obscured by another window, “…the window system decides the fate of the incoming fragment. Possible results are that the fragment is discarded or that some subset of the subsequent per-fragment operations are applied to the fragment.”

Another way to look at it is the contents of the framebuffer are undefined wherever the ownership test fails. That’s why, with ReadPixels “the results are also undefined for individual pixels that are not owned by the current context.”

So you are damned on two fronts. If ownership fails, the depth test might not be done. If the depth test is done, the results might be undefined.

If you really want the sun under the window to absolutely positively lens flare, you’ll have to render to a pbuffer during the occlusion querry.

-mr. bill