home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / lib / site-packages / OpenGL / raw / GL / ARB / occlusion_query.py < prev    next >
Encoding:
Python Source  |  2008-12-07  |  6.4 KB  |  155 lines

  1. '''OpenGL extension ARB.occlusion_query
  2.  
  3. Overview (from the spec)
  4.     
  5.     This extension defines a mechanism whereby an application can query
  6.     the number of pixels (or, more precisely, samples) drawn by a
  7.     primitive or group of primitives.
  8.     
  9.     The primary purpose of such a query (hereafter referred to as an
  10.     "occlusion query") is to determine the visibility of an object.
  11.     Typically, the application will render the major occluders in the
  12.     scene, then perform an occlusion query for the bounding box of each
  13.     detail object in the scene.  Only if said bounding box is visible,
  14.     i.e., if at least one sample is drawn, should the corresponding object
  15.     be drawn.
  16.     
  17.     The earlier HP_occlusion_test extension defined a similar mechanism,
  18.     but it had two major shortcomings.
  19.     
  20.     - It returned the result as a simple GL_TRUE/GL_FALSE result, when in
  21.       fact it is often useful to know exactly how many samples were
  22.       drawn.
  23.     - It provided only a simple "stop-and-wait" model for using multiple
  24.       queries.  The application begins an occlusion test and ends it;
  25.       then, at some later point, it asks for the result, at which point
  26.       the driver must stop and wait until the result from the previous
  27.       test is back before the application can even begin the next one.
  28.       This is a very simple model, but its performance is mediocre when
  29.       an application wishes to perform many queries, and it eliminates
  30.       most of the opportunities for parallelism between the CPU and GPU.
  31.     
  32.     This extension solves both of those problems.  It returns as its
  33.     result the number of samples that pass the depth and stencil tests,
  34.     and it encapsulates occlusion queries in "query objects" that allow
  35.     applications to issue many queries before asking for the result of
  36.     any one.  As a result, they can overlap the time it takes for the
  37.     occlusion query results to be returned with other, more useful work,
  38.     such as rendering other parts of the scene or performing other
  39.     computations on the CPU.
  40.     
  41.     There are many situations where a pixel/sample count, rather than a
  42.     boolean result, is useful.
  43.     
  44.     - Objects that are visible but cover only a very small number of
  45.       pixels can be skipped at a minimal reduction of image quality.
  46.     - Knowing exactly how many pixels an object might cover may help the
  47.       application decide which level-of-detail model should be used.  If
  48.       only a few pixels are visible, a low-detail model may be
  49.       acceptable.
  50.     - "Depth peeling" techniques, such as order-independent transparency,
  51.       need to know when to stop rendering more layers; it is difficult to
  52.       determine a priori how many layers are needed.  A boolean result
  53.       allows applications to stop when more layers will not affect the
  54.       image at all, but this will likely result in unacceptable
  55.       performance.  Instead, it makes more sense to stop rendering when
  56.       the number of pixels in each layer falls below a given threshold.
  57.     - Occlusion queries can replace glReadPixels of the depth buffer to
  58.       determine whether (for example) a light source is visible for the
  59.       purposes of a lens flare effect or a halo to simulate glare.  Pixel
  60.       counts allow you to compute the percentage of the light source that
  61.       is visible, and the brightness of these effects can be modulated
  62.       accordingly.
  63.  
  64. The official definition of this extension is available here:
  65.     http://oss.sgi.com/projects/ogl-sample/registry/ARB/occlusion_query.txt
  66.  
  67. Automatically generated by the get_gl_extensions script, do not edit!
  68. '''
  69. from OpenGL import platform, constants, constant, arrays
  70. from OpenGL import extensions
  71. from OpenGL.GL import glget
  72. import ctypes
  73. EXTENSION_NAME = 'GL_ARB_occlusion_query'
  74. GL_QUERY_COUNTER_BITS_ARB = constant.Constant( 'GL_QUERY_COUNTER_BITS_ARB', 0x8864 )
  75. GL_CURRENT_QUERY_ARB = constant.Constant( 'GL_CURRENT_QUERY_ARB', 0x8865 )
  76. GL_QUERY_RESULT_ARB = constant.Constant( 'GL_QUERY_RESULT_ARB', 0x8866 )
  77. GL_QUERY_RESULT_AVAILABLE_ARB = constant.Constant( 'GL_QUERY_RESULT_AVAILABLE_ARB', 0x8867 )
  78. GL_SAMPLES_PASSED_ARB = constant.Constant( 'GL_SAMPLES_PASSED_ARB', 0x8914 )
  79. glGenQueriesARB = platform.createExtensionFunction( 
  80.     'glGenQueriesARB', dll=platform.GL,
  81.     extension=EXTENSION_NAME,
  82.     resultType=None, 
  83.     argTypes=(constants.GLsizei, arrays.GLuintArray,),
  84.     doc = 'glGenQueriesARB( GLsizei(n), GLuintArray(ids) ) -> None',
  85.     argNames = ('n', 'ids',),
  86. )
  87.  
  88. glDeleteQueriesARB = platform.createExtensionFunction( 
  89.     'glDeleteQueriesARB', dll=platform.GL,
  90.     extension=EXTENSION_NAME,
  91.     resultType=None, 
  92.     argTypes=(constants.GLsizei, arrays.GLuintArray,),
  93.     doc = 'glDeleteQueriesARB( GLsizei(n), GLuintArray(ids) ) -> None',
  94.     argNames = ('n', 'ids',),
  95. )
  96.  
  97. glIsQueryARB = platform.createExtensionFunction( 
  98.     'glIsQueryARB', dll=platform.GL,
  99.     extension=EXTENSION_NAME,
  100.     resultType=constants.GLboolean, 
  101.     argTypes=(constants.GLuint,),
  102.     doc = 'glIsQueryARB( GLuint(id) ) -> constants.GLboolean',
  103.     argNames = ('id',),
  104. )
  105.  
  106. glBeginQueryARB = platform.createExtensionFunction( 
  107.     'glBeginQueryARB', dll=platform.GL,
  108.     extension=EXTENSION_NAME,
  109.     resultType=None, 
  110.     argTypes=(constants.GLenum, constants.GLuint,),
  111.     doc = 'glBeginQueryARB( GLenum(target), GLuint(id) ) -> None',
  112.     argNames = ('target', 'id',),
  113. )
  114.  
  115. glEndQueryARB = platform.createExtensionFunction( 
  116.     'glEndQueryARB', dll=platform.GL,
  117.     extension=EXTENSION_NAME,
  118.     resultType=None, 
  119.     argTypes=(constants.GLenum,),
  120.     doc = 'glEndQueryARB( GLenum(target) ) -> None',
  121.     argNames = ('target',),
  122. )
  123.  
  124. glGetQueryivARB = platform.createExtensionFunction( 
  125.     'glGetQueryivARB', dll=platform.GL,
  126.     extension=EXTENSION_NAME,
  127.     resultType=None, 
  128.     argTypes=(constants.GLenum, constants.GLenum, arrays.GLintArray,),
  129.     doc = 'glGetQueryivARB( GLenum(target), GLenum(pname), GLintArray(params) ) -> None',
  130.     argNames = ('target', 'pname', 'params',),
  131. )
  132.  
  133. glGetQueryObjectivARB = platform.createExtensionFunction( 
  134.     'glGetQueryObjectivARB', dll=platform.GL,
  135.     extension=EXTENSION_NAME,
  136.     resultType=None, 
  137.     argTypes=(constants.GLuint, constants.GLenum, arrays.GLintArray,),
  138.     doc = 'glGetQueryObjectivARB( GLuint(id), GLenum(pname), GLintArray(params) ) -> None',
  139.     argNames = ('id', 'pname', 'params',),
  140. )
  141.  
  142. glGetQueryObjectuivARB = platform.createExtensionFunction( 
  143.     'glGetQueryObjectuivARB', dll=platform.GL,
  144.     extension=EXTENSION_NAME,
  145.     resultType=None, 
  146.     argTypes=(constants.GLuint, constants.GLenum, arrays.GLuintArray,),
  147.     doc = 'glGetQueryObjectuivARB( GLuint(id), GLenum(pname), GLuintArray(params) ) -> None',
  148.     argNames = ('id', 'pname', 'params',),
  149. )
  150.  
  151.  
  152. def glInitOcclusionQueryARB():
  153.     '''Return boolean indicating whether this extension is available'''
  154.     return extensions.hasGLExtension( EXTENSION_NAME )
  155.