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

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

OpenGL implementation guide
1–13
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
For related information, see the functions:
glEnable
,
glDisable
, and
glIsEnabled
.
Extended Area
Enumerated Type
Description
Enable.Disable/IsEnabled GL_OCCLUSION_TEST_HP
Default: Disabled
pname variable.
Get*
GL_OCCLUSION_TEST_RESULT_HP
Default: Zero (0)
pname variable