c380ba27dcc6ba68773d8609a6ba613ccbd78d2e
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.1
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 /*
27 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
28 * to run on X servers which do not have the real GLX extension.
29 *
30 * Thanks to the contributors:
31 *
32 * Initial version: Philip Brown (phil@bolthole.com)
33 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
34 * Further visual-handling refinements: Wolfram Gloger
35 * (wmglo@Dent.MED.Uni-Muenchen.DE).
36 *
37 * Notes:
38 * Don't be fooled, stereo isn't supported yet.
39 */
40
41
42
43 #include "glxheader.h"
44 #include "glxapi.h"
45 #include "GL/xmesa.h"
46 #include "context.h"
47 #include "config.h"
48 #include "macros.h"
49 #include "imports.h"
50 #include "mtypes.h"
51 #include "version.h"
52 #include "xfonts.h"
53 #include "xmesaP.h"
54
55
56 /* This indicates the client-side GLX API and GLX encoder version. */
57 #define CLIENT_MAJOR_VERSION 1
58 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
59
60 /* This indicates the server-side GLX decoder version.
61 * GLX 1.4 indicates OpenGL 1.3 support
62 */
63 #define SERVER_MAJOR_VERSION 1
64 #define SERVER_MINOR_VERSION 4
65
66 /* This is appended onto the glXGetClient/ServerString version strings. */
67 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
68
69 /* Who implemented this GLX? */
70 #define VENDOR "Brian Paul"
71
72 #define EXTENSIONS \
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_get_proc_address " \
78 "GLX_EXT_visual_info " \
79 "GLX_EXT_visual_rating " \
80 "GLX_SGI_video_sync " \
81 "GLX_SGIX_fbconfig " \
82 "GLX_SGIX_pbuffer "
83 /*
84 "GLX_ARB_render_texture"
85 */
86
87
88 /*
89 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
90 *
91 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
92 * and vice versa.
93 *
94 * We really just need this structure in order to make the libGL functions
95 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
96 * work correctly.
97 */
98 struct fake_glx_context {
99 __GLXcontext glxContext; /* this MUST be first! */
100 XMesaContext xmesaContext;
101 };
102
103
104
105 /**********************************************************************/
106 /*** GLX Visual Code ***/
107 /**********************************************************************/
108
109 #define DONT_CARE -1
110
111
112 #define MAX_VISUALS 100
113 static XMesaVisual VisualTable[MAX_VISUALS];
114 static int NumVisuals = 0;
115
116
117 /*
118 * This struct and some code fragments borrowed
119 * from Mark Kilgard's GLUT library.
120 */
121 typedef struct _OverlayInfo {
122 /* Avoid 64-bit portability problems by being careful to use
123 longs due to the way XGetWindowProperty is specified. Note
124 that these parameters are passed as CARD32s over X
125 protocol. */
126 unsigned long overlay_visual;
127 long transparent_type;
128 long value;
129 long layer;
130 } OverlayInfo;
131
132
133
134 /* Macro to handle c_class vs class field name in XVisualInfo struct */
135 #if defined(__cplusplus) || defined(c_plusplus)
136 #define CLASS c_class
137 #else
138 #define CLASS class
139 #endif
140
141
142
143
144 /*
145 * Test if the given XVisualInfo is usable for Mesa rendering.
146 */
147 static GLboolean is_usable_visual( XVisualInfo *vinfo )
148 {
149 switch (vinfo->CLASS) {
150 case StaticGray:
151 case GrayScale:
152 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
153 return GL_TRUE;
154 case StaticColor:
155 case PseudoColor:
156 /* Any StaticColor/PseudoColor visual of at least 4 bits */
157 if (vinfo->depth>=4) {
158 return GL_TRUE;
159 }
160 else {
161 return GL_FALSE;
162 }
163 case TrueColor:
164 case DirectColor:
165 /* Any depth of TrueColor or DirectColor works in RGB mode */
166 return GL_TRUE;
167 default:
168 /* This should never happen */
169 return GL_FALSE;
170 }
171 }
172
173
174
175 /*
176 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
177 * Input: dpy - the X display
178 * vinfo - the XVisualInfo to test
179 * Return: level of the visual:
180 * 0 = normal planes
181 * >0 = overlay planes
182 * <0 = underlay planes
183 */
184 static int level_of_visual( Display *dpy, XVisualInfo *vinfo )
185 {
186 Atom overlayVisualsAtom;
187 OverlayInfo *overlay_info = NULL;
188 int numOverlaysPerScreen;
189 Status status;
190 Atom actualType;
191 int actualFormat;
192 unsigned long sizeData, bytesLeft;
193 int i;
194
195 /*
196 * The SERVER_OVERLAY_VISUALS property on the root window contains
197 * a list of overlay visuals. Get that list now.
198 */
199 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
200 if (overlayVisualsAtom == None) {
201 return 0;
202 }
203
204 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
205 overlayVisualsAtom, 0L, (long) 10000, False,
206 overlayVisualsAtom, &actualType, &actualFormat,
207 &sizeData, &bytesLeft,
208 (unsigned char **) &overlay_info );
209
210 if (status != Success || actualType != overlayVisualsAtom ||
211 actualFormat != 32 || sizeData < 4) {
212 /* something went wrong */
213 XFree((void *) overlay_info);
214 return 0;
215 }
216
217 /* search the overlay visual list for the visual ID of interest */
218 numOverlaysPerScreen = (int) (sizeData / 4);
219 for (i=0;i<numOverlaysPerScreen;i++) {
220 OverlayInfo *ov;
221 ov = overlay_info + i;
222 if (ov->overlay_visual==vinfo->visualid) {
223 /* found the visual */
224 if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
225 int level = ov->layer;
226 XFree((void *) overlay_info);
227 return level;
228 }
229 else {
230 XFree((void *) overlay_info);
231 return 0;
232 }
233 }
234 }
235
236 /* The visual ID was not found in the overlay list. */
237 XFree((void *) overlay_info);
238 return 0;
239 }
240
241
242
243
244 /*
245 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
246 * configuration in our list of GLX visuals.
247 */
248 static XMesaVisual
249 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
250 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
251 GLboolean stereoFlag,
252 GLint depth_size, GLint stencil_size,
253 GLint accumRedSize, GLint accumGreenSize,
254 GLint accumBlueSize, GLint accumAlphaSize,
255 GLint level, GLint numAuxBuffers )
256 {
257 GLboolean ximageFlag = GL_TRUE;
258 XMesaVisual xmvis;
259 GLint i;
260 GLboolean comparePointers;
261
262 if (dbFlag) {
263 /* Check if the MESA_BACK_BUFFER env var is set */
264 char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
265 if (backbuffer) {
266 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
267 ximageFlag = GL_FALSE;
268 }
269 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
270 ximageFlag = GL_TRUE;
271 }
272 else {
273 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
274 }
275 }
276 }
277
278 /* Comparing IDs uses less memory but sometimes fails. */
279 /* XXX revisit this after 3.0 is finished. */
280 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
281 comparePointers = GL_TRUE;
282 else
283 comparePointers = GL_FALSE;
284
285 /* Force the visual to have an alpha channel */
286 if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
287 alphaFlag = GL_TRUE;
288
289 /* First check if a matching visual is already in the list */
290 for (i=0; i<NumVisuals; i++) {
291 XMesaVisual v = VisualTable[i];
292 if (v->display == dpy
293 && v->mesa_visual.level == level
294 && v->mesa_visual.numAuxBuffers == numAuxBuffers
295 && v->ximage_flag == ximageFlag
296 && v->mesa_visual.rgbMode == rgbFlag
297 && v->mesa_visual.doubleBufferMode == dbFlag
298 && v->mesa_visual.stereoMode == stereoFlag
299 && (v->mesa_visual.alphaBits > 0) == alphaFlag
300 && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
301 && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
302 && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
303 && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
304 && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
305 && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
306 /* now either compare XVisualInfo pointers or visual IDs */
307 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
308 || (comparePointers && v->vishandle == vinfo)) {
309 return v;
310 }
311 }
312 }
313
314 /* Create a new visual and add it to the list. */
315
316 if (NumVisuals >= MAX_VISUALS) {
317 _mesa_problem(NULL, "GLX Error: maximum number of visuals exceeded");
318 return NULL;
319 }
320
321 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
322 stereoFlag, ximageFlag,
323 depth_size, stencil_size,
324 accumRedSize, accumBlueSize,
325 accumBlueSize, accumAlphaSize, 0, level,
326 GLX_NONE_EXT );
327 if (xmvis) {
328 /* Save a copy of the pointer now so we can find this visual again
329 * if we need to search for it in find_glx_visual().
330 */
331 xmvis->vishandle = vinfo;
332 /* add xmvis to the list */
333 VisualTable[NumVisuals] = xmvis;
334 NumVisuals++;
335 /* XXX minor hack */
336 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
337 }
338 return xmvis;
339 }
340
341
342
343 /*
344 * Create a GLX visual from a regular XVisualInfo.
345 * This is called when Fake GLX is given an XVisualInfo which wasn't
346 * returned by glXChooseVisual. Since this is the first time we're
347 * considering this visual we'll take a guess at reasonable values
348 * for depth buffer size, stencil size, accum size, etc.
349 * This is the best we can do with a client-side emulation of GLX.
350 */
351 static XMesaVisual
352 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
353 {
354 int vislevel;
355
356 vislevel = level_of_visual( dpy, visinfo );
357 if (vislevel) {
358 /* Configure this visual as a CI, single-buffered overlay */
359 return save_glx_visual( dpy, visinfo,
360 GL_FALSE, /* rgb */
361 GL_FALSE, /* alpha */
362 GL_FALSE, /* double */
363 GL_FALSE, /* stereo */
364 0, /* depth bits */
365 0, /* stencil bits */
366 0,0,0,0, /* accum bits */
367 vislevel, /* level */
368 0 /* numAux */
369 );
370 }
371 else if (is_usable_visual( visinfo )) {
372 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
373 /* Configure this visual as a COLOR INDEX visual. */
374 return save_glx_visual( dpy, visinfo,
375 GL_FALSE, /* rgb */
376 GL_FALSE, /* alpha */
377 GL_TRUE, /* double */
378 GL_FALSE, /* stereo */
379 DEFAULT_SOFTWARE_DEPTH_BITS,
380 8 * sizeof(GLstencil),
381 0 * sizeof(GLaccum), /* r */
382 0 * sizeof(GLaccum), /* g */
383 0 * sizeof(GLaccum), /* b */
384 0 * sizeof(GLaccum), /* a */
385 0, /* level */
386 0 /* numAux */
387 );
388 }
389 else {
390 /* Configure this visual as RGB, double-buffered, depth-buffered. */
391 /* This is surely wrong for some people's needs but what else */
392 /* can be done? They should use glXChooseVisual(). */
393 return save_glx_visual( dpy, visinfo,
394 GL_TRUE, /* rgb */
395 GL_FALSE, /* alpha */
396 GL_TRUE, /* double */
397 GL_FALSE, /* stereo */
398 DEFAULT_SOFTWARE_DEPTH_BITS,
399 8 * sizeof(GLstencil),
400 8 * sizeof(GLaccum), /* r */
401 8 * sizeof(GLaccum), /* g */
402 8 * sizeof(GLaccum), /* b */
403 8 * sizeof(GLaccum), /* a */
404 0, /* level */
405 0 /* numAux */
406 );
407 }
408 }
409 else {
410 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
411 return NULL;
412 }
413 }
414
415
416
417 /*
418 * Find the GLX visual associated with an XVisualInfo.
419 */
420 static XMesaVisual
421 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
422 {
423 int i;
424
425 /* try to match visual id */
426 for (i=0;i<NumVisuals;i++) {
427 if (VisualTable[i]->display==dpy
428 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
429 return VisualTable[i];
430 }
431 }
432
433 /* if that fails, try to match pointers */
434 for (i=0;i<NumVisuals;i++) {
435 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
436 return VisualTable[i];
437 }
438 }
439
440 return NULL;
441 }
442
443
444
445 /*
446 * Return the transparent pixel value for a GLX visual.
447 * Input: glxvis - the glx_visual
448 * Return: a pixel value or -1 if no transparent pixel
449 */
450 static int transparent_pixel( XMesaVisual glxvis )
451 {
452 Display *dpy = glxvis->display;
453 XVisualInfo *vinfo = glxvis->visinfo;
454 Atom overlayVisualsAtom;
455 OverlayInfo *overlay_info = NULL;
456 int numOverlaysPerScreen;
457 Status status;
458 Atom actualType;
459 int actualFormat;
460 unsigned long sizeData, bytesLeft;
461 int i;
462
463 /*
464 * The SERVER_OVERLAY_VISUALS property on the root window contains
465 * a list of overlay visuals. Get that list now.
466 */
467 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
468 if (overlayVisualsAtom == None) {
469 return -1;
470 }
471
472 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
473 overlayVisualsAtom, 0L, (long) 10000, False,
474 overlayVisualsAtom, &actualType, &actualFormat,
475 &sizeData, &bytesLeft,
476 (unsigned char **) &overlay_info );
477
478 if (status != Success || actualType != overlayVisualsAtom ||
479 actualFormat != 32 || sizeData < 4) {
480 /* something went wrong */
481 XFree((void *) overlay_info);
482 return -1;
483 }
484
485 /* search the overlay visual list for the visual ID of interest */
486 numOverlaysPerScreen = (int) (sizeData / 4);
487 for (i=0;i<numOverlaysPerScreen;i++) {
488 OverlayInfo *ov;
489 ov = overlay_info + i;
490 if (ov->overlay_visual==vinfo->visualid) {
491 /* found it! */
492 if (ov->transparent_type==0) {
493 /* type 0 indicates no transparency */
494 XFree((void *) overlay_info);
495 return -1;
496 }
497 else {
498 /* ov->value is the transparent pixel */
499 XFree((void *) overlay_info);
500 return ov->value;
501 }
502 }
503 }
504
505 /* The visual ID was not found in the overlay list. */
506 XFree((void *) overlay_info);
507 return -1;
508 }
509
510
511
512 /*
513 * Try to get an X visual which matches the given arguments.
514 */
515 static XVisualInfo *get_visual( Display *dpy, int scr,
516 unsigned int depth, int xclass )
517 {
518 XVisualInfo temp, *vis;
519 long mask;
520 int n;
521 unsigned int default_depth;
522 int default_class;
523
524 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
525 temp.screen = scr;
526 temp.depth = depth;
527 temp.CLASS = xclass;
528
529 default_depth = DefaultDepth(dpy,scr);
530 default_class = DefaultVisual(dpy,scr)->CLASS;
531
532 if (depth==default_depth && xclass==default_class) {
533 /* try to get root window's visual */
534 temp.visualid = DefaultVisual(dpy,scr)->visualid;
535 mask |= VisualIDMask;
536 }
537
538 vis = XGetVisualInfo( dpy, mask, &temp, &n );
539
540 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
541 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
542 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
543 */
544 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
545 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
546 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
547 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
548 return vis;
549 }
550 else {
551 XFree((void *) vis);
552 return NULL;
553 }
554 }
555
556 return vis;
557 }
558
559
560
561 /*
562 * Retrieve the value of the given environment variable and find
563 * the X visual which matches it.
564 * Input: dpy - the display
565 * screen - the screen number
566 * varname - the name of the environment variable
567 * Return: an XVisualInfo pointer to NULL if error.
568 */
569 static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname)
570 {
571 char value[100], type[100];
572 int depth, xclass = -1;
573 XVisualInfo *vis;
574
575 if (!_mesa_getenv( varname )) {
576 return NULL;
577 }
578
579 _mesa_strncpy( value, _mesa_getenv(varname), 100 );
580 value[99] = 0;
581
582 sscanf( value, "%s %d", type, &depth );
583
584 if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor;
585 else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor;
586 else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
587 else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor;
588 else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale;
589 else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray;
590
591 if (xclass>-1 && depth>0) {
592 vis = get_visual( dpy, scr, depth, xclass );
593 if (vis) {
594 return vis;
595 }
596 }
597
598 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
599 type, depth);
600
601 return NULL;
602 }
603
604
605
606 /*
607 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
608 * Input: dpy, screen - X display and screen number
609 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
610 * min_depth - minimum visual depth
611 * preferred_class - preferred GLX visual class or DONT_CARE
612 * Return: pointer to an XVisualInfo or NULL.
613 */
614 static XVisualInfo *choose_x_visual( Display *dpy, int screen,
615 GLboolean rgba, int min_depth,
616 int preferred_class )
617 {
618 XVisualInfo *vis;
619 int xclass, visclass = 0;
620 int depth;
621
622 if (rgba) {
623 Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True);
624 /* First see if the MESA_RGB_VISUAL env var is defined */
625 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
626 if (vis) {
627 return vis;
628 }
629 /* Otherwise, search for a suitable visual */
630 if (preferred_class==DONT_CARE) {
631 for (xclass=0;xclass<6;xclass++) {
632 switch (xclass) {
633 case 0: visclass = TrueColor; break;
634 case 1: visclass = DirectColor; break;
635 case 2: visclass = PseudoColor; break;
636 case 3: visclass = StaticColor; break;
637 case 4: visclass = GrayScale; break;
638 case 5: visclass = StaticGray; break;
639 }
640 if (min_depth==0) {
641 /* start with shallowest */
642 for (depth=0;depth<=32;depth++) {
643 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
644 /* Special case: try to get 8-bit PseudoColor before */
645 /* 8-bit TrueColor */
646 vis = get_visual( dpy, screen, 8, PseudoColor );
647 if (vis) {
648 return vis;
649 }
650 }
651 vis = get_visual( dpy, screen, depth, visclass );
652 if (vis) {
653 return vis;
654 }
655 }
656 }
657 else {
658 /* start with deepest */
659 for (depth=32;depth>=min_depth;depth--) {
660 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
661 /* Special case: try to get 8-bit PseudoColor before */
662 /* 8-bit TrueColor */
663 vis = get_visual( dpy, screen, 8, PseudoColor );
664 if (vis) {
665 return vis;
666 }
667 }
668 vis = get_visual( dpy, screen, depth, visclass );
669 if (vis) {
670 return vis;
671 }
672 }
673 }
674 }
675 }
676 else {
677 /* search for a specific visual class */
678 switch (preferred_class) {
679 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
680 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
681 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
682 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
683 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
684 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
685 default: return NULL;
686 }
687 if (min_depth==0) {
688 /* start with shallowest */
689 for (depth=0;depth<=32;depth++) {
690 vis = get_visual( dpy, screen, depth, visclass );
691 if (vis) {
692 return vis;
693 }
694 }
695 }
696 else {
697 /* start with deepest */
698 for (depth=32;depth>=min_depth;depth--) {
699 vis = get_visual( dpy, screen, depth, visclass );
700 if (vis) {
701 return vis;
702 }
703 }
704 }
705 }
706 }
707 else {
708 /* First see if the MESA_CI_VISUAL env var is defined */
709 vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" );
710 if (vis) {
711 return vis;
712 }
713 /* Otherwise, search for a suitable visual, starting with shallowest */
714 if (preferred_class==DONT_CARE) {
715 for (xclass=0;xclass<4;xclass++) {
716 switch (xclass) {
717 case 0: visclass = PseudoColor; break;
718 case 1: visclass = StaticColor; break;
719 case 2: visclass = GrayScale; break;
720 case 3: visclass = StaticGray; break;
721 }
722 /* try 8-bit up through 16-bit */
723 for (depth=8;depth<=16;depth++) {
724 vis = get_visual( dpy, screen, depth, visclass );
725 if (vis) {
726 return vis;
727 }
728 }
729 /* try min_depth up to 8-bit */
730 for (depth=min_depth;depth<8;depth++) {
731 vis = get_visual( dpy, screen, depth, visclass );
732 if (vis) {
733 return vis;
734 }
735 }
736 }
737 }
738 else {
739 /* search for a specific visual class */
740 switch (preferred_class) {
741 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
742 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
743 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
744 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
745 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
746 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
747 default: return NULL;
748 }
749 /* try 8-bit up through 16-bit */
750 for (depth=8;depth<=16;depth++) {
751 vis = get_visual( dpy, screen, depth, visclass );
752 if (vis) {
753 return vis;
754 }
755 }
756 /* try min_depth up to 8-bit */
757 for (depth=min_depth;depth<8;depth++) {
758 vis = get_visual( dpy, screen, depth, visclass );
759 if (vis) {
760 return vis;
761 }
762 }
763 }
764 }
765
766 /* didn't find a visual */
767 return NULL;
768 }
769
770
771
772 /*
773 * Find the deepest X over/underlay visual of at least min_depth.
774 * Input: dpy, screen - X display and screen number
775 * level - the over/underlay level
776 * trans_type - transparent pixel type: GLX_NONE_EXT,
777 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
778 * or DONT_CARE
779 * trans_value - transparent pixel value or DONT_CARE
780 * min_depth - minimum visual depth
781 * preferred_class - preferred GLX visual class or DONT_CARE
782 * Return: pointer to an XVisualInfo or NULL.
783 */
784 static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr,
785 GLboolean rgbFlag,
786 int level, int trans_type,
787 int trans_value,
788 int min_depth,
789 int preferred_class )
790 {
791 Atom overlayVisualsAtom;
792 OverlayInfo *overlay_info;
793 int numOverlaysPerScreen;
794 Status status;
795 Atom actualType;
796 int actualFormat;
797 unsigned long sizeData, bytesLeft;
798 int i;
799 XVisualInfo *deepvis;
800 int deepest;
801
802 /*DEBUG int tt, tv; */
803
804 switch (preferred_class) {
805 case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break;
806 case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break;
807 case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break;
808 case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break;
809 case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break;
810 case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break;
811 default: preferred_class = DONT_CARE;
812 }
813
814 /*
815 * The SERVER_OVERLAY_VISUALS property on the root window contains
816 * a list of overlay visuals. Get that list now.
817 */
818 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
819 if (overlayVisualsAtom == (Atom) None) {
820 return NULL;
821 }
822
823 status = XGetWindowProperty(dpy, RootWindow( dpy, scr ),
824 overlayVisualsAtom, 0L, (long) 10000, False,
825 overlayVisualsAtom, &actualType, &actualFormat,
826 &sizeData, &bytesLeft,
827 (unsigned char **) &overlay_info );
828
829 if (status != Success || actualType != overlayVisualsAtom ||
830 actualFormat != 32 || sizeData < 4) {
831 /* something went wrong */
832 return NULL;
833 }
834
835 /* Search for the deepest overlay which satisifies all criteria. */
836 deepest = min_depth;
837 deepvis = NULL;
838
839 numOverlaysPerScreen = (int) (sizeData / 4);
840 for (i=0;i<numOverlaysPerScreen;i++) {
841 XVisualInfo *vislist, vistemplate;
842 int count;
843 OverlayInfo *ov;
844 ov = overlay_info + i;
845
846 if (ov->layer!=level) {
847 /* failed overlay level criteria */
848 continue;
849 }
850 if (!(trans_type==DONT_CARE
851 || (trans_type==GLX_TRANSPARENT_INDEX_EXT
852 && ov->transparent_type>0)
853 || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
854 /* failed transparent pixel type criteria */
855 continue;
856 }
857 if (trans_value!=DONT_CARE && trans_value!=ov->value) {
858 /* failed transparent pixel value criteria */
859 continue;
860 }
861
862 /* get XVisualInfo and check the depth */
863 vistemplate.visualid = ov->overlay_visual;
864 vistemplate.screen = scr;
865 vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
866 &vistemplate, &count );
867
868 if (count!=1) {
869 /* something went wrong */
870 continue;
871 }
872 if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
873 /* wrong visual class */
874 continue;
875 }
876
877 /* if RGB was requested, make sure we have True/DirectColor */
878 if (rgbFlag && vislist->CLASS != TrueColor
879 && vislist->CLASS != DirectColor)
880 continue;
881
882 /* if CI was requested, make sure we have a color indexed visual */
883 if (!rgbFlag
884 && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor))
885 continue;
886
887 if (deepvis==NULL || vislist->depth > deepest) {
888 /* YES! found a satisfactory visual */
889 if (deepvis) {
890 XFree( deepvis );
891 }
892 deepest = vislist->depth;
893 deepvis = vislist;
894 /* DEBUG tt = ov->transparent_type;*/
895 /* DEBUG tv = ov->value; */
896 }
897 }
898
899 /*DEBUG
900 if (deepvis) {
901 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
902 deepvis->visualid, level, deepvis->depth, tt, tv );
903 }
904 */
905 return deepvis;
906 }
907
908
909 /**********************************************************************/
910 /*** Begin Fake GLX API Functions ***/
911 /**********************************************************************/
912
913
914 static XMesaVisual choose_visual( Display *dpy, int screen, const int *list,
915 GLboolean rgbModeDefault )
916 {
917 const int *parselist;
918 XVisualInfo *vis;
919 int min_ci = 0;
920 int min_red=0, min_green=0, min_blue=0;
921 GLboolean rgb_flag = rgbModeDefault;
922 GLboolean alpha_flag = GL_FALSE;
923 GLboolean double_flag = GL_FALSE;
924 GLboolean stereo_flag = GL_FALSE;
925 GLint depth_size = 0;
926 GLint stencil_size = 0;
927 GLint accumRedSize = 0;
928 GLint accumGreenSize = 0;
929 GLint accumBlueSize = 0;
930 GLint accumAlphaSize = 0;
931 int level = 0;
932 int visual_type = DONT_CARE;
933 int trans_type = DONT_CARE;
934 int trans_value = DONT_CARE;
935 GLint caveat = DONT_CARE;
936 XMesaVisual xmvis = NULL;
937 int desiredVisualID = -1;
938 int numAux = 0;
939
940 parselist = list;
941
942 while (*parselist) {
943
944 switch (*parselist) {
945 case GLX_USE_GL:
946 /* ignore */
947 parselist++;
948 break;
949 case GLX_BUFFER_SIZE:
950 parselist++;
951 min_ci = *parselist++;
952 break;
953 case GLX_LEVEL:
954 parselist++;
955 level = *parselist++;
956 break;
957 case GLX_RGBA:
958 rgb_flag = GL_TRUE;
959 parselist++;
960 break;
961 case GLX_DOUBLEBUFFER:
962 double_flag = GL_TRUE;
963 parselist++;
964 break;
965 case GLX_STEREO:
966 stereo_flag = GL_TRUE;
967 return NULL;
968 case GLX_AUX_BUFFERS:
969 /* ignore */
970 parselist++;
971 numAux = *parselist++;
972 if (numAux > MAX_AUX_BUFFERS)
973 return NULL;
974 break;
975 case GLX_RED_SIZE:
976 parselist++;
977 min_red = *parselist++;
978 break;
979 case GLX_GREEN_SIZE:
980 parselist++;
981 min_green = *parselist++;
982 break;
983 case GLX_BLUE_SIZE:
984 parselist++;
985 min_blue = *parselist++;
986 break;
987 case GLX_ALPHA_SIZE:
988 parselist++;
989 {
990 GLint size = *parselist++;
991 alpha_flag = size>0 ? 1 : 0;
992 }
993 break;
994 case GLX_DEPTH_SIZE:
995 parselist++;
996 depth_size = *parselist++;
997 break;
998 case GLX_STENCIL_SIZE:
999 parselist++;
1000 stencil_size = *parselist++;
1001 break;
1002 case GLX_ACCUM_RED_SIZE:
1003 parselist++;
1004 {
1005 GLint size = *parselist++;
1006 accumRedSize = MAX2( accumRedSize, size );
1007 }
1008 break;
1009 case GLX_ACCUM_GREEN_SIZE:
1010 parselist++;
1011 {
1012 GLint size = *parselist++;
1013 accumGreenSize = MAX2( accumGreenSize, size );
1014 }
1015 break;
1016 case GLX_ACCUM_BLUE_SIZE:
1017 parselist++;
1018 {
1019 GLint size = *parselist++;
1020 accumBlueSize = MAX2( accumBlueSize, size );
1021 }
1022 break;
1023 case GLX_ACCUM_ALPHA_SIZE:
1024 parselist++;
1025 {
1026 GLint size = *parselist++;
1027 accumAlphaSize = MAX2( accumAlphaSize, size );
1028 }
1029 break;
1030
1031 /*
1032 * GLX_EXT_visual_info extension
1033 */
1034 case GLX_X_VISUAL_TYPE_EXT:
1035 parselist++;
1036 visual_type = *parselist++;
1037 break;
1038 case GLX_TRANSPARENT_TYPE_EXT:
1039 parselist++;
1040 trans_type = *parselist++;
1041 break;
1042 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1043 parselist++;
1044 trans_value = *parselist++;
1045 break;
1046 case GLX_TRANSPARENT_RED_VALUE_EXT:
1047 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1048 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1049 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1050 /* ignore */
1051 parselist++;
1052 parselist++;
1053 break;
1054
1055 /*
1056 * GLX_EXT_visual_info extension
1057 */
1058 case GLX_VISUAL_CAVEAT_EXT:
1059 parselist++;
1060 caveat = *parselist++; /* ignored for now */
1061 break;
1062
1063 /*
1064 * GLX_ARB_multisample
1065 */
1066 case GLX_SAMPLE_BUFFERS_ARB:
1067 /* ms not supported */
1068 return NULL;
1069 case GLX_SAMPLES_ARB:
1070 /* ms not supported */
1071 return NULL;
1072
1073 /*
1074 * FBConfig attribs.
1075 */
1076 case GLX_RENDER_TYPE:
1077 parselist++;
1078 if (*parselist == GLX_RGBA_BIT) {
1079 rgb_flag = GL_TRUE;
1080 }
1081 else if (*parselist == GLX_COLOR_INDEX_BIT) {
1082 rgb_flag = GL_FALSE;
1083 }
1084 else if (*parselist == 0) {
1085 rgb_flag = GL_TRUE;
1086 }
1087 parselist++;
1088 break;
1089 case GLX_DRAWABLE_TYPE:
1090 parselist++;
1091 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
1092 return NULL; /* bad bit */
1093 }
1094 parselist++;
1095 break;
1096 case GLX_FBCONFIG_ID:
1097 parselist++;
1098 desiredVisualID = *parselist;
1099 break;
1100
1101 case None:
1102 /* end of list */
1103 break;
1104
1105 default:
1106 /* undefined attribute */
1107 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
1108 *parselist);
1109 return NULL;
1110 }
1111 }
1112
1113 (void) caveat;
1114
1115 /*
1116 * Since we're only simulating the GLX extension this function will never
1117 * find any real GL visuals. Instead, all we can do is try to find an RGB
1118 * or CI visual of appropriate depth. Other requested attributes such as
1119 * double buffering, depth buffer, etc. will be associated with the X
1120 * visual and stored in the VisualTable[].
1121 */
1122 if (desiredVisualID != -1) {
1123 /* try to get a specific visual, by visualID */
1124 XVisualInfo temp;
1125 int n;
1126 temp.visualid = desiredVisualID;
1127 temp.screen = screen;
1128 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
1129 if (vis) {
1130 /* give the visual some useful GLX attributes */
1131 double_flag = GL_TRUE;
1132 if (vis->depth > 8)
1133 rgb_flag = GL_TRUE;
1134 depth_size = DEFAULT_SOFTWARE_DEPTH_BITS;
1135 stencil_size = STENCIL_BITS;
1136 /* XXX accum??? */
1137 }
1138 }
1139 else if (level==0) {
1140 /* normal color planes */
1141 if (rgb_flag) {
1142 /* Get an RGB visual */
1143 int min_rgb = min_red + min_green + min_blue;
1144 if (min_rgb>1 && min_rgb<8) {
1145 /* a special case to be sure we can get a monochrome visual */
1146 min_rgb = 1;
1147 }
1148 vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type );
1149 }
1150 else {
1151 /* Get a color index visual */
1152 vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type );
1153 accumRedSize = accumGreenSize = accumBlueSize = accumAlphaSize = 0;
1154 }
1155 }
1156 else {
1157 /* over/underlay planes */
1158 if (rgb_flag) {
1159 /* rgba overlay */
1160 int min_rgb = min_red + min_green + min_blue;
1161 if (min_rgb>1 && min_rgb<8) {
1162 /* a special case to be sure we can get a monochrome visual */
1163 min_rgb = 1;
1164 }
1165 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1166 trans_type, trans_value, min_rgb, visual_type );
1167 }
1168 else {
1169 /* color index overlay */
1170 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1171 trans_type, trans_value, min_ci, visual_type );
1172 }
1173 }
1174
1175 if (vis) {
1176 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1177 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1178 * largest depth buffer size, which is 32bits/value. Instead, we
1179 * return 16 to maintain performance with earlier versions of Mesa.
1180 */
1181 if (depth_size > 24)
1182 depth_size = 31; /* 32 causes int overflow problems */
1183 else if (depth_size > 16)
1184 depth_size = 24;
1185 else if (depth_size > 0)
1186 depth_size = DEFAULT_SOFTWARE_DEPTH_BITS; /*16*/
1187
1188 /* we only support one size of stencil and accum buffers. */
1189 if (stencil_size > 0)
1190 stencil_size = STENCIL_BITS;
1191 if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
1192 accumAlphaSize > 0) {
1193 accumRedSize = ACCUM_BITS;
1194 accumGreenSize = ACCUM_BITS;
1195 accumBlueSize = ACCUM_BITS;
1196 accumAlphaSize = alpha_flag ? ACCUM_BITS : 0;
1197 }
1198
1199 xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1200 stereo_flag, depth_size, stencil_size,
1201 accumRedSize, accumGreenSize,
1202 accumBlueSize, accumAlphaSize, level, numAux );
1203 }
1204
1205 return xmvis;
1206 }
1207
1208
1209 static XVisualInfo *
1210 Fake_glXChooseVisual( Display *dpy, int screen, int *list )
1211 {
1212 XMesaVisual xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1213 if (xmvis) {
1214 #if 0
1215 return xmvis->vishandle;
1216 #else
1217 /* create a new vishandle - the cached one may be stale */
1218 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1219 if (xmvis->vishandle) {
1220 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1221 }
1222 return xmvis->vishandle;
1223 #endif
1224 }
1225 else
1226 return NULL;
1227 }
1228
1229
1230 static GLXContext
1231 Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1232 GLXContext share_list, Bool direct )
1233 {
1234 XMesaVisual xmvis;
1235 struct fake_glx_context *glxCtx;
1236 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
1237
1238 if (!dpy || !visinfo)
1239 return 0;
1240
1241 glxCtx = CALLOC_STRUCT(fake_glx_context);
1242 if (!glxCtx)
1243 return 0;
1244
1245 /* deallocate unused windows/buffers */
1246 XMesaGarbageCollect();
1247
1248 xmvis = find_glx_visual( dpy, visinfo );
1249 if (!xmvis) {
1250 /* This visual wasn't found with glXChooseVisual() */
1251 xmvis = create_glx_visual( dpy, visinfo );
1252 if (!xmvis) {
1253 /* unusable visual */
1254 FREE(glxCtx);
1255 return NULL;
1256 }
1257 }
1258
1259 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
1260 shareCtx ? shareCtx->xmesaContext : NULL);
1261 if (!glxCtx->xmesaContext) {
1262 FREE(glxCtx);
1263 return NULL;
1264 }
1265
1266 glxCtx->xmesaContext->direct = GL_FALSE;
1267 glxCtx->glxContext.isDirect = GL_FALSE;
1268 glxCtx->glxContext.currentDpy = dpy;
1269 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
1270
1271 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
1272
1273 return (GLXContext) glxCtx;
1274 }
1275
1276
1277 /* XXX these may have to be removed due to thread-safety issues. */
1278 static GLXContext MakeCurrent_PrevContext = 0;
1279 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1280 static GLXDrawable MakeCurrent_PrevReadable = 0;
1281 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1282 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1283
1284
1285 /* GLX 1.3 and later */
1286 static Bool
1287 Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1288 GLXDrawable read, GLXContext ctx )
1289 {
1290 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1291
1292 if (ctx && draw && read) {
1293 XMesaBuffer drawBuffer, readBuffer;
1294 XMesaContext xmctx = glxCtx->xmesaContext;
1295
1296 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1297 if (ctx == MakeCurrent_PrevContext
1298 && draw == MakeCurrent_PrevDrawable) {
1299 drawBuffer = MakeCurrent_PrevDrawBuffer;
1300 }
1301 else {
1302 drawBuffer = XMesaFindBuffer( dpy, draw );
1303 }
1304 if (!drawBuffer) {
1305 /* drawable must be a new window! */
1306 drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx);
1307 if (!drawBuffer) {
1308 /* Out of memory, or context/drawable depth mismatch */
1309 return False;
1310 }
1311 }
1312
1313 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1314 if (ctx == MakeCurrent_PrevContext
1315 && read == MakeCurrent_PrevReadable) {
1316 readBuffer = MakeCurrent_PrevReadBuffer;
1317 }
1318 else {
1319 readBuffer = XMesaFindBuffer( dpy, read );
1320 }
1321 if (!readBuffer) {
1322 /* drawable must be a new window! */
1323 readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual,
1324 read, xmctx);
1325 if (!readBuffer) {
1326 /* Out of memory, or context/drawable depth mismatch */
1327 return False;
1328 }
1329 }
1330
1331 MakeCurrent_PrevContext = ctx;
1332 MakeCurrent_PrevDrawable = draw;
1333 MakeCurrent_PrevReadable = read;
1334 MakeCurrent_PrevDrawBuffer = drawBuffer;
1335 MakeCurrent_PrevReadBuffer = readBuffer;
1336
1337 /* Now make current! */
1338 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1339 ((__GLXcontext *) ctx)->currentDpy = dpy;
1340 ((__GLXcontext *) ctx)->currentDrawable = draw;
1341 #ifndef GLX_BUILT_IN_XMESA
1342 ((__GLXcontext *) ctx)->currentReadable = read;
1343 #else
1344 __glXSetCurrentContext(ctx);
1345 #endif
1346 return True;
1347 }
1348 else {
1349 return False;
1350 }
1351 }
1352 else if (!ctx && !draw && !read) {
1353 /* release current context w/out assigning new one. */
1354 XMesaMakeCurrent( NULL, NULL );
1355 MakeCurrent_PrevContext = 0;
1356 MakeCurrent_PrevDrawable = 0;
1357 MakeCurrent_PrevReadable = 0;
1358 MakeCurrent_PrevDrawBuffer = 0;
1359 MakeCurrent_PrevReadBuffer = 0;
1360 #ifdef GLX_BUILT_IN_XMESA
1361 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1362 #endif
1363 return True;
1364 }
1365 else {
1366 /* The args must either all be non-zero or all zero.
1367 * This is an error.
1368 */
1369 return False;
1370 }
1371 }
1372
1373
1374
1375 static Bool
1376 Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1377 {
1378 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1379 }
1380
1381
1382
1383 static GLXPixmap
1384 Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1385 {
1386 XMesaVisual v;
1387 XMesaBuffer b;
1388
1389 v = find_glx_visual( dpy, visinfo );
1390 if (!v) {
1391 v = create_glx_visual( dpy, visinfo );
1392 if (!v) {
1393 /* unusable visual */
1394 return 0;
1395 }
1396 }
1397
1398 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1399 if (!b) {
1400 return 0;
1401 }
1402 return b->frontbuffer;
1403 }
1404
1405
1406 /*** GLX_MESA_pixmap_colormap ***/
1407
1408 static GLXPixmap
1409 Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1410 Pixmap pixmap, Colormap cmap )
1411 {
1412 XMesaVisual v;
1413 XMesaBuffer b;
1414
1415 v = find_glx_visual( dpy, visinfo );
1416 if (!v) {
1417 v = create_glx_visual( dpy, visinfo );
1418 if (!v) {
1419 /* unusable visual */
1420 return 0;
1421 }
1422 }
1423
1424 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1425 if (!b) {
1426 return 0;
1427 }
1428 return b->frontbuffer;
1429 }
1430
1431
1432 static void
1433 Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1434 {
1435 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1436 if (b) {
1437 XMesaDestroyBuffer(b);
1438 }
1439 else if (_mesa_getenv("MESA_DEBUG")) {
1440 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1441 }
1442 }
1443
1444
1445
1446 static void
1447 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1448 unsigned long mask )
1449 {
1450 struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src;
1451 struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst;
1452 XMesaContext xm_src = fakeSrc->xmesaContext;
1453 XMesaContext xm_dst = fakeDst->xmesaContext;
1454 (void) dpy;
1455 _mesa_copy_context( &(xm_src->mesa), &(xm_dst->mesa), (GLuint) mask );
1456 }
1457
1458
1459
1460 static Bool
1461 Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1462 {
1463 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1464 (void) dpy;
1465 (void) errorb;
1466 (void) event;
1467 return True;
1468 }
1469
1470
1471 extern void _kw_ungrab_all( Display *dpy );
1472 void _kw_ungrab_all( Display *dpy )
1473 {
1474 XUngrabPointer( dpy, CurrentTime );
1475 XUngrabKeyboard( dpy, CurrentTime );
1476 }
1477
1478
1479 static void
1480 Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1481 {
1482 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1483 (void) dpy;
1484 MakeCurrent_PrevContext = 0;
1485 MakeCurrent_PrevDrawable = 0;
1486 MakeCurrent_PrevReadable = 0;
1487 MakeCurrent_PrevDrawBuffer = 0;
1488 MakeCurrent_PrevReadBuffer = 0;
1489 XMesaDestroyContext( glxCtx->xmesaContext );
1490 XMesaGarbageCollect();
1491 }
1492
1493
1494
1495 static Bool
1496 Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1497 {
1498 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1499 (void) dpy;
1500 return glxCtx->xmesaContext->direct;
1501 }
1502
1503
1504
1505 static void
1506 Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1507 {
1508 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1509
1510 if (buffer) {
1511 XMesaSwapBuffers(buffer);
1512 }
1513 else if (_mesa_getenv("MESA_DEBUG")) {
1514 _mesa_warning(NULL, "Mesa: glXSwapBuffers: invalid drawable\n");
1515 }
1516 }
1517
1518
1519
1520 /*** GLX_MESA_copy_sub_buffer ***/
1521
1522 static void
1523 Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1524 int x, int y, int width, int height )
1525 {
1526 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1527 if (buffer) {
1528 XMesaCopySubBuffer(buffer, x, y, width, height);
1529 }
1530 else if (_mesa_getenv("MESA_DEBUG")) {
1531 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1532 }
1533 }
1534
1535
1536
1537 static Bool
1538 Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1539 {
1540 (void) dpy;
1541 /* Return GLX version, not Mesa version */
1542 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1543 *maj = CLIENT_MAJOR_VERSION;
1544 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1545 return True;
1546 }
1547
1548
1549
1550 /*
1551 * Query the GLX attributes of the given XVisualInfo.
1552 */
1553 static int
1554 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1555 {
1556 ASSERT(xmvis);
1557 switch(attrib) {
1558 case GLX_USE_GL:
1559 *value = (int) True;
1560 return 0;
1561 case GLX_BUFFER_SIZE:
1562 *value = xmvis->visinfo->depth;
1563 return 0;
1564 case GLX_LEVEL:
1565 *value = xmvis->mesa_visual.level;
1566 return 0;
1567 case GLX_RGBA:
1568 if (xmvis->mesa_visual.rgbMode) {
1569 *value = True;
1570 }
1571 else {
1572 *value = False;
1573 }
1574 return 0;
1575 case GLX_DOUBLEBUFFER:
1576 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1577 return 0;
1578 case GLX_STEREO:
1579 *value = (int) xmvis->mesa_visual.stereoMode;
1580 return 0;
1581 case GLX_AUX_BUFFERS:
1582 *value = xmvis->mesa_visual.numAuxBuffers;
1583 return 0;
1584 case GLX_RED_SIZE:
1585 *value = xmvis->mesa_visual.redBits;
1586 return 0;
1587 case GLX_GREEN_SIZE:
1588 *value = xmvis->mesa_visual.greenBits;
1589 return 0;
1590 case GLX_BLUE_SIZE:
1591 *value = xmvis->mesa_visual.blueBits;
1592 return 0;
1593 case GLX_ALPHA_SIZE:
1594 *value = xmvis->mesa_visual.alphaBits;
1595 return 0;
1596 case GLX_DEPTH_SIZE:
1597 *value = xmvis->mesa_visual.depthBits;
1598 return 0;
1599 case GLX_STENCIL_SIZE:
1600 *value = xmvis->mesa_visual.stencilBits;
1601 return 0;
1602 case GLX_ACCUM_RED_SIZE:
1603 *value = xmvis->mesa_visual.accumRedBits;
1604 return 0;
1605 case GLX_ACCUM_GREEN_SIZE:
1606 *value = xmvis->mesa_visual.accumGreenBits;
1607 return 0;
1608 case GLX_ACCUM_BLUE_SIZE:
1609 *value = xmvis->mesa_visual.accumBlueBits;
1610 return 0;
1611 case GLX_ACCUM_ALPHA_SIZE:
1612 *value = xmvis->mesa_visual.accumAlphaBits;
1613 return 0;
1614
1615 /*
1616 * GLX_EXT_visual_info extension
1617 */
1618 case GLX_X_VISUAL_TYPE_EXT:
1619 switch (xmvis->visinfo->CLASS) {
1620 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1621 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1622 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1623 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1624 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1625 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1626 }
1627 return 0;
1628 case GLX_TRANSPARENT_TYPE_EXT:
1629 if (xmvis->mesa_visual.level==0) {
1630 /* normal planes */
1631 *value = GLX_NONE_EXT;
1632 }
1633 else if (xmvis->mesa_visual.level>0) {
1634 /* overlay */
1635 if (xmvis->mesa_visual.rgbMode) {
1636 *value = GLX_TRANSPARENT_RGB_EXT;
1637 }
1638 else {
1639 *value = GLX_TRANSPARENT_INDEX_EXT;
1640 }
1641 }
1642 else if (xmvis->mesa_visual.level<0) {
1643 /* underlay */
1644 *value = GLX_NONE_EXT;
1645 }
1646 return 0;
1647 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1648 {
1649 int pixel = transparent_pixel( xmvis );
1650 if (pixel>=0) {
1651 *value = pixel;
1652 }
1653 /* else undefined */
1654 }
1655 return 0;
1656 case GLX_TRANSPARENT_RED_VALUE_EXT:
1657 /* undefined */
1658 return 0;
1659 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1660 /* undefined */
1661 return 0;
1662 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1663 /* undefined */
1664 return 0;
1665 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1666 /* undefined */
1667 return 0;
1668
1669 /*
1670 * GLX_EXT_visual_info extension
1671 */
1672 case GLX_VISUAL_CAVEAT_EXT:
1673 /* test for zero, just in case */
1674 if (xmvis->mesa_visual.visualRating > 0)
1675 *value = xmvis->mesa_visual.visualRating;
1676 else
1677 *value = GLX_NONE_EXT;
1678 return 0;
1679
1680 /*
1681 * GLX_ARB_multisample
1682 */
1683 case GLX_SAMPLE_BUFFERS_ARB:
1684 *value = 0;
1685 return 0;
1686 case GLX_SAMPLES_ARB:
1687 *value = 0;
1688 return 0;
1689
1690 /*
1691 * For FBConfigs:
1692 */
1693 case GLX_SCREEN_EXT:
1694 if (!fbconfig)
1695 return GLX_BAD_ATTRIBUTE;
1696 *value = xmvis->visinfo->screen;
1697 break;
1698 case GLX_DRAWABLE_TYPE: /*SGIX too */
1699 if (!fbconfig)
1700 return GLX_BAD_ATTRIBUTE;
1701 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1702 break;
1703 case GLX_RENDER_TYPE_SGIX:
1704 if (!fbconfig)
1705 return GLX_BAD_ATTRIBUTE;
1706 if (xmvis->mesa_visual.rgbMode)
1707 *value = GLX_RGBA_BIT;
1708 else
1709 *value = GLX_COLOR_INDEX_BIT;
1710 break;
1711 case GLX_X_RENDERABLE_SGIX:
1712 if (!fbconfig)
1713 return GLX_BAD_ATTRIBUTE;
1714 *value = True; /* XXX really? */
1715 break;
1716 case GLX_FBCONFIG_ID_SGIX:
1717 if (!fbconfig)
1718 return GLX_BAD_ATTRIBUTE;
1719 *value = xmvis->visinfo->visualid;
1720 break;
1721 case GLX_MAX_PBUFFER_WIDTH:
1722 if (!fbconfig)
1723 return GLX_BAD_ATTRIBUTE;
1724 /* XXX or MAX_WIDTH? */
1725 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1726 break;
1727 case GLX_MAX_PBUFFER_HEIGHT:
1728 if (!fbconfig)
1729 return GLX_BAD_ATTRIBUTE;
1730 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1731 break;
1732 case GLX_MAX_PBUFFER_PIXELS:
1733 if (!fbconfig)
1734 return GLX_BAD_ATTRIBUTE;
1735 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1736 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1737 break;
1738 case GLX_VISUAL_ID:
1739 if (!fbconfig)
1740 return GLX_BAD_ATTRIBUTE;
1741 *value = xmvis->visinfo->visualid;
1742 break;
1743
1744 default:
1745 return GLX_BAD_ATTRIBUTE;
1746 }
1747 return Success;
1748 }
1749
1750
1751 static int
1752 Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1753 int attrib, int *value )
1754 {
1755 XMesaVisual xmvis;
1756
1757 if (!dpy || !visinfo)
1758 return GLX_BAD_ATTRIBUTE;
1759
1760 xmvis = find_glx_visual( dpy, visinfo );
1761 if (!xmvis) {
1762 /* this visual wasn't obtained with glXChooseVisual */
1763 xmvis = create_glx_visual( dpy, visinfo );
1764 if (!xmvis) {
1765 /* this visual can't be used for GL rendering */
1766 if (attrib==GLX_USE_GL) {
1767 *value = (int) False;
1768 return 0;
1769 }
1770 else {
1771 return GLX_BAD_VISUAL;
1772 }
1773 }
1774 }
1775
1776 return get_config(xmvis, attrib, value, GL_FALSE);
1777 }
1778
1779
1780 static void
1781 Fake_glXWaitGL( void )
1782 {
1783 XMesaContext xmesa = XMesaGetCurrentContext();
1784 XMesaFlush( xmesa );
1785 }
1786
1787
1788
1789 static void
1790 Fake_glXWaitX( void )
1791 {
1792 XMesaContext xmesa = XMesaGetCurrentContext();
1793 XMesaFlush( xmesa );
1794 }
1795
1796
1797 static const char *
1798 get_extensions( void )
1799 {
1800 #ifdef FX
1801 const char *fx = _mesa_getenv("MESA_GLX_FX");
1802 if (fx && fx[0] != 'd') {
1803 return EXTENSIONS;
1804 }
1805 #endif
1806 return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
1807 }
1808
1809
1810
1811 /* GLX 1.1 and later */
1812 static const char *
1813 Fake_glXQueryExtensionsString( Display *dpy, int screen )
1814 {
1815 (void) dpy;
1816 (void) screen;
1817 return get_extensions();
1818 }
1819
1820
1821
1822 /* GLX 1.1 and later */
1823 static const char *
1824 Fake_glXQueryServerString( Display *dpy, int screen, int name )
1825 {
1826 static char version[1000];
1827 _mesa_sprintf(version, "%d.%d %s",
1828 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
1829
1830 (void) dpy;
1831 (void) screen;
1832
1833 switch (name) {
1834 case GLX_EXTENSIONS:
1835 return get_extensions();
1836 case GLX_VENDOR:
1837 return VENDOR;
1838 case GLX_VERSION:
1839 return version;
1840 default:
1841 return NULL;
1842 }
1843 }
1844
1845
1846
1847 /* GLX 1.1 and later */
1848 static const char *
1849 Fake_glXGetClientString( Display *dpy, int name )
1850 {
1851 static char version[1000];
1852 _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1853 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
1854
1855 (void) dpy;
1856
1857 switch (name) {
1858 case GLX_EXTENSIONS:
1859 return get_extensions();
1860 case GLX_VENDOR:
1861 return VENDOR;
1862 case GLX_VERSION:
1863 return version;
1864 default:
1865 return NULL;
1866 }
1867 }
1868
1869
1870
1871 /*
1872 * GLX 1.3 and later
1873 */
1874
1875
1876 static GLXFBConfig *
1877 Fake_glXChooseFBConfig( Display *dpy, int screen,
1878 const int *attribList, int *nitems )
1879 {
1880 XMesaVisual xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1881 if (xmvis) {
1882 GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
1883 if (!config) {
1884 *nitems = 0;
1885 return NULL;
1886 }
1887 *nitems = 1;
1888 config[0] = (GLXFBConfig) xmvis;
1889 return (GLXFBConfig *) config;
1890 }
1891 else {
1892 *nitems = 0;
1893 return NULL;
1894 }
1895 }
1896
1897
1898 static int
1899 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1900 int attribute, int *value )
1901 {
1902 XMesaVisual v = (XMesaVisual) config;
1903 (void) dpy;
1904 (void) config;
1905
1906 if (!dpy || !config || !value)
1907 return -1;
1908
1909 return get_config(v, attribute, value, GL_TRUE);
1910 }
1911
1912
1913 static GLXFBConfig *
1914 Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1915 {
1916 XVisualInfo *visuals, visTemplate;
1917 const long visMask = VisualScreenMask;
1918 int i;
1919
1920 /* Get list of all X visuals */
1921 visTemplate.screen = screen;
1922 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1923 if (*nelements > 0) {
1924 XMesaVisual *results;
1925 results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
1926 if (!results) {
1927 *nelements = 0;
1928 return NULL;
1929 }
1930 for (i = 0; i < *nelements; i++) {
1931 results[i] = create_glx_visual(dpy, visuals + i);
1932 }
1933 return (GLXFBConfig *) results;
1934 }
1935 return NULL;
1936 }
1937
1938
1939 static XVisualInfo *
1940 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1941 {
1942 if (dpy && config) {
1943 XMesaVisual xmvis = (XMesaVisual) config;
1944 #if 0
1945 return xmvis->vishandle;
1946 #else
1947 /* create a new vishandle - the cached one may be stale */
1948 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1949 if (xmvis->vishandle) {
1950 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1951 }
1952 return xmvis->vishandle;
1953 #endif
1954 }
1955 else {
1956 return NULL;
1957 }
1958 }
1959
1960
1961 static GLXWindow
1962 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1963 const int *attribList )
1964 {
1965 XMesaVisual xmvis = (XMesaVisual) config;
1966 XMesaBuffer xmbuf;
1967 if (!xmvis)
1968 return 0;
1969
1970 xmbuf = XMesaCreateWindowBuffer2(xmvis, win, NULL);
1971 if (!xmbuf)
1972 return 0;
1973
1974 (void) dpy;
1975 (void) attribList; /* Ignored in GLX 1.3 */
1976
1977 return win; /* A hack for now */
1978 }
1979
1980
1981 static void
1982 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1983 {
1984 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1985 if (b)
1986 XMesaDestroyBuffer(b);
1987 /* don't destroy X window */
1988 }
1989
1990
1991 /* XXX untested */
1992 static GLXPixmap
1993 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1994 const int *attribList )
1995 {
1996 XMesaVisual v = (XMesaVisual) config;
1997 XMesaBuffer b;
1998
1999 (void) dpy;
2000 (void) config;
2001 (void) pixmap;
2002 (void) attribList; /* Ignored in GLX 1.3 */
2003
2004 if (!dpy || !config || !pixmap)
2005 return 0;
2006
2007 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2008 if (!b) {
2009 return 0;
2010 }
2011
2012 return pixmap;
2013 }
2014
2015
2016 static void
2017 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2018 {
2019 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
2020 if (b)
2021 XMesaDestroyBuffer(b);
2022 /* don't destroy X pixmap */
2023 }
2024
2025
2026 static GLXPbuffer
2027 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2028 const int *attribList )
2029 {
2030 XMesaVisual xmvis = (XMesaVisual) config;
2031 XMesaBuffer xmbuf;
2032 const int *attrib;
2033 int width = 0, height = 0;
2034 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2035
2036 (void) dpy;
2037
2038 for (attrib = attribList; *attrib; attrib++) {
2039 switch (*attrib) {
2040 case GLX_PBUFFER_WIDTH:
2041 attrib++;
2042 width = *attrib;
2043 break;
2044 case GLX_PBUFFER_HEIGHT:
2045 attrib++;
2046 height = *attrib;
2047 break;
2048 case GLX_PRESERVED_CONTENTS:
2049 attrib++;
2050 preserveContents = *attrib; /* ignored */
2051 break;
2052 case GLX_LARGEST_PBUFFER:
2053 attrib++;
2054 useLargest = *attrib; /* ignored */
2055 break;
2056 default:
2057 return 0;
2058 }
2059 }
2060
2061 /* not used at this time */
2062 (void) useLargest;
2063 (void) preserveContents;
2064
2065 if (width == 0 || height == 0)
2066 return 0;
2067
2068 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2069 /* A GLXPbuffer handle must be an X Drawable because that's what
2070 * glXMakeCurrent takes.
2071 */
2072 return (GLXPbuffer) xmbuf->frontbuffer;
2073 }
2074
2075
2076 static void
2077 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2078 {
2079 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2080 if (b) {
2081 XMesaDestroyBuffer(b);
2082 }
2083 }
2084
2085
2086 static void
2087 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2088 unsigned int *value )
2089 {
2090 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2091 if (!xmbuf)
2092 return;
2093
2094 switch (attribute) {
2095 case GLX_WIDTH:
2096 *value = xmbuf->width;
2097 break;
2098 case GLX_HEIGHT:
2099 *value = xmbuf->height;
2100 break;
2101 case GLX_PRESERVED_CONTENTS:
2102 *value = True;
2103 break;
2104 case GLX_LARGEST_PBUFFER:
2105 *value = xmbuf->width * xmbuf->height;
2106 break;
2107 case GLX_FBCONFIG_ID:
2108 *value = xmbuf->xm_visual->visinfo->visualid;
2109 return;
2110 default:
2111 return; /* GLX_BAD_ATTRIBUTE? */
2112 }
2113 }
2114
2115
2116 static GLXContext
2117 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2118 int renderType, GLXContext shareList, Bool direct )
2119 {
2120 struct fake_glx_context *glxCtx;
2121 struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList;
2122 XMesaVisual xmvis = (XMesaVisual) config;
2123
2124 if (!dpy || !config ||
2125 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2126 return 0;
2127
2128 glxCtx = CALLOC_STRUCT(fake_glx_context);
2129 if (!glxCtx)
2130 return 0;
2131
2132 /* deallocate unused windows/buffers */
2133 XMesaGarbageCollect();
2134
2135 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2136 shareCtx ? shareCtx->xmesaContext : NULL);
2137 if (!glxCtx->xmesaContext) {
2138 FREE(glxCtx);
2139 return NULL;
2140 }
2141
2142 glxCtx->xmesaContext->direct = GL_FALSE;
2143 glxCtx->glxContext.isDirect = GL_FALSE;
2144 glxCtx->glxContext.currentDpy = dpy;
2145 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2146
2147 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2148
2149 return (GLXContext) glxCtx;
2150 }
2151
2152
2153 static int
2154 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2155 {
2156 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
2157 XMesaContext xmctx = glxCtx->xmesaContext;
2158
2159 (void) dpy;
2160 (void) ctx;
2161
2162 switch (attribute) {
2163 case GLX_FBCONFIG_ID:
2164 *value = xmctx->xm_visual->visinfo->visualid;
2165 break;
2166 case GLX_RENDER_TYPE:
2167 if (xmctx->xm_visual->mesa_visual.rgbMode)
2168 *value = GLX_RGBA_BIT;
2169 else
2170 *value = GLX_COLOR_INDEX_BIT;
2171 break;
2172 case GLX_SCREEN:
2173 *value = 0;
2174 return Success;
2175 default:
2176 return GLX_BAD_ATTRIBUTE;
2177 }
2178 return 0;
2179 }
2180
2181
2182 static void
2183 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2184 {
2185 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2186 if (xmbuf)
2187 xmbuf->selectedEvents = mask;
2188 }
2189
2190
2191 static void
2192 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2193 unsigned long *mask )
2194 {
2195 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2196 if (xmbuf)
2197 *mask = xmbuf->selectedEvents;
2198 else
2199 *mask = 0;
2200 }
2201
2202
2203
2204 /*** GLX_SGI_swap_control ***/
2205
2206 static int
2207 Fake_glXSwapIntervalSGI(int interval)
2208 {
2209 (void) interval;
2210 return 0;
2211 }
2212
2213
2214
2215 /*** GLX_SGI_video_sync ***/
2216
2217 static int
2218 Fake_glXGetVideoSyncSGI(unsigned int *count)
2219 {
2220 (void) count;
2221 return 0;
2222 }
2223
2224 static int
2225 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2226 {
2227 (void) divisor;
2228 (void) remainder;
2229 (void) count;
2230 return 0;
2231 }
2232
2233
2234
2235 /*** GLX_SGI_make_current_read ***/
2236
2237 static Bool
2238 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2239 {
2240 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
2241 }
2242
2243 /* not used
2244 static GLXDrawable
2245 Fake_glXGetCurrentReadDrawableSGI(void)
2246 {
2247 return 0;
2248 }
2249 */
2250
2251
2252 /*** GLX_SGIX_video_source ***/
2253 #if defined(_VL_H)
2254
2255 static GLXVideoSourceSGIX
2256 Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2257 {
2258 (void) dpy;
2259 (void) screen;
2260 (void) server;
2261 (void) path;
2262 (void) nodeClass;
2263 (void) drainNode;
2264 return 0;
2265 }
2266
2267 static void
2268 Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2269 {
2270 (void) dpy;
2271 (void) src;
2272 }
2273
2274 #endif
2275
2276
2277 /*** GLX_EXT_import_context ***/
2278
2279 static void
2280 Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2281 {
2282 (void) dpy;
2283 (void) context;
2284 }
2285
2286 static GLXContextID
2287 Fake_glXGetContextIDEXT(const GLXContext context)
2288 {
2289 (void) context;
2290 return 0;
2291 }
2292
2293 static GLXContext
2294 Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2295 {
2296 (void) dpy;
2297 (void) contextID;
2298 return 0;
2299 }
2300
2301 static int
2302 Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2303 {
2304 (void) dpy;
2305 (void) context;
2306 (void) attribute;
2307 (void) value;
2308 return 0;
2309 }
2310
2311
2312
2313 /*** GLX_SGIX_fbconfig ***/
2314
2315 static int
2316 Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2317 {
2318 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
2319 }
2320
2321 static GLXFBConfigSGIX *
2322 Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2323 {
2324 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2325 }
2326
2327
2328 static GLXPixmap
2329 Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2330 {
2331 XMesaVisual xmvis = (XMesaVisual) config;
2332 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2333 return xmbuf->frontbuffer; /* need to return an X ID */
2334 }
2335
2336
2337 static GLXContext
2338 Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2339 {
2340 XMesaVisual xmvis = (XMesaVisual) config;
2341 struct fake_glx_context *glxCtx;
2342 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
2343
2344 glxCtx = CALLOC_STRUCT(fake_glx_context);
2345 if (!glxCtx)
2346 return 0;
2347
2348 /* deallocate unused windows/buffers */
2349 XMesaGarbageCollect();
2350
2351 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2352 shareCtx ? shareCtx->xmesaContext : NULL);
2353 if (!glxCtx->xmesaContext) {
2354 FREE(glxCtx);
2355 return NULL;
2356 }
2357
2358 glxCtx->xmesaContext->direct = GL_FALSE;
2359 glxCtx->glxContext.isDirect = GL_FALSE;
2360 glxCtx->glxContext.currentDpy = dpy;
2361 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2362
2363 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2364
2365 return (GLXContext) glxCtx;
2366 }
2367
2368
2369 static XVisualInfo *
2370 Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2371 {
2372 return Fake_glXGetVisualFromFBConfig(dpy, config);
2373 }
2374
2375
2376 static GLXFBConfigSGIX
2377 Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2378 {
2379 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2380 if (!xmvis) {
2381 /* This visual wasn't found with glXChooseVisual() */
2382 xmvis = create_glx_visual(dpy, vis);
2383 }
2384
2385 return (GLXFBConfigSGIX) xmvis;
2386 }
2387
2388
2389
2390 /*** GLX_SGIX_pbuffer ***/
2391
2392 static GLXPbufferSGIX
2393 Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2394 unsigned int width, unsigned int height,
2395 int *attribList)
2396 {
2397 XMesaVisual xmvis = (XMesaVisual) config;
2398 XMesaBuffer xmbuf;
2399 const int *attrib;
2400 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2401
2402 (void) dpy;
2403
2404 for (attrib = attribList; attrib && *attrib; attrib++) {
2405 switch (*attrib) {
2406 case GLX_PRESERVED_CONTENTS_SGIX:
2407 attrib++;
2408 preserveContents = *attrib; /* ignored */
2409 break;
2410 case GLX_LARGEST_PBUFFER_SGIX:
2411 attrib++;
2412 useLargest = *attrib; /* ignored */
2413 break;
2414 default:
2415 return 0;
2416 }
2417 }
2418
2419 /* not used at this time */
2420 (void) useLargest;
2421 (void) preserveContents;
2422
2423 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2424 /* A GLXPbuffer handle must be an X Drawable because that's what
2425 * glXMakeCurrent takes.
2426 */
2427 return (GLXPbuffer) xmbuf->frontbuffer;
2428 }
2429
2430
2431 static void
2432 Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2433 {
2434 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2435 if (xmbuf) {
2436 XMesaDestroyBuffer(xmbuf);
2437 }
2438 }
2439
2440
2441 static int
2442 Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2443 {
2444 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2445
2446 if (!xmbuf) {
2447 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2448 return 0;
2449 }
2450
2451 switch (attribute) {
2452 case GLX_PRESERVED_CONTENTS_SGIX:
2453 *value = True;
2454 break;
2455 case GLX_LARGEST_PBUFFER_SGIX:
2456 *value = xmbuf->width * xmbuf->height;
2457 break;
2458 case GLX_WIDTH_SGIX:
2459 *value = xmbuf->width;
2460 break;
2461 case GLX_HEIGHT_SGIX:
2462 *value = xmbuf->height;
2463 break;
2464 case GLX_EVENT_MASK_SGIX:
2465 *value = 0; /* XXX might be wrong */
2466 break;
2467 default:
2468 *value = 0;
2469 }
2470 return 0;
2471 }
2472
2473
2474 static void
2475 Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2476 {
2477 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2478 if (xmbuf) {
2479 /* Note: we'll never generate clobber events */
2480 xmbuf->selectedEvents = mask;
2481 }
2482 }
2483
2484
2485 static void
2486 Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2487 {
2488 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2489 if (xmbuf) {
2490 *mask = xmbuf->selectedEvents;
2491 }
2492 else {
2493 *mask = 0;
2494 }
2495 }
2496
2497
2498
2499 /*** GLX_SGI_cushion ***/
2500
2501 static void
2502 Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2503 {
2504 (void) dpy;
2505 (void) win;
2506 (void) cushion;
2507 }
2508
2509
2510
2511 /*** GLX_SGIX_video_resize ***/
2512
2513 static int
2514 Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2515 {
2516 (void) dpy;
2517 (void) screen;
2518 (void) channel;
2519 (void) window;
2520 return 0;
2521 }
2522
2523 static int
2524 Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2525 {
2526 (void) dpy;
2527 (void) screen;
2528 (void) channel;
2529 (void) x;
2530 (void) y;
2531 (void) w;
2532 (void) h;
2533 return 0;
2534 }
2535
2536 static int
2537 Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2538 {
2539 (void) dpy;
2540 (void) screen;
2541 (void) channel;
2542 (void) x;
2543 (void) y;
2544 (void) w;
2545 (void) h;
2546 return 0;
2547 }
2548
2549 static int
2550 Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2551 {
2552 (void) dpy;
2553 (void) screen;
2554 (void) channel;
2555 (void) dx;
2556 (void) dy;
2557 (void) dw;
2558 (void) dh;
2559 return 0;
2560 }
2561
2562 static int
2563 Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2564 {
2565 (void) dpy;
2566 (void) screen;
2567 (void) channel;
2568 (void) synctype;
2569 return 0;
2570 }
2571
2572
2573
2574 /*** GLX_SGIX_dmbuffer **/
2575
2576 #if defined(_DM_BUFFER_H_)
2577 static Bool
2578 Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2579 {
2580 (void) dpy;
2581 (void) pbuffer;
2582 (void) params;
2583 (void) dmbuffer;
2584 return False;
2585 }
2586 #endif
2587
2588
2589 /*** GLX_SGIX_swap_group ***/
2590
2591 static void
2592 Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2593 {
2594 (void) dpy;
2595 (void) drawable;
2596 (void) member;
2597 }
2598
2599
2600
2601 /*** GLX_SGIX_swap_barrier ***/
2602
2603 static void
2604 Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2605 {
2606 (void) dpy;
2607 (void) drawable;
2608 (void) barrier;
2609 }
2610
2611 static Bool
2612 Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2613 {
2614 (void) dpy;
2615 (void) screen;
2616 (void) max;
2617 return False;
2618 }
2619
2620
2621
2622 /*** GLX_SUN_get_transparent_index ***/
2623
2624 static Status
2625 Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2626 {
2627 (void) dpy;
2628 (void) overlay;
2629 (void) underlay;
2630 (void) pTransparent;
2631 return 0;
2632 }
2633
2634
2635
2636 /*** GLX_MESA_release_buffers ***/
2637
2638 /*
2639 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2640 * (a window or pixmap) prior to destroying the GLXDrawable.
2641 */
2642 static Bool
2643 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2644 {
2645 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2646 if (b) {
2647 XMesaDestroyBuffer(b);
2648 return True;
2649 }
2650 return False;
2651 }
2652
2653
2654
2655 /*** GLX_MESA_set_3dfx_mode ***/
2656
2657 static Bool
2658 Fake_glXSet3DfxModeMESA( int mode )
2659 {
2660 return XMesaSetFXmode( mode );
2661 }
2662
2663
2664
2665 /*** GLX_NV_vertex_array range ***/
2666 static void *
2667 Fake_glXAllocateMemoryNV( GLsizei size,
2668 GLfloat readFrequency,
2669 GLfloat writeFrequency,
2670 GLfloat priority )
2671 {
2672 (void) size;
2673 (void) readFrequency;
2674 (void) writeFrequency;
2675 (void) priority;
2676 return NULL;
2677 }
2678
2679
2680 static void
2681 Fake_glXFreeMemoryNV( GLvoid *pointer )
2682 {
2683 (void) pointer;
2684 }
2685
2686
2687 /*** GLX_MESA_agp_offset ***/
2688
2689 static GLuint
2690 Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2691 {
2692 (void) pointer;
2693 return ~0;
2694 }
2695
2696
2697 /*** GLX_ARB_render_texture ***/
2698
2699 static Bool
2700 Fake_glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer )
2701 {
2702 return False;
2703 }
2704
2705
2706 static Bool
2707 Fake_glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer )
2708 {
2709 return False;
2710 }
2711
2712
2713 static Bool
2714 Fake_glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList )
2715 {
2716 return False;
2717 }
2718
2719
2720
2721 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
2722 struct _glxapi_table *_mesa_GetGLXDispatchTable(void)
2723 {
2724 static struct _glxapi_table glx;
2725
2726 /* be sure our dispatch table size <= libGL's table */
2727 {
2728 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
2729 (void) size;
2730 assert(_glxapi_get_dispatch_table_size() >= size);
2731 }
2732
2733 /* initialize the whole table to no-ops */
2734 _glxapi_set_no_op_table(&glx);
2735
2736 /* now initialize the table with the functions I implement */
2737 glx.ChooseVisual = Fake_glXChooseVisual;
2738 glx.CopyContext = Fake_glXCopyContext;
2739 glx.CreateContext = Fake_glXCreateContext;
2740 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2741 glx.DestroyContext = Fake_glXDestroyContext;
2742 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2743 glx.GetConfig = Fake_glXGetConfig;
2744 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2745 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2746 glx.IsDirect = Fake_glXIsDirect;
2747 glx.MakeCurrent = Fake_glXMakeCurrent;
2748 glx.QueryExtension = Fake_glXQueryExtension;
2749 glx.QueryVersion = Fake_glXQueryVersion;
2750 glx.SwapBuffers = Fake_glXSwapBuffers;
2751 glx.UseXFont = Fake_glXUseXFont;
2752 glx.WaitGL = Fake_glXWaitGL;
2753 glx.WaitX = Fake_glXWaitX;
2754
2755 /*** GLX_VERSION_1_1 ***/
2756 glx.GetClientString = Fake_glXGetClientString;
2757 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2758 glx.QueryServerString = Fake_glXQueryServerString;
2759
2760 /*** GLX_VERSION_1_2 ***/
2761 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2762
2763 /*** GLX_VERSION_1_3 ***/
2764 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2765 glx.CreateNewContext = Fake_glXCreateNewContext;
2766 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2767 glx.CreatePixmap = Fake_glXCreatePixmap;
2768 glx.CreateWindow = Fake_glXCreateWindow;
2769 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2770 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2771 glx.DestroyWindow = Fake_glXDestroyWindow;
2772 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2773 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
2774 glx.GetFBConfigs = Fake_glXGetFBConfigs;
2775 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2776 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2777 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2778 glx.QueryContext = Fake_glXQueryContext;
2779 glx.QueryDrawable = Fake_glXQueryDrawable;
2780 glx.SelectEvent = Fake_glXSelectEvent;
2781
2782 /*** GLX_SGI_swap_control ***/
2783 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
2784
2785 /*** GLX_SGI_video_sync ***/
2786 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2787 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
2788
2789 /*** GLX_SGI_make_current_read ***/
2790 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
2791 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2792
2793 /*** GLX_SGIX_video_source ***/
2794 #if defined(_VL_H)
2795 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2796 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2797 #endif
2798
2799 /*** GLX_EXT_import_context ***/
2800 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2801 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
2802 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2803 glx.ImportContextEXT = Fake_glXImportContextEXT;
2804 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
2805
2806 /*** GLX_SGIX_fbconfig ***/
2807 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2808 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2809 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2810 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2811 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2812 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
2813
2814 /*** GLX_SGIX_pbuffer ***/
2815 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2816 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2817 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2818 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2819 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
2820
2821 /*** GLX_SGI_cushion ***/
2822 glx.CushionSGI = Fake_glXCushionSGI;
2823
2824 /*** GLX_SGIX_video_resize ***/
2825 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2826 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2827 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2828 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2829 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
2830
2831 /*** GLX_SGIX_dmbuffer **/
2832 #if defined(_DM_BUFFER_H_)
2833 glx.AssociateDMPbufferSGIX = NULL;
2834 #endif
2835
2836 /*** GLX_SGIX_swap_group ***/
2837 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
2838
2839 /*** GLX_SGIX_swap_barrier ***/
2840 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2841 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
2842
2843 /*** GLX_SUN_get_transparent_index ***/
2844 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
2845
2846 /*** GLX_MESA_copy_sub_buffer ***/
2847 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
2848
2849 /*** GLX_MESA_release_buffers ***/
2850 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
2851
2852 /*** GLX_MESA_pixmap_colormap ***/
2853 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
2854
2855 /*** GLX_MESA_set_3dfx_mode ***/
2856 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
2857
2858 /*** GLX_NV_vertex_array_range ***/
2859 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
2860 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
2861
2862 /*** GLX_MESA_agp_offset ***/
2863 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
2864
2865 /*** GLX_ARB_render_texture ***/
2866 glx.BindTexImageARB = Fake_glXBindTexImageARB;
2867 glx.ReleaseTexImageARB = Fake_glXReleaseTexImageARB;
2868 glx.DrawableAttribARB = Fake_glXDrawableAttribARB;
2869
2870 return &glx;
2871 }