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