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