Jump to content
  • Advertisement
Sign in to follow this  
anayghotikar

Help required with Occlusion Queries

This topic is 2495 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

Hi,

I need some help with occlusion queries. I am trying to get the visibility of certain objects in a scene. I need to calculate the visibility of each object from a single point. For this, I am using occlusion queries. Following is the code:


for (int i = 0; i < wt; i++)
{
for (int j = ht; j >= 0; j--)
{
cellX = i; cellY = dimY - j;
if (pf->getCellTypeAt(cellX, cellY) == PP::Cell::T_FREE)
{
if (eyeloc.eof())
break;
else
eyeloc>>eyeX>>eyeZ; // Read from a file
vis<<"---------------------------------------------- Cell: ("<<cellX<<", "<<cellY<<") ----------------------------------------------"<<endl;
for (vector<char*>::iterator it = selectedObjects.begin(); it != selectedObjects.end(); it++)
{
PP::Vec3f objCenter = getObjectCenter(pmodel, *it);
vis<<"******** EYE--> x:"<<eyeX<<"\ty:"<<viewHeight<<"\tz:"<<eyeZ<<" ********"<<endl;
gluLookAt(eyeX, viewHeight, eyeZ, objCenter._v[0], objCenter._v[1], objCenter._v[2], 0, 1, 0);
visibility = 0.0f;
obj_samples = 0;
totalPixels = renderedPixels = 0;

string obj(*it);
object = new char [obj.size()+1];
strcpy (object, obj.c_str());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Render the object first, to get the total number of pixels
//glPushMatrix();
glBeginQueryARB(GL_SAMPLES_PASSED_ARB, oq_Objects[count]);
drawObject(pmodel, object, mode);
glEndQueryARB(GL_SAMPLES_PASSED_ARB);
//glPopMatrix();
glGetQueryObjectuivARB(oq_Objects[count], GL_QUERY_RESULT_ARB, &obj_samples);

totalPixels = obj_samples;
obj_samples = 0;
count++;

// Render the object after rendering the modified scene to get the pixels drawn after occlusion
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw the scene excluding the specified object
//glPushMatrix();
drawModifiedScene(pmodel, mode, object);
glBeginQueryARB(GL_SAMPLES_PASSED_ARB, oq_Objects[count]);
drawObject(pmodel, object, mode);
glEndQueryARB(GL_SAMPLES_PASSED_ARB);
//glPopMatrix();
glGetQueryObjectuivARB(oq_Objects[count], GL_QUERY_RESULT_ARB, &obj_samples);

renderedPixels = obj_samples;
count++;

if (totalPixels != 0)
visibility = (float) renderedPixels/totalPixels;
delete [] object;
}
}
}
}


Count is a variable defined outside the loop. oq_objects is initialized as follows in another function:


GLuint* oq_Objects;
oq_Objects = (GLuint*) malloc(sizeof(GLuint)*size);
if (oq_Objects == 0)
{
cout<<"Memory could not be allocated!!"<<endl;
exit(1);
}
glGenQueriesARB(size, oq_Objects);


The problem is that the occlusion query works only for the 1st time i.e. only for the 1st iteration. For all the other calls I get the same value as the result of the 1st iteration.
Can someone please tell me where I am going wrong?

Thanks,
Anay

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!