Jump to content
  • Advertisement
Sign in to follow this  
dnaxx

GL_*_occlusion_query questions

This topic is 4431 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I am using (/trying to use) GL_ARB_occlusion_query for a simple occlusion test. An object is completely behind a terrain hill but the occlusion test does not detect the occlusion. Another object that moves with the camera is sometimes marked as occluded, when just a part of this model is occluded by a small hill. Can someone explain me please, why such things happen? thank you,

Share this post


Link to post
Share on other sites
Advertisement
it's just taken from the sgi documentation:


GLuint queries = 0;
GLuint sampleCount;

glGenQueriesARB(1, &queries);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST);

glBeginQueryARB(GL_SAMPLES_PASSED_ARB, queries);
// Draw model here
...

glEndQueryARB(GL_SAMPLES_PASSED_ARB);

glEnable(GL_BLEND);
glEnable(GL_STENCIL_TEST);

glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

glGetQueryObjectuivARB(queries, GL_QUERY_RESULT_ARB, &sampleCount);
if (sampleCount <= 0)
{
return;
}
// Draw object here


Share this post


Link to post
Share on other sites
You don't need to do the more complicated query you are currently doing, if you just want to know if the object is visible.

Try this one, works fine for me. Where in the scheme of things are you doing your query?


GLboolean CCamera::OcclusionQueryMesh( CVector3 pos, CVector3 rot, t3DObject *pObject )
{
GLboolean result;

glDepthMask(GL_FALSE);
glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);

glEnable(GL_OCCLUSION_TEST_HP);

glDrawElements( GL_TRIANGLES, pObject->numOfFaces * 3,
GL_UNSIGNED_INT, pObject->pIndices);

glDisable(GL_OCCLUSION_TEST_HP);

glDepthMask(GL_TRUE);
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);

glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP, &result);

return(result);
}







You are currently getting a return value of the amount of pixels that are rendered.

Share this post


Link to post
Share on other sites
thanks but your code gives the same results.

My rendering order looks like this:
- Render Terrain (which occludes some objects)
- Switch to occlusion test mode, draw object that can be occluded
- if object is occluded, then don't draw it, else draw object.

Share this post


Link to post
Share on other sites
u have to see also if the result of the query is avialable yet (check the spec on howto)
its not instant (i believe theres something like this coming)

eg u should have the follwoing

lots of objects
{
begin query
draw obj
end query
}

// do stuff

see if the result is available
query result

Share this post


Link to post
Share on other sites
Quote:
Original post by zedzeek
u have to see also if the result of the query is avialable yet (check the spec on howto)


No he doesnt have to check whether the query result is available or not. When he calls

glGetQueryObjectuivARB(queries, GL_QUERY_RESULT_ARB, &sampleCount);

then the calling thread automaticaly waits till the result is available.

[Edited by - Trahern on April 7, 2006 4:53:49 PM]

Share this post


Link to post
Share on other sites
Which is not a good thing™.

One solution is to send the queries in the current frame, and then check for the results at the beginning of the next frame and then take appropriate action. This way occlusion queries are almost free.

Disadvantage is that if the camera suddenly rotates by a large margin or cuts to another angle, there will be 1 frame with incorrect results, but with games running at 60fps, this will be barely noticable.

Share this post


Link to post
Share on other sites
Quote:
Original post by GamerSg
Which is not a good thing™.

One solution is to send the queries in the current frame, and then check for the results at the beginning of the next frame and then take appropriate action. This way occlusion queries are almost free.

Disadvantage is that if the camera suddenly rotates by a large margin or cuts to another angle, there will be 1 frame with incorrect results, but with games running at 60fps, this will be barely noticable.


yes, but it does not take effect on my problem ;).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!