PDA

View Full Version : PBuffers and GL_ARB_occlusion_query



hacer
09-16-2004, 04:38 AM
hi.
I have a problem about running occlusion queries when a PBuffer render context is enabled. I could not make occlusion query give proper result, i mean the query result returns 0. (using ARB_occlusion_query extension and PBuffers.) is there anybody who used these two and get proper results?
I run the program on GeForceFX 5200, driver 61.77.

thanks..

Relic
09-16-2004, 05:24 AM
Not sure if this helps, but note that occlusion queries are not shared among contexts because they are small. You need to generate them in the context you use them in.
Other than that make sure that you have allocated a pbuffer with a depth buffer and correctly wait until the results are available like in the examples of the ARB_occlusion_query spec.
Here's what happens if you don't:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=015084

Hampel
09-16-2004, 06:29 AM
But I think for the ARB version of this extension a busy loop til the query result is available should not be necessary any more, shouldn't it? I think the call for the query result will block until the result is available?

Relic
09-16-2004, 06:50 AM
I don't think this changed, because it's still the same hardware running it and the spec has this example:

do {
DoSomeStuff();
glGetQueryObjectivARB(queries[i],
GL_QUERY_RESULT_AVAILABLE_ARB,
&available);
} while (!available);

hacer
09-16-2004, 01:13 PM
thanks for the answers.
I had already defined the query in the current PBuffer render context and waited for the occlusion result as it is mentioned in the extension specs. but it did not work. in my first program with GL_ARB_occlusion_query, there was a strange error that i realized. the code was:
//-----
Display(){
..
GenQuery(&id);

ActivateFragmentShader(); // a Cg program
DrawOccluderObject();
DeactivateFragmentShader();

//write the code for occlusion query
SetColorMask(false);
SetDepthMask(false);
BeginOcclusionQuery(id);
DrawSecondObject();
EndOcclusionQuery();

Flush();
// exacly same as the example given in the specs
GetQueryResult();

SetColorMask(true);
SetDepthmask(true);

// look at the sample_count returned by the query
// and do what you want accordingly
..
}

//----------------

The Fragment Shader mentioned above (written with Cg fp30) only sets the depth and color values. This simple occlusion query program had not worked. when i didn't use Fragment shader it worked fine.. it was strange that only after i added to the begining of the display rutine these lines (below), it started working. ( a dummy begin and end query calls)
//
Display(){
..
GenQuery(&id);

// a dummy BeginQuery and EndQuery..
glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query);
glClearColor (1.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | DEPTH_BUFFER_BIT);
glEndQueryARB(GL_SAMPLES_PASSED_ARB);

// rest is the same as above
ActivateFragmentShader(); // a Cg program
DrawOccluderObject();
DeactivateFr..
.. // same as above

}

that is why i was not sure if occlusion queries run properly inside the pbuffers using Fragment shaders. I still could not fix the problem but I will post a message if I can make it run properly..

thanks

Hampel
09-16-2004, 09:08 PM
@Relic: But this is only an example about not wasting time by waiting for the not yet available query result. IMH, this has nothing to do with the need for an explicit app level busy loop...

hacer
09-17-2004, 01:43 AM
hi.the occlusion query in a PBuffer context finally worked.what i did wrong was trying to render a polygon directly to PBuffer which is defined to be a float buffer. it is said in the NV_float_buffer extension that fragment programs are aloowed to read and write from floating point PBuffers. problem is eliminated with using a generic fragment program to render polygons. When the data is not written to the buffer occlusion seemed not working to me.
interesting thing still is the need to call dummy Begin and End queries at the begining of the rendering part.. occlusion queries seemed not working without these dummy calls. any idea about this?