View Full Version : questions regarding occlusion queries

08-03-2006, 04:31 AM
i'm still having some trouble with occlusion queries using 'GL_ARB_occlusion_query'. they work fine in general, but sometimes some meshes still seem to be drawn although they are occluded and some others are not rendered although they are visible. i guess this is because not all results are available yet. so i read the spec which suggests the following to check if the results are available yet:

i = N*3/4; // instead of N-1, to prevent the GPU from going idle
do {
glGetQueryObjectivARB(queries[i], GL_QUERY_RESULT_AVAILABLE_ARB, &available);
} while (!available);first of all, 'available' has to be an integer.. so what should it return? 1 if the result is available, 0 otherwise?
i added it to my code, compiled and ran my app, however, it kept freezing, probably because of an infinite loop..

so instead i just placed the occlusion queries at the end of every frame hoping that the results will always be available in the next frame - this works in most cases, but still not 100%.


ah another question - sometimes the result is bigger than the total pixels on the screen, i.e. result > width x height.. how is this possible?

and why are occlusion queries asynchronously at all?

08-03-2006, 05:17 AM
ideas?Did you end your query properly?

Another thing - I hope DoSomeStuff does not use occlusion queries. If it does then you are unlikely to see this loop ever coming to an end.

sometimes the result is bigger than the total pixels on the screenIf you draw a fullscreen quad twice then you will get 2 times more pixels drawn than screen has. I'ts as simple as that.
Occlusion query does not tell you how many pixels are visible on the screen after you are done with drawing but how many pixels were put to screen while drawing.

and why are occlusion queries asynchronouslyBecause GPU and CPU are separate devices and if you won't let them work asynchronously you'll waste a lot of processing power.

08-03-2006, 07:54 AM
Did you check that there is no error reported by any from the occlusion query functions you called?

08-10-2006, 11:47 PM
Just in case the mystery of the oversized result is still bothering you...

Originally posted by Vexator:
sometimes the result is bigger than the total pixels on the screen, i.e. result > width x height.. how is this possible?
Are you multisampling or have you turned on antialiasing via the OpenGL driver?

GL_ARB_occlusion_query says:
If the value of SAMPLE_BUFFERS is 1, then the samples-passed count increases by the number of samples whose coverage bit is set. However, implementations, at their discretion, are allowed to instead increase the samples-passed count by the value of SAMPLES if any sample in the fragment is covered.Try dividing your query result by numSamples after inserting code something like this:

GLint numSamples;
GLint sampleBuffers = -1;
glGetIntegerv(GL_SAMPLE_BUFFERS, &sampleBuffers);
if (sampleBuffers == -1)
cerr << "Error querying multisample SAMPLE_BUFFERS\n";
else if (sampleBuffers == 0)
numSamples = 1;
numSamples = -1;
glGetIntegerv(GL_SAMPLES, &amp;numSamples);
if (numSamples == -1)
cerr << "Error querying multisample SAMPLES\n";