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