Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xlibdriver.html 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <HTML>
  2. <TITLE>Xlib Software Driver</TITLE>
  3. <link rel="stylesheet" type="text/css" href="mesa.css"></head>
  4. <BODY>
  5. <H1>Xlib Software Driver</H1>
  6. <p>
  7. Mesa's Xlib driver provides an emulation of the GLX interface so that
  8. OpenGL programs which use the GLX API can render to any X display, even
  9. those that don't support the GLX extension.
  10. Effectively, the Xlib driver converts all OpenGL rendering into Xlib calls.
  11. </p>
  12. <p>
  13. The Xlib driver is the oldest Mesa driver and the most mature of Mesa's
  14. software-only drivers.
  15. </p>
  16. <p>
  17. Since the Xlib driver <em>emulates</em> the GLX extension, it's not
  18. totally conformant with a true GLX implementation.
  19. The differences are fairly obscure, however.
  20. </p>
  21. <p>
  22. The unique features of the Xlib driver follows.
  23. </p>
  24. <H2>X Visual Selection</H2>
  25. <p>
  26. Mesa supports RGB(A) rendering into almost any X visual type and depth.
  27. </p>
  28. <p>
  29. The glXChooseVisual function tries to choose the best X visual
  30. for the given attribute list. However, if this doesn't suit your needs
  31. you can force Mesa to use any X visual you want (any supported by your
  32. X server that is) by setting the <b>MESA_RGB_VISUAL</b> and
  33. <b>MESA_CI_VISUAL</b>
  34. environment variables.
  35. When an RGB visual is requested, glXChooseVisual
  36. will first look if the MESA_RGB_VISUAL variable is defined.
  37. If so, it will try to use the specified visual.
  38. Similarly, when a color index visual is requested, glXChooseVisual will
  39. look for the MESA_CI_VISUAL variable.
  40. </p>
  41. <p>
  42. The format of accepted values is: <code>visual-class depth</code>
  43. </p>
  44. <p>
  45. Here are some examples:
  46. </p>
  47. <pre>
  48. using csh:
  49. % setenv MESA_RGB_VISUAL "TrueColor 8" // 8-bit TrueColor
  50. % setenv MESA_CI_VISUAL "PseudoColor 12" // 12-bit PseudoColor
  51. % setenv MESA_RGB_VISUAL "PseudoColor 8" // 8-bit PseudoColor
  52. using bash:
  53. $ export MESA_RGB_VISUAL="TrueColor 8"
  54. $ export MESA_CI_VISUAL="PseudoColor 12"
  55. $ export MESA_RGB_VISUAL="PseudoColor 8"
  56. </pre>
  57. <H2>Double Buffering</H2>
  58. <p>
  59. Mesa can use either an X Pixmap or XImage as the back color buffer when in
  60. double-buffer mode.
  61. The default is to use an XImage.
  62. The <b>MESA_BACK_BUFFER</b> environment variable can override this.
  63. The valid values for <b>MESA_BACK_BUFFER</b> are: <b>Pixmap</b> and
  64. <b>XImage</b> (only the first letter is checked, case doesn't matter).
  65. </p>
  66. <p>
  67. Using XImage is almost always faster than a Pixmap since it resides in
  68. the application's address space.
  69. When glXSwapBuffers() is called, XPutImage() or XShmPutImage() is used
  70. to transfer the XImage to the on-screen window.
  71. </p>
  72. <p>
  73. A Pixmap may be faster when doing remote rendering of a simple scene.
  74. Some OpenGL features will be very slow with a Pixmap (for example, blending
  75. will require a round-trip message for pixel readback.)
  76. </p>
  77. <p>
  78. Experiment with the MESA_BACK_BUFFER variable to see which is faster
  79. for your application.
  80. </p>
  81. <H2>Colormaps</H2>
  82. <p>
  83. When using Mesa directly or with GLX, it's up to the application
  84. writer to create a window with an appropriate colormap. The GLUT
  85. toolkit tris to minimize colormap <em>flashing</em> by sharing
  86. colormaps when possible. Specifically, if the visual and depth of the
  87. window matches that of the root window, the root window's colormap
  88. will be shared by the Mesa window. Otherwise, a new, private colormap
  89. will be allocated.
  90. </p>
  91. <p>
  92. When sharing the root colormap, Mesa may be unable to allocate the colors
  93. it needs, resulting in poor color quality. This can happen when a
  94. large number of colorcells in the root colormap are already allocated.
  95. To prevent colormap sharing in GLUT, set the
  96. <b>MESA_PRIVATE_CMAP</b> environment variable. The value isn't
  97. significant.
  98. </p>
  99. <H2>Gamma Correction</H2>
  100. <p>
  101. To compensate for the nonlinear relationship between pixel values
  102. and displayed intensities, there is a gamma correction feature in
  103. Mesa. Some systems, such as Silicon Graphics, support gamma
  104. correction in hardware (man gamma) so you won't need to use Mesa's
  105. gamma facility. Other systems, however, may need gamma adjustment
  106. to produce images which look correct. If you believe that
  107. Mesa's images are too dim, read on.
  108. </p>
  109. <p>
  110. Gamma correction is controlled with the <b>MESA_GAMMA</b> environment
  111. variable. Its value is of the form <b>Gr Gg Gb</b> or just <b>G</b> where
  112. Gr is the red gamma value, Gg is the green gamma value, Gb is the
  113. blue gamma value and G is one gamma value to use for all three
  114. channels. Each value is a positive real number typically in the
  115. range 1.0 to 2.5.
  116. The defaults are all 1.0, effectively disabling gamma correction.
  117. Examples:
  118. </p>
  119. <pre>
  120. % export MESA_GAMMA="2.3 2.2 2.4" // separate R,G,B values
  121. % export MESA_GAMMA="2.0" // same gamma for R,G,B
  122. </pre>
  123. <p>
  124. The progs/demos/gamma.c program may help you to determine reasonable gamma
  125. value for your display. With correct gamma values, the color intensities
  126. displayed in the top row (drawn by dithering) should nearly match those
  127. in the bottom row (drawn as grays).
  128. </p>
  129. <p>
  130. Alex De Bruyn reports that gamma values of 1.6, 1.6 and 1.9 work well
  131. on HP displays using the HP-ColorRecovery technology.
  132. </p>
  133. <p>
  134. Mesa implements gamma correction with a lookup table which translates
  135. a "linear" pixel value to a gamma-corrected pixel value. There is a
  136. small performance penalty. Gamma correction only works in RGB mode.
  137. Also be aware that pixel values read back from the frame buffer will
  138. not be "un-corrected" so glReadPixels may not return the same data
  139. drawn with glDrawPixels.
  140. </p>
  141. <p>
  142. For more information about gamma correction see:
  143. <a href="http://www.inforamp.net/~poynton/notes/colour_and_gamma/GammaFAQ.html"
  144. the Gamma FAQ</a>
  145. </p>
  146. <H2>Overlay Planes</H2>
  147. <p>
  148. Hardware overlay planes are supported by the Xlib driver. To
  149. determine if your X server has overlay support you can test for the
  150. SERVER_OVERLAY_VISUALS property:
  151. </p>
  152. <pre>
  153. xprop -root | grep SERVER_OVERLAY_VISUALS
  154. </pre>
  155. <H2>HPCR Dithering</H2>
  156. <p>
  157. If you set the <b>MESA_HPCR_CLEAR</b> environment variable then dithering
  158. will be used when clearing the color buffer. This is only applicable
  159. to HP systems with the HPCR (Color Recovery) feature.
  160. This incurs a small performance penalty.
  161. </p>
  162. <H2>Extensions</H2>
  163. <p>
  164. The following MESA-specific extensions are implemented in the Xlib driver.
  165. </p>
  166. <h3>GLX_MESA_pixmap_colormap</h3>
  167. <p>
  168. This extension adds the GLX function:
  169. </p>
  170. <pre>
  171. GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
  172. Pixmap pixmap, Colormap cmap )
  173. </pre>
  174. <p>
  175. It is an alternative to the standard glXCreateGLXPixmap() function.
  176. Since Mesa supports RGB rendering into any X visual, not just True-
  177. Color or DirectColor, Mesa needs colormap information to convert RGB
  178. values into pixel values. An X window carries this information but a
  179. pixmap does not. This function associates a colormap to a GLX pixmap.
  180. See the xdemos/glxpixmap.c file for an example of how to use this
  181. extension.
  182. </p>
  183. <p>
  184. <a href="MESA_pixmap_colormap.spec">GLX_MESA_pixmap_colormap specification</a>
  185. </p>
  186. <h3>GLX_MESA_release_buffers</h3>
  187. <p>
  188. Mesa associates a set of ancillary (depth, accumulation, stencil and
  189. alpha) buffers with each X window it draws into. These ancillary
  190. buffers are allocated for each X window the first time the X window
  191. is passed to glXMakeCurrent(). Mesa, however, can't detect when an
  192. X window has been destroyed in order to free the ancillary buffers.
  193. </p>
  194. <p>
  195. The best it can do is to check for recently destroyed windows whenever
  196. the client calls the glXCreateContext() or glXDestroyContext()
  197. functions. This may not be sufficient in all situations though.
  198. </p>
  199. <p>
  200. The GLX_MESA_release_buffers extension allows a client to explicitly
  201. deallocate the ancillary buffers by calling glxReleaseBuffersMESA()
  202. just before an X window is destroyed. For example:
  203. </p>
  204. <pre>
  205. #ifdef GLX_MESA_release_buffers
  206. glXReleaseBuffersMESA( dpy, window );
  207. #endif
  208. XDestroyWindow( dpy, window );
  209. </pre>
  210. <p>
  211. <a href="MESA_release_buffers.spec">GLX_MESA_release_buffers specification</a>
  212. </p>
  213. <p>
  214. This extension was added in Mesa 2.0.
  215. </p>
  216. <H3>GLX_MESA_copy_sub_buffer</H3>
  217. <p>
  218. This extension adds the glXCopySubBufferMESA() function. It works
  219. like glXSwapBuffers() but only copies a sub-region of the window
  220. instead of the whole window.
  221. </p>
  222. <p>
  223. <a href="MESA_copy_sub_buffer.spec">GLX_MESA_copy_sub_buffer specification</a>
  224. </p>
  225. <p>
  226. This extension was added in Mesa 2.6
  227. </p>
  228. <h2>Summary of X-related environment variables</H2>
  229. <pre>
  230. MESA_RGB_VISUAL - specifies the X visual and depth for RGB mode (X only)
  231. MESA_CI_VISUAL - specifies the X visual and depth for CI mode (X only)
  232. MESA_BACK_BUFFER - specifies how to implement the back color buffer (X only)
  233. MESA_PRIVATE_CMAP - force aux/tk libraries to use private colormaps (X only)
  234. MESA_GAMMA - gamma correction coefficients (X only)
  235. </pre>
  236. </body>
  237. </html>