OPENGL ARB_occlusion_query Occlusion Culling

1.6k views Asked by At
for (int i = 0; i < Number_Of_queries; i++)
{
    glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries[i]);

    Box[i]

    glEndQueryARB(GL_SAMPLES_PASSED_ARB);
}

I'm curious about the method suggested in GPU GEMS 1 for occlusion culling where a certain number of querys are performed. Using the method described you can't test individual boxes against each other so are you supposed to do the following?

Test Box A -> Render Box A

Test Box B -> Render Box B

Test Box C -> Render Box C

and so on...

2

There are 2 answers

0
starmole On

I think (it would have been good to link the GPU gems article...) you are confused about somewhat asynchronous queries as described in extensions like this:

http://developer.download.nvidia.com/opengl/specs/GL_NV_conditional_render.txt

If I recall correctly there were other extensions to check for the availability of a result without blocking also.

As Christian Rau points out doing just "query, wait for result, do stuff based on result" might stall and might not be any gain because of that, depending on how much work is in "do stuff". In fact, doing the query, waiting for it to round trip just to save a single draw call is most likely not going to help at all.

0
Christian Rau On

I'm not sure if I understand you correctly, but isn't this one of the drawbacks of the naive implementation of first rendering all boxes (and not writing to depth buffer) and then using the query results to check every object? But your suggestion to use the query result of a single box immediately is an even more naive approach as this stalls the pipeline. If you read this chapter (assuming you refer to chapter 29) further, they present a simple technique to overcome the disadvantages of both naive approaches (that is, just render everything normally and use the query results of the previous frame).