HP Workstation zx2000 HP OpenGL Implementation Guide for HP-UX 11.X (IPF versi - Page 17
occlusion culling code fragments, Enumerated Types for Occlusion, Extended Area, Enumerated Type
View all HP Workstation zx2000 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 17 highlights
overview of OpenGL occlusion culling code fragments The following is a sample code segment that shows a simple usage of occlusion culling. /* Turn off writes to depth and color buffers */ glDepthMask(GL_FALSE); glColorMask (GL_FALSE, GL_FALSE, GL_FALSE); /* Enable Occlusion Culling test */ glEnable(GL_OCCLUSION_TEST_HP); for (i=0; i < numParts; i++) { /* Render your favorite bounding box */ renderBoundingBox(i); /* If bounding box is visible, render part */ glGetBooleanv(GL_OCCLUSION_RESULT_HP, &result); if (result) { glColorMask(GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); renderPart(i); glDepthMask(GL_FALSE); glColorMask (GL_FALSE, GL_FALSE, GL_FALSE); } } /* Disable Occlusion Culling test */ glDisable(GL_OCCLUSION_TEST_HP); /* Turn on writes to depth and color buffers */ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE); glDepthMask(GL_TRUE); The key idea behind occlusion culling is that the bounding box is much simpler (that is, fewer vertices) than the part itself. Occlusion culling provides a quick means to test non-visibility of a part by testing its bounding box. It should also be noted that this occlusion culling functionality is very useful for view frustum culling. If a part's bounding box is not visible for any reason (not just because it's occluded in the Z-buffer) this test will give correct results. To maximize the probability that an object is occluded by other objects in a scene, the database should be sorted and rendered from front to back. Also, the database may be sorted hierarchically such that the outer objects are rendered first and the inner are rendered last. An example would be rendering the body of an automobile first and the engine and transmission last. In this way, the engine would not be rendered due to the bounding box test indicating that the engine is not visible. Enumerated Types for Occlusion Extended Area Enumerated Type Description Enable.Disable/IsEnabled GL_OCCLUSION_TEST_HP Default: Disabled pname variable. Get* GL_OCCLUSION_TEST_RESULT_HP pname variable Default: Zero (0) For related information, see the functions: glEnable, glDisable, and glIsEnabled. OpenGL implementation guide 1-13