#### Archived

This topic is now archived and is closed to further replies.

# NV_OCCLUSION_QUERY extention for occlusion culling

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

## Recommended Posts

Hi, I want to use the NV_OCCLUSION_QUERY extention for occlusion culling in an octree (with front to back rendering) This is the source code for rendering the AABB containing the triangles, and testing if they are visible. glDisable(GL_CULL_FACE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); glDepthMask(GL_FALSE); glBeginOcclusionQueryNV(cull_box2); glPushMatrix(); glTranslatef(bb.mid[0],bb.mid[1],bb.mid[2]); glScalef(bb.len[0],bb.len[1],bb.len[2]); glutSolidCube(1.0); glPopMatrix(); glEndOcclusionQueryNV(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); glEnable(GL_CULL_FACE); GLuint pixelCount=0; glGetOcclusionQueryuivNV( cull_box2 , GL_PIXEL_COUNT_NV, &pixelCount); if (pixelCount>pixel_threshold) render triangles of AABB with display list Problem is, the code is slower with culling then without occlusion culling (just rendering with display list), even though a lot less triangles are rendered with occlusion culling. Especially when de depth of the octree is getting bigger (>4) it slows very much (i guess because of the begin- and end-occlusion query, i used some timing queries to find out where the bottleneck was). Note that with depth 2 of 3 (not too many occlusion querys) there is a significant win over non occlusion culling when e.g. inside a certain model, but with larger octree depths the overhead of occlusion queries and octree seem to win, and there are less fps. In nvidia slides (http://www.nvidia.com/dev_content/gdc2002/GDC2002_occlusion_files/frame.htm) was a note : "Do other CPU computation while queries are being made " Should i use a separate thread to perform the occlusion queries, or do the occlusion queries already run in an seperate thread ? Is it normal that the queries become a bottleneck when used frequently ? With large octree depth, octree rendering without culling is even faster then with culling (with queries). With depth 5 there are like 1000''s / 10000''s of occlusion queries. Can this be a bottleneck ? How can i fix this problem ? tia, and merry christmas Roel Martens

##### Share on other sites
You can try interleaving the querries:

int num_octree_nodes = 8; /* typical value */for (i = 0; i < num_octree_nodes; i++) {   glBeginOcclusionQueryNV(cull_box);   glPushMatrix();   glTranslatef(bb.mid[0],bb.mid[1],bb.mid[2]);   glScalef(bb.len[0],bb.len[1],bb.len[2]);   glutSolidCube(1.0);   glPopMatrix();   glEndOcclusionQueryNV();}for (i = 0; i < num_octree_nodes; i++) {   GLuint pixelCount=0;   glGetOcclusionQueryuivNV(cull_box[i] , GL_PIXEL_COUNT_NV, &pixelCount);   if (pixelCount>pixel_threshold)      render triangles of AABB with display list}

Note that glGetOcclusionQueryuivNV implies a glFlush, which is why your current code is slower.

##### Share on other sites
To add to my last post, you cuold probably split that last loop in two to not have the glFlush overhead inserted in your render loop.
GLuint pixelCount[num_octree_nodes];for (i = 0; i < num_octree_nodes; i++) {   glGetOcclusionQueryuivNV(cull_box , GL_PIXEL_COUNT_NV, &pixelCount[i]);}for (i = 0; i < num_octree_nodes; i++) {   if (pixelCount[i]>pixel_threshold)      render triangles of AABB with display list}

##### Share on other sites
Oh, and please don''t cross post on 3 forums, Mr Impatience. I just found this thread on FlipCode and OpenGL.org...

##### Share on other sites
i add myself to the ap.. thought it was not me that posted it

don''t crosspost. even over forums, its annyoing

"take a look around" - limp bizkit

##### Share on other sites

for (i = 0; i < num_octree_nodes; i++) {
test if bb is visible
}

i think the problem here is, that you cannot know the visibility of the other octree nodes, because it can change because of rendering other octree nodes. So you gotta check a bb for visibility, and if visible render its triangles, i guess..

--
I''m writing this because i do a thesis on occlusion culling and want to make an implementation which shows the advantages of occlusion culling with the NV_OCCLUSION_QUERY extention.

I guess octrees are not a very good way to use the query, because it''s not as fast when used this way, so i''m thinking of using object based files (like xgl), and draw bb rond object for testing visibility with the query. Are there any other file formats where you can distinct seperate objects in the file (e.g. houses in a city xgl file), and are there download locations for sample (city?) files, or even modellers would do fine.

##### Share on other sites
Each octree has 8 nodes. Check all 8 nodes, and only then check their children.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633715
• Total Posts
3013496
×