17ec681f3SmrgXlib Software Driver
27ec681f3Smrg====================
37ec681f3Smrg
47ec681f3SmrgMesa's Xlib driver provides an emulation of the GLX interface so that
57ec681f3SmrgOpenGL programs which use the GLX API can render to any X display, even
67ec681f3Smrgthose that don't support the GLX extension. Effectively, the Xlib driver
77ec681f3Smrgconverts all OpenGL rendering into Xlib calls.
87ec681f3Smrg
97ec681f3SmrgThe Xlib driver is the oldest Mesa driver and the most mature of Mesa's
107ec681f3Smrgsoftware-only drivers.
117ec681f3Smrg
127ec681f3SmrgSince the Xlib driver *emulates* the GLX extension, it's not totally
137ec681f3Smrgconformant with a true GLX implementation. The differences are fairly
147ec681f3Smrgobscure, however.
157ec681f3Smrg
167ec681f3SmrgThe unique features of the Xlib driver follows.
177ec681f3Smrg
187ec681f3SmrgX Visual Selection
197ec681f3Smrg------------------
207ec681f3Smrg
217ec681f3SmrgMesa supports RGB(A) rendering into almost any X visual type and depth.
227ec681f3Smrg
237ec681f3SmrgThe glXChooseVisual function tries to choose the best X visual for the
247ec681f3Smrggiven attribute list. However, if this doesn't suit your needs you can
257ec681f3Smrgforce Mesa to use any X visual you want (any supported by your X server
267ec681f3Smrgthat is) by setting the **MESA_RGB_VISUAL** environment variable. When
277ec681f3Smrga visual is requested, glXChooseVisual will first look if the
287ec681f3SmrgMESA_RGB_VISUAL variable is defined. If so, it will try to use the
297ec681f3Smrgspecified visual.
307ec681f3Smrg
317ec681f3SmrgThe format of accepted values is: ``visual-class depth``
327ec681f3Smrg
337ec681f3SmrgHere are some examples:
347ec681f3Smrg
357ec681f3Smrg::
367ec681f3Smrg
377ec681f3Smrg   using csh:
387ec681f3Smrg       % setenv MESA_RGB_VISUAL "TrueColor 8"      // 8-bit TrueColor
397ec681f3Smrg       % setenv MESA_RGB_VISUAL "PseudoColor 8"    // 8-bit PseudoColor
407ec681f3Smrg
417ec681f3Smrg   using bash:
427ec681f3Smrg       $ export MESA_RGB_VISUAL="TrueColor 8"
437ec681f3Smrg       $ export MESA_RGB_VISUAL="PseudoColor 8"
447ec681f3Smrg
457ec681f3SmrgDouble Buffering
467ec681f3Smrg----------------
477ec681f3Smrg
487ec681f3SmrgMesa can use either an X Pixmap or XImage as the back color buffer when
497ec681f3Smrgin double-buffer mode. The default is to use an XImage. The
507ec681f3Smrg**MESA_BACK_BUFFER** environment variable can override this. The valid
517ec681f3Smrgvalues for **MESA_BACK_BUFFER** are: **Pixmap** and **XImage** (only the
527ec681f3Smrgfirst letter is checked, case doesn't matter).
537ec681f3Smrg
547ec681f3SmrgUsing XImage is almost always faster than a Pixmap since it resides in
557ec681f3Smrgthe application's address space. When glXSwapBuffers() is called,
567ec681f3SmrgXPutImage() or XShmPutImage() is used to transfer the XImage to the
577ec681f3Smrgon-screen window.
587ec681f3Smrg
597ec681f3SmrgA Pixmap may be faster when doing remote rendering of a simple scene.
607ec681f3SmrgSome OpenGL features will be very slow with a Pixmap (for example,
617ec681f3Smrgblending will require a round-trip message for pixel readback.)
627ec681f3Smrg
637ec681f3SmrgExperiment with the MESA_BACK_BUFFER variable to see which is faster for
647ec681f3Smrgyour application.
657ec681f3Smrg
667ec681f3SmrgColormaps
677ec681f3Smrg---------
687ec681f3Smrg
697ec681f3SmrgWhen using Mesa directly or with GLX, it's up to the application writer
707ec681f3Smrgto create a window with an appropriate colormap. The GLUT toolkit tries
717ec681f3Smrgto minimize colormap *flashing* by sharing colormaps when possible.
727ec681f3SmrgSpecifically, if the visual and depth of the window matches that of the
737ec681f3Smrgroot window, the root window's colormap will be shared by the Mesa
747ec681f3Smrgwindow. Otherwise, a new, private colormap will be allocated.
757ec681f3Smrg
767ec681f3SmrgWhen sharing the root colormap, Mesa may be unable to allocate the
777ec681f3Smrgcolors it needs, resulting in poor color quality. This can happen when a
787ec681f3Smrglarge number of colorcells in the root colormap are already allocated.
797ec681f3Smrg
807ec681f3SmrgGamma Correction
817ec681f3Smrg----------------
827ec681f3Smrg
837ec681f3SmrgTo compensate for the nonlinear relationship between pixel values and
847ec681f3Smrgdisplayed intensities, there is a gamma correction feature in Mesa. Some
857ec681f3Smrgsystems, such as Silicon Graphics, support gamma correction in hardware
867ec681f3Smrg(man gamma) so you won't need to use Mesa's gamma facility. Other
877ec681f3Smrgsystems, however, may need gamma adjustment to produce images which look
887ec681f3Smrgcorrect. If you believe that Mesa's images are too dim, read on.
897ec681f3Smrg
907ec681f3SmrgGamma correction is controlled with the **MESA_GAMMA** environment
917ec681f3Smrgvariable. Its value is of the form **Gr Gg Gb** or just **G** where Gr
927ec681f3Smrgis the red gamma value, Gg is the green gamma value, Gb is the blue
937ec681f3Smrggamma value and G is one gamma value to use for all three channels. Each
947ec681f3Smrgvalue is a positive real number typically in the range 1.0 to 2.5. The
957ec681f3Smrgdefaults are all 1.0, effectively disabling gamma correction. Examples:
967ec681f3Smrg
977ec681f3Smrg.. code-block:: console
987ec681f3Smrg
997ec681f3Smrg   % export MESA_GAMMA="2.3 2.2 2.4"  # separate R,G,B values
1007ec681f3Smrg   % export MESA_GAMMA="2.0"          # same gamma for R,G,B
1017ec681f3Smrg
1027ec681f3SmrgThe ``demos/gamma.c`` program in mesa/demos repository may help you to
1037ec681f3Smrgdetermine reasonable gamma value for your display. With correct gamma
1047ec681f3Smrgvalues, the color intensities displayed in the top row (drawn by
1057ec681f3Smrgdithering) should nearly match those in the bottom row (drawn as grays).
1067ec681f3Smrg
1077ec681f3SmrgAlex De Bruyn reports that gamma values of 1.6, 1.6 and 1.9 work well on
1087ec681f3SmrgHP displays using the HP-ColorRecovery technology.
1097ec681f3Smrg
1107ec681f3SmrgMesa implements gamma correction with a lookup table which translates a
1117ec681f3Smrg"linear" pixel value to a gamma-corrected pixel value. There is a small
1127ec681f3Smrgperformance penalty. Gamma correction only works in RGB mode. Also be
1137ec681f3Smrgaware that pixel values read back from the frame buffer will not be
1147ec681f3Smrg"un-corrected" so glReadPixels may not return the same data drawn with
1157ec681f3SmrgglDrawPixels.
1167ec681f3Smrg
1177ec681f3SmrgFor more information about gamma correction, see the `Wikipedia
1187ec681f3Smrgarticle <https://en.wikipedia.org/wiki/Gamma_correction>`__
1197ec681f3Smrg
1207ec681f3SmrgOverlay Planes
1217ec681f3Smrg--------------
1227ec681f3Smrg
1237ec681f3SmrgHardware overlay planes are supported by the Xlib driver. To determine
1247ec681f3Smrgif your X server has overlay support you can test for the
1257ec681f3SmrgSERVER_OVERLAY_VISUALS property:
1267ec681f3Smrg
1277ec681f3Smrg.. code-block:: console
1287ec681f3Smrg
1297ec681f3Smrg   xprop -root | grep SERVER_OVERLAY_VISUALS
1307ec681f3Smrg
1317ec681f3Smrg
1327ec681f3SmrgExtensions
1337ec681f3Smrg----------
1347ec681f3Smrg
1357ec681f3SmrgThe following Mesa-specific extensions are implemented in the Xlib
1367ec681f3Smrgdriver.
1377ec681f3Smrg
1387ec681f3SmrgGLX_MESA_pixmap_colormap
1397ec681f3Smrg~~~~~~~~~~~~~~~~~~~~~~~~
1407ec681f3Smrg
1417ec681f3SmrgThis extension adds the GLX function:
1427ec681f3Smrg
1437ec681f3Smrg.. code-block:: c
1447ec681f3Smrg
1457ec681f3Smrg   GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
1467ec681f3Smrg                                     Pixmap pixmap, Colormap cmap )
1477ec681f3Smrg
1487ec681f3SmrgIt is an alternative to the standard glXCreateGLXPixmap() function.
1497ec681f3SmrgSince Mesa supports RGB rendering into any X visual, not just True-
1507ec681f3SmrgColor or DirectColor, Mesa needs colormap information to convert RGB
1517ec681f3Smrgvalues into pixel values. An X window carries this information but a
1527ec681f3Smrgpixmap does not. This function associates a colormap to a GLX pixmap.
1537ec681f3SmrgSee the xdemos/glxpixmap.c file for an example of how to use this
1547ec681f3Smrgextension.
1557ec681f3Smrg
1567ec681f3Smrg`GLX_MESA_pixmap_colormap
1577ec681f3Smrgspecification <specs/MESA_pixmap_colormap.spec>`__
1587ec681f3Smrg
1597ec681f3SmrgGLX_MESA_release_buffers
1607ec681f3Smrg~~~~~~~~~~~~~~~~~~~~~~~~
1617ec681f3Smrg
1627ec681f3SmrgMesa associates a set of ancillary (depth, accumulation, stencil and
1637ec681f3Smrgalpha) buffers with each X window it draws into. These ancillary buffers
1647ec681f3Smrgare allocated for each X window the first time the X window is passed to
1657ec681f3SmrgglXMakeCurrent(). Mesa, however, can't detect when an X window has been
1667ec681f3Smrgdestroyed in order to free the ancillary buffers.
1677ec681f3Smrg
1687ec681f3SmrgThe best it can do is to check for recently destroyed windows whenever
1697ec681f3Smrgthe client calls the glXCreateContext() or glXDestroyContext()
1707ec681f3Smrgfunctions. This may not be sufficient in all situations though.
1717ec681f3Smrg
1727ec681f3SmrgThe GLX_MESA_release_buffers extension allows a client to explicitly
1737ec681f3Smrgdeallocate the ancillary buffers by calling glxReleaseBuffersMESA() just
1747ec681f3Smrgbefore an X window is destroyed. For example:
1757ec681f3Smrg
1767ec681f3Smrg.. code-block:: c
1777ec681f3Smrg
1787ec681f3Smrg   #ifdef GLX_MESA_release_buffers
1797ec681f3Smrg      glXReleaseBuffersMESA( dpy, window );
1807ec681f3Smrg   #endif
1817ec681f3Smrg   XDestroyWindow( dpy, window );
1827ec681f3Smrg
1837ec681f3Smrg`GLX_MESA_release_buffers
1847ec681f3Smrgspecification <specs/MESA_release_buffers.spec>`__
1857ec681f3Smrg
1867ec681f3SmrgThis extension was added in Mesa 2.0.
1877ec681f3Smrg
1887ec681f3SmrgGLX_MESA_copy_sub_buffer
1897ec681f3Smrg~~~~~~~~~~~~~~~~~~~~~~~~
1907ec681f3Smrg
1917ec681f3SmrgThis extension adds the glXCopySubBufferMESA() function. It works like
1927ec681f3SmrgglXSwapBuffers() but only copies a sub-region of the window instead of
1937ec681f3Smrgthe whole window.
1947ec681f3Smrg
1957ec681f3Smrg`GLX_MESA_copy_sub_buffer
1967ec681f3Smrgspecification <specs/MESA_copy_sub_buffer.spec>`__
1977ec681f3Smrg
1987ec681f3SmrgThis extension was added in Mesa 2.6
1997ec681f3Smrg
2007ec681f3SmrgSummary of X-related environment variables
2017ec681f3Smrg------------------------------------------
2027ec681f3Smrg
2037ec681f3Smrg+-----------------------------+--------------------------------------+
2047ec681f3Smrg| Environment variable        | Description                          |
2057ec681f3Smrg+=============================+======================================+
2067ec681f3Smrg| :envvar:`MESA_RGB_VISUAL`   | specifies the X visual and depth for |
2077ec681f3Smrg|                             | RGB mode (X only)                    |
2087ec681f3Smrg+-----------------------------+--------------------------------------+
2097ec681f3Smrg| :envvar:`MESA_BACK_BUFFER`  | specifies how to implement the back  |
2107ec681f3Smrg|                             | color buffer (X only)                |
2117ec681f3Smrg+-----------------------------+--------------------------------------+
2127ec681f3Smrg| :envvar:`MESA_GAMMA`        | gamma correction coefficients        |
2137ec681f3Smrg|                             | (X only)                             |
2147ec681f3Smrg+-----------------------------+--------------------------------------+
215