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