Sign in to follow this  
Alessandro

ARB occlusion query help needed

Recommended Posts

I'm trying (and trying and trying) to use occlusion query with a terrain engine. For the sake of simplicity, i suppose the terrain is a 64x64 regular grid, and i have a simple quad that i use as an occluder: terrain quads behind the occluder quad, must not be rendered. The problem is that when i move the occluder quad around, all the terrain quads are rendered. Even if the occluder quad covers all the screen, fps tell that the terrain is there ... I'm showing the init() and render() routines, which are quite simple, i can't figure out why it doesn't work. Thanks for any help, i've been trying all the weekend to make it work and i didn't succeed ! Oh, BTW, occlusion query is supported from my vga card.
init()
{
    #define MAX_QUERIES 32*32
    GLuint QO_terrain[MAX_QUERIES];
    glGenQueriesARB( MAX_QUERIES, QO_terrain );
}


render()
{
     int MAP_SIZE = 32;
     Draw_Occluder_Quad();
     
// run occlusion query
     int qindex=0;
     glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
     glDepthMask(GL_FALSE);
	
	for (int i=-MAP_SIZE/2; i<MAP_SIZE/2; i++)
	{
		for (int j=-MAP_SIZE/2; j<MAP_SIZE/2; j++)
		{	
			glBeginQueryARB( GL_SAMPLES_PASSED_ARB, QO_terrain[qindex]);
			glBegin(GL_QUADS);
			glVertex3f(j+0,i+0,0);
			glVertex3f(j+1,i+0,0);
			glVertex3f(j+1,i+1,0);
			glVertex3f(j+0,i+1,0);
			glEnd();
			glEndQueryARB( GL_SAMPLES_PASSED_ARB );
			qindex++;
		}	
	}
	

	
    // render visible terrain
    qindex=0;
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glDepthMask(GL_TRUE);
	
	for (int i=-MAP_SIZE/2; i<MAP_SIZE/2; i++)
	{
		for (int j=-MAP_SIZE/2; j<MAP_SIZE/2; j++)
		{
			glGetQueryObjectuivARB( QO_terrain[qindex], GL_QUERY_RESULT_ARB, &terrainFragmentCount);	// get occlusion query results
			if (terrainFragmentCount>0)		// if fragments are visible, render the terrain patch
			{
			glBegin(GL_QUADS);
			glVertex3f(j+0,i+0,0);
			glVertex3f(j+1,i+0,0);
			glVertex3f(j+1,i+1,0);
			glVertex3f(j+0,i+1,0);
			glEnd();
			}
			qindex++;
		}	
	}
}


Share this post


Link to post
Share on other sites
what i can suggest is to create a lower detail version of your terrain which you can used as the collision mesh for the terrain. Then on Every frame render all the collision meshes that makes up the sceene between and glBeginQuery and glEndQuery. Then what you do is check each Object and see if they have any visible pixel on screen. If the visible pixel for the object is >0 then you know it is visible otherwise it is not. So what you need to do is check each object and if there is some pixels that are visible batch that object into a list and keep on doing that until you check all the objects. Once you are done, you can just render the ojbect list, which you know will only holds only the meshes that are visible. One word of advice try to make you collision meshes as low as possible so for rendering purposes it won't take too much processing power.

By the way looking at your code i see that you are doing things in Immediate mode which is slow, i would suggest you batch the terrain and draw it using Vertex/Index Buffers.

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