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