xref: /aosp_15_r20/external/mesa3d/docs/xlibdriver.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard WorkerXlib Software Driver
2*61046927SAndroid Build Coastguard Worker====================
3*61046927SAndroid Build Coastguard Worker
4*61046927SAndroid Build Coastguard WorkerMesa's Xlib driver provides an emulation of the GLX interface so that
5*61046927SAndroid Build Coastguard WorkerOpenGL programs which use the GLX API can render to any X display, even
6*61046927SAndroid Build Coastguard Workerthose that don't support the GLX extension. Effectively, the Xlib driver
7*61046927SAndroid Build Coastguard Workerconverts all OpenGL rendering into Xlib calls.
8*61046927SAndroid Build Coastguard Worker
9*61046927SAndroid Build Coastguard WorkerThe Xlib driver is the oldest Mesa driver and the most mature of Mesa's
10*61046927SAndroid Build Coastguard Workersoftware-only drivers.
11*61046927SAndroid Build Coastguard Worker
12*61046927SAndroid Build Coastguard WorkerSince the Xlib driver *emulates* the GLX extension, it's not totally
13*61046927SAndroid Build Coastguard Workerconformant with a true GLX implementation. The differences are fairly
14*61046927SAndroid Build Coastguard Workerobscure, however.
15*61046927SAndroid Build Coastguard Worker
16*61046927SAndroid Build Coastguard WorkerThe unique features of the Xlib driver follows.
17*61046927SAndroid Build Coastguard Worker
18*61046927SAndroid Build Coastguard WorkerX Visual Selection
19*61046927SAndroid Build Coastguard Worker------------------
20*61046927SAndroid Build Coastguard Worker
21*61046927SAndroid Build Coastguard WorkerMesa supports RGB(A) rendering into TrueColor and DirectColor visuals, for
22*61046927SAndroid Build Coastguard Workerany depth with a corresponding renderable OpenGL texture format.
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard WorkerThe glXChooseVisual function tries to choose the best X visual for the
25*61046927SAndroid Build Coastguard Workergiven attribute list. However, if this doesn't suit your needs you can
26*61046927SAndroid Build Coastguard Workerforce Mesa to use any X visual you want (any supported by your X server
27*61046927SAndroid Build Coastguard Workerthat is) by setting the **MESA_RGB_VISUAL** environment variable. When
28*61046927SAndroid Build Coastguard Workera visual is requested, glXChooseVisual will first look if the
29*61046927SAndroid Build Coastguard WorkerMESA_RGB_VISUAL variable is defined. If so, it will try to use the
30*61046927SAndroid Build Coastguard Workerspecified visual.
31*61046927SAndroid Build Coastguard Worker
32*61046927SAndroid Build Coastguard WorkerThe format of accepted values is: ``visual-class depth``
33*61046927SAndroid Build Coastguard Worker
34*61046927SAndroid Build Coastguard WorkerHere are some examples:
35*61046927SAndroid Build Coastguard Worker
36*61046927SAndroid Build Coastguard Worker::
37*61046927SAndroid Build Coastguard Worker
38*61046927SAndroid Build Coastguard Worker   using csh:
39*61046927SAndroid Build Coastguard Worker       % setenv MESA_RGB_VISUAL "TrueColor 8"      // 8-bit TrueColor
40*61046927SAndroid Build Coastguard Worker       % setenv MESA_RGB_VISUAL "DirectColor 30"   // 30-bit DirectColor
41*61046927SAndroid Build Coastguard Worker
42*61046927SAndroid Build Coastguard Worker   using bash:
43*61046927SAndroid Build Coastguard Worker       $ export MESA_RGB_VISUAL="TrueColor 8"
44*61046927SAndroid Build Coastguard Worker       $ export MESA_RGB_VISUAL="DirectColor 30"
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard WorkerDouble Buffering
47*61046927SAndroid Build Coastguard Worker----------------
48*61046927SAndroid Build Coastguard Worker
49*61046927SAndroid Build Coastguard WorkerMesa can use either an X Pixmap or XImage as the back color buffer when
50*61046927SAndroid Build Coastguard Workerin double-buffer mode. The default is to use an XImage. The
51*61046927SAndroid Build Coastguard Worker**MESA_BACK_BUFFER** environment variable can override this. The valid
52*61046927SAndroid Build Coastguard Workervalues for **MESA_BACK_BUFFER** are: **Pixmap** and **XImage** (only the
53*61046927SAndroid Build Coastguard Workerfirst letter is checked, case doesn't matter).
54*61046927SAndroid Build Coastguard Worker
55*61046927SAndroid Build Coastguard WorkerUsing XImage is almost always faster than a Pixmap since it resides in
56*61046927SAndroid Build Coastguard Workerthe application's address space. When glXSwapBuffers() is called,
57*61046927SAndroid Build Coastguard WorkerXPutImage() or XShmPutImage() is used to transfer the XImage to the
58*61046927SAndroid Build Coastguard Workeron-screen window.
59*61046927SAndroid Build Coastguard Worker
60*61046927SAndroid Build Coastguard WorkerA Pixmap may be faster when doing remote rendering of a simple scene.
61*61046927SAndroid Build Coastguard WorkerSome OpenGL features will be very slow with a Pixmap (for example,
62*61046927SAndroid Build Coastguard Workerblending will require a round-trip message for pixel readback.)
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard WorkerExperiment with the MESA_BACK_BUFFER variable to see which is faster for
65*61046927SAndroid Build Coastguard Workeryour application.
66*61046927SAndroid Build Coastguard Worker
67*61046927SAndroid Build Coastguard WorkerColormaps
68*61046927SAndroid Build Coastguard Worker---------
69*61046927SAndroid Build Coastguard Worker
70*61046927SAndroid Build Coastguard WorkerWhen using Mesa directly or with GLX, it's up to the application writer
71*61046927SAndroid Build Coastguard Workerto create a window with an appropriate colormap. The GLUT toolkit tries
72*61046927SAndroid Build Coastguard Workerto minimize colormap *flashing* by sharing colormaps when possible.
73*61046927SAndroid Build Coastguard WorkerSpecifically, if the visual and depth of the window matches that of the
74*61046927SAndroid Build Coastguard Workerroot window, the root window's colormap will be shared by the Mesa
75*61046927SAndroid Build Coastguard Workerwindow. Otherwise, a new, private colormap will be allocated.
76*61046927SAndroid Build Coastguard Worker
77*61046927SAndroid Build Coastguard WorkerWhen sharing the root colormap, Mesa may be unable to allocate the
78*61046927SAndroid Build Coastguard Workercolors it needs, resulting in poor color quality. This can happen when a
79*61046927SAndroid Build Coastguard Workerlarge number of colorcells in the root colormap are already allocated.
80*61046927SAndroid Build Coastguard Worker
81*61046927SAndroid Build Coastguard WorkerOverlay Planes
82*61046927SAndroid Build Coastguard Worker--------------
83*61046927SAndroid Build Coastguard Worker
84*61046927SAndroid Build Coastguard WorkerHardware overlay planes are supported by the Xlib driver. To determine
85*61046927SAndroid Build Coastguard Workerif your X server has overlay support you can test for the
86*61046927SAndroid Build Coastguard WorkerSERVER_OVERLAY_VISUALS property:
87*61046927SAndroid Build Coastguard Worker
88*61046927SAndroid Build Coastguard Worker.. code-block:: sh
89*61046927SAndroid Build Coastguard Worker
90*61046927SAndroid Build Coastguard Worker   xprop -root | grep SERVER_OVERLAY_VISUALS
91*61046927SAndroid Build Coastguard Worker
92*61046927SAndroid Build Coastguard Worker
93*61046927SAndroid Build Coastguard WorkerExtensions
94*61046927SAndroid Build Coastguard Worker----------
95*61046927SAndroid Build Coastguard Worker
96*61046927SAndroid Build Coastguard WorkerThe following Mesa-specific extensions are implemented in the Xlib
97*61046927SAndroid Build Coastguard Workerdriver.
98*61046927SAndroid Build Coastguard Worker
99*61046927SAndroid Build Coastguard WorkerGLX_MESA_pixmap_colormap
100*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~
101*61046927SAndroid Build Coastguard Worker
102*61046927SAndroid Build Coastguard WorkerThis extension adds the GLX function:
103*61046927SAndroid Build Coastguard Worker
104*61046927SAndroid Build Coastguard Worker.. code-block:: c
105*61046927SAndroid Build Coastguard Worker
106*61046927SAndroid Build Coastguard Worker   GLXPixmap glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visual,
107*61046927SAndroid Build Coastguard Worker                                     Pixmap pixmap, Colormap cmap )
108*61046927SAndroid Build Coastguard Worker
109*61046927SAndroid Build Coastguard WorkerIt is an alternative to the standard glXCreateGLXPixmap() function.
110*61046927SAndroid Build Coastguard WorkerSince Mesa supports RGB rendering into any X visual, not just True-
111*61046927SAndroid Build Coastguard WorkerColor or DirectColor, Mesa needs colormap information to convert RGB
112*61046927SAndroid Build Coastguard Workervalues into pixel values. An X window carries this information but a
113*61046927SAndroid Build Coastguard Workerpixmap does not. This function associates a colormap to a GLX pixmap.
114*61046927SAndroid Build Coastguard WorkerSee the xdemos/glxpixmap.c file for an example of how to use this
115*61046927SAndroid Build Coastguard Workerextension.
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard Worker`GLX_MESA_pixmap_colormap
118*61046927SAndroid Build Coastguard Workerspecification <specs/MESA_pixmap_colormap.spec>`__
119*61046927SAndroid Build Coastguard Worker
120*61046927SAndroid Build Coastguard WorkerGLX_MESA_release_buffers
121*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~
122*61046927SAndroid Build Coastguard Worker
123*61046927SAndroid Build Coastguard WorkerMesa associates a set of ancillary (depth, accumulation, stencil and
124*61046927SAndroid Build Coastguard Workeralpha) buffers with each X window it draws into. These ancillary buffers
125*61046927SAndroid Build Coastguard Workerare allocated for each X window the first time the X window is passed to
126*61046927SAndroid Build Coastguard WorkerglXMakeCurrent(). Mesa, however, can't detect when an X window has been
127*61046927SAndroid Build Coastguard Workerdestroyed in order to free the ancillary buffers.
128*61046927SAndroid Build Coastguard Worker
129*61046927SAndroid Build Coastguard WorkerThe best it can do is to check for recently destroyed windows whenever
130*61046927SAndroid Build Coastguard Workerthe client calls the glXCreateContext() or glXDestroyContext()
131*61046927SAndroid Build Coastguard Workerfunctions. This may not be sufficient in all situations though.
132*61046927SAndroid Build Coastguard Worker
133*61046927SAndroid Build Coastguard WorkerThe GLX_MESA_release_buffers extension allows a client to explicitly
134*61046927SAndroid Build Coastguard Workerdeallocate the ancillary buffers by calling glxReleaseBuffersMESA() just
135*61046927SAndroid Build Coastguard Workerbefore an X window is destroyed. For example:
136*61046927SAndroid Build Coastguard Worker
137*61046927SAndroid Build Coastguard Worker.. code-block:: c
138*61046927SAndroid Build Coastguard Worker
139*61046927SAndroid Build Coastguard Worker   #ifdef GLX_MESA_release_buffers
140*61046927SAndroid Build Coastguard Worker      glXReleaseBuffersMESA( dpy, window );
141*61046927SAndroid Build Coastguard Worker   #endif
142*61046927SAndroid Build Coastguard Worker   XDestroyWindow( dpy, window );
143*61046927SAndroid Build Coastguard Worker
144*61046927SAndroid Build Coastguard Worker`GLX_MESA_release_buffers
145*61046927SAndroid Build Coastguard Workerspecification <specs/MESA_release_buffers.spec>`__
146*61046927SAndroid Build Coastguard Worker
147*61046927SAndroid Build Coastguard WorkerThis extension was added in Mesa 2.0.
148*61046927SAndroid Build Coastguard Worker
149*61046927SAndroid Build Coastguard WorkerGLX_MESA_copy_sub_buffer
150*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~~~
151*61046927SAndroid Build Coastguard Worker
152*61046927SAndroid Build Coastguard WorkerThis extension adds the glXCopySubBufferMESA() function. It works like
153*61046927SAndroid Build Coastguard WorkerglXSwapBuffers() but only copies a sub-region of the window instead of
154*61046927SAndroid Build Coastguard Workerthe whole window.
155*61046927SAndroid Build Coastguard Worker
156*61046927SAndroid Build Coastguard Worker`GLX_MESA_copy_sub_buffer
157*61046927SAndroid Build Coastguard Workerspecification <specs/MESA_copy_sub_buffer.spec>`__
158*61046927SAndroid Build Coastguard Worker
159*61046927SAndroid Build Coastguard WorkerThis extension was added in Mesa 2.6
160*61046927SAndroid Build Coastguard Worker
161*61046927SAndroid Build Coastguard WorkerSummary of X-related environment variables
162*61046927SAndroid Build Coastguard Worker------------------------------------------
163*61046927SAndroid Build Coastguard Worker
164*61046927SAndroid Build Coastguard Worker+-----------------------------+--------------------------------------+
165*61046927SAndroid Build Coastguard Worker| Environment variable        | Description                          |
166*61046927SAndroid Build Coastguard Worker+=============================+======================================+
167*61046927SAndroid Build Coastguard Worker| :envvar:`MESA_RGB_VISUAL`   | specifies the X visual and depth for |
168*61046927SAndroid Build Coastguard Worker|                             | RGB mode (X only)                    |
169*61046927SAndroid Build Coastguard Worker+-----------------------------+--------------------------------------+
170*61046927SAndroid Build Coastguard Worker| :envvar:`MESA_BACK_BUFFER`  | specifies how to implement the back  |
171*61046927SAndroid Build Coastguard Worker|                             | color buffer (X only)                |
172*61046927SAndroid Build Coastguard Worker+-----------------------------+--------------------------------------+
173