Sign in to follow this  
b3rs3rk

Occlusion query

Recommended Posts

b3rs3rk    216
i'm trying to use the GL_ARB_occlusion_query extension, but i've ran in some problems... first of all, here's part of my code:
GLuint nSamples = 0;	
for (uint i= 0; i<GetMeshCount(); i++){
	LMesh &mesh = GetMesh(i);
	if(!g_Camera.BoxInFrustum(mesh.BBoxMin,mesh.BBoxMax))
		continue;
		
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glDepthMask(GL_FALSE);
	glBeginQueryARB(GL_SAMPLES_PASSED_ARB,mesh.occlusionID);
        mesh.DrawBBox();
	glEndQueryARB(GL_SAMPLES_PASSED_ARB);
	glGetQueryObjectuivARB(mesh.occlusionID, GL_QUERY_RESULT_ARB, &nSamples);

	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glDepthMask(GL_TRUE);
	if (nSamples>0){
		mesh.Render();
		VisibleCells++;
	}
	nSamples = 0;
}

works fine but i get a huge fps drop, from ~350 to ~180. I'm rendering 4 buildings (1 texture, 1 lights, nothing more), approx 48k poly, with a GeFo 6600GT (using VBOs). I don't think this is normal so... any advices?

Share this post


Link to post
Share on other sites
_the_phantom_    11250
the problem is you are issuing your query and then asking for the results back right away. This causes a stall in the pipeline while everything which is involved in the query is processed, the results collected and sent back.

Instead of doing it that way the best way todo it is to have a number of queries on the go at once and delay reading from them for as long as you can.

Share this post


Link to post
Share on other sites
b3rs3rk    216
i've changed my code a bit (using some code from the nvidia nature demo), now i use 2 consequent frames to check occlusions. Works fine if i have only one building (every building is composed of multiple meshes), but often a building or two disappears and "pops out" when the camera is quite near...


if(prevView != g_Camera.GetModelView()) {
prevView = g_Camera.GetModelView();

for (uint i= 0; i<GetMeshCount(); i++){
LMesh &mesh = GetMesh(i);
mesh.setVisible(g_Camera.BoxInFrustum(mesh.BBoxMin+m_Position,mesh.BBoxMax+m_Position));
}
queryClock = true;
}
else {
if(queryClock){
for (uint i= 3; i<GetMeshCount(); i++)
GetMesh(i).StopOcclusionQuery();
queryClock = false;
}
}

for (uint i= 0; i<GetMeshCount(); i++){
LMesh &mesh = GetMesh(i);

if(queryClock)
mesh.StartOcclusionQuery();
else
mesh.Render();
}




i use these functions to control the queries:

bool LMesh::StartOcclusionQuery(){
if(!occlusionID || !visible)
return false;

glBeginQueryARB(GL_SAMPLES_PASSED_ARB, occlusionID);
Render();
glEndQueryARB(GL_SAMPLES_PASSED_ARB);

return true;
}

bool LMesh::StopOcclusionQuery()
{
int available = 0;

if(!occlusionID || !visible)
return false;

while(!available)
glGetQueryObjectivARB(occlusionID, GL_QUERY_RESULT_AVAILABLE_ARB, &available);

glGetQueryObjectuivARB(occlusionID, GL_QUERY_RESULT_ARB, &visible);
setVisible(visible);

return true;
}



any advices?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this