small cleanup, remove some warnings
[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 static XMesaVisual
906 choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
907 {
908 const GLboolean rgbModeDefault = fbConfig;
909 const int *parselist;
910 XVisualInfo *vis;
911 int min_ci = 0;
912 int min_red=0, min_green=0, min_blue=0;
913 GLboolean rgb_flag = rgbModeDefault;
914 GLboolean alpha_flag = GL_FALSE;
915 GLboolean double_flag = GL_FALSE;
916 GLboolean stereo_flag = GL_FALSE;
917 GLint depth_size = 0;
918 GLint stencil_size = 0;
919 GLint accumRedSize = 0;
920 GLint accumGreenSize = 0;
921 GLint accumBlueSize = 0;
922 GLint accumAlphaSize = 0;
923 int level = 0;
924 int visual_type = DONT_CARE;
925 int trans_type = DONT_CARE;
926 int trans_value = DONT_CARE;
927 GLint caveat = DONT_CARE;
928 XMesaVisual xmvis = NULL;
929 int desiredVisualID = -1;
930 int numAux = 0;
931
932 parselist = list;
933
934 while (*parselist) {
935
936 switch (*parselist) {
937 case GLX_USE_GL:
938 if (fbConfig) {
939 /* invalid token */
940 return NULL;
941 }
942 else {
943 /* skip */
944 parselist++;
945 }
946 break;
947 case GLX_BUFFER_SIZE:
948 parselist++;
949 min_ci = *parselist++;
950 break;
951 case GLX_LEVEL:
952 parselist++;
953 level = *parselist++;
954 break;
955 case GLX_RGBA:
956 if (fbConfig) {
957 /* invalid token */
958 return NULL;
959 }
960 else {
961 rgb_flag = GL_TRUE;
962 parselist++;
963 }
964 break;
965 case GLX_DOUBLEBUFFER:
966 parselist++;
967 if (fbConfig) {
968 double_flag = *parselist++;
969 }
970 else {
971 double_flag = GL_TRUE;
972 }
973 break;
974 case GLX_STEREO:
975 parselist++;
976 if (fbConfig) {
977 stereo_flag = *parselist++;
978 }
979 else {
980 stereo_flag = GL_TRUE;
981 }
982 return NULL; /* stereo not supported */
983 case GLX_AUX_BUFFERS:
984 parselist++;
985 numAux = *parselist++;
986 if (numAux > MAX_AUX_BUFFERS)
987 return NULL;
988 break;
989 case GLX_RED_SIZE:
990 parselist++;
991 min_red = *parselist++;
992 break;
993 case GLX_GREEN_SIZE:
994 parselist++;
995 min_green = *parselist++;
996 break;
997 case GLX_BLUE_SIZE:
998 parselist++;
999 min_blue = *parselist++;
1000 break;
1001 case GLX_ALPHA_SIZE:
1002 parselist++;
1003 {
1004 GLint size = *parselist++;
1005 alpha_flag = size>0 ? 1 : 0;
1006 }
1007 break;
1008 case GLX_DEPTH_SIZE:
1009 parselist++;
1010 depth_size = *parselist++;
1011 break;
1012 case GLX_STENCIL_SIZE:
1013 parselist++;
1014 stencil_size = *parselist++;
1015 break;
1016 case GLX_ACCUM_RED_SIZE:
1017 parselist++;
1018 {
1019 GLint size = *parselist++;
1020 accumRedSize = MAX2( accumRedSize, size );
1021 }
1022 break;
1023 case GLX_ACCUM_GREEN_SIZE:
1024 parselist++;
1025 {
1026 GLint size = *parselist++;
1027 accumGreenSize = MAX2( accumGreenSize, size );
1028 }
1029 break;
1030 case GLX_ACCUM_BLUE_SIZE:
1031 parselist++;
1032 {
1033 GLint size = *parselist++;
1034 accumBlueSize = MAX2( accumBlueSize, size );
1035 }
1036 break;
1037 case GLX_ACCUM_ALPHA_SIZE:
1038 parselist++;
1039 {
1040 GLint size = *parselist++;
1041 accumAlphaSize = MAX2( accumAlphaSize, size );
1042 }
1043 break;
1044
1045 /*
1046 * GLX_EXT_visual_info extension
1047 */
1048 case GLX_X_VISUAL_TYPE_EXT:
1049 parselist++;
1050 visual_type = *parselist++;
1051 break;
1052 case GLX_TRANSPARENT_TYPE_EXT:
1053 parselist++;
1054 trans_type = *parselist++;
1055 break;
1056 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1057 parselist++;
1058 trans_value = *parselist++;
1059 break;
1060 case GLX_TRANSPARENT_RED_VALUE_EXT:
1061 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1062 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1063 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1064 /* ignore */
1065 parselist++;
1066 parselist++;
1067 break;
1068
1069 /*
1070 * GLX_EXT_visual_info extension
1071 */
1072 case GLX_VISUAL_CAVEAT_EXT:
1073 parselist++;
1074 caveat = *parselist++; /* ignored for now */
1075 break;
1076
1077 /*
1078 * GLX_ARB_multisample
1079 */
1080 case GLX_SAMPLE_BUFFERS_ARB:
1081 /* ms not supported */
1082 return NULL;
1083 case GLX_SAMPLES_ARB:
1084 /* ms not supported */
1085 return NULL;
1086
1087 /*
1088 * FBConfig attribs.
1089 */
1090 case GLX_RENDER_TYPE:
1091 parselist++;
1092 if (*parselist == GLX_RGBA_BIT) {
1093 rgb_flag = GL_TRUE;
1094 }
1095 else if (*parselist == GLX_COLOR_INDEX_BIT) {
1096 rgb_flag = GL_FALSE;
1097 }
1098 else if (*parselist == 0) {
1099 rgb_flag = GL_TRUE;
1100 }
1101 parselist++;
1102 break;
1103 case GLX_DRAWABLE_TYPE:
1104 parselist++;
1105 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
1106 return NULL; /* bad bit */
1107 }
1108 parselist++;
1109 break;
1110 case GLX_FBCONFIG_ID:
1111 parselist++;
1112 desiredVisualID = *parselist;
1113 break;
1114
1115 case None:
1116 /* end of list */
1117 break;
1118
1119 default:
1120 /* undefined attribute */
1121 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
1122 *parselist);
1123 return NULL;
1124 }
1125 }
1126
1127 (void) caveat;
1128
1129 /*
1130 * Since we're only simulating the GLX extension this function will never
1131 * find any real GL visuals. Instead, all we can do is try to find an RGB
1132 * or CI visual of appropriate depth. Other requested attributes such as
1133 * double buffering, depth buffer, etc. will be associated with the X
1134 * visual and stored in the VisualTable[].
1135 */
1136 if (desiredVisualID != -1) {
1137 /* try to get a specific visual, by visualID */
1138 XVisualInfo temp;
1139 int n;
1140 temp.visualid = desiredVisualID;
1141 temp.screen = screen;
1142 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
1143 if (vis) {
1144 /* give the visual some useful GLX attributes */
1145 double_flag = GL_TRUE;
1146 if (vis->depth > 8)
1147 rgb_flag = GL_TRUE;
1148 depth_size = default_depth_bits();
1149 stencil_size = STENCIL_BITS;
1150 /* XXX accum??? */
1151 }
1152 }
1153 else if (level==0) {
1154 /* normal color planes */
1155 if (rgb_flag) {
1156 /* Get an RGB visual */
1157 int min_rgb = min_red + min_green + min_blue;
1158 if (min_rgb>1 && min_rgb<8) {
1159 /* a special case to be sure we can get a monochrome visual */
1160 min_rgb = 1;
1161 }
1162 vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type );
1163 }
1164 else {
1165 /* Get a color index visual */
1166 vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type );
1167 accumRedSize = accumGreenSize = accumBlueSize = accumAlphaSize = 0;
1168 }
1169 }
1170 else {
1171 /* over/underlay planes */
1172 if (rgb_flag) {
1173 /* rgba overlay */
1174 int min_rgb = min_red + min_green + min_blue;
1175 if (min_rgb>1 && min_rgb<8) {
1176 /* a special case to be sure we can get a monochrome visual */
1177 min_rgb = 1;
1178 }
1179 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1180 trans_type, trans_value, min_rgb, visual_type );
1181 }
1182 else {
1183 /* color index overlay */
1184 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1185 trans_type, trans_value, min_ci, visual_type );
1186 }
1187 }
1188
1189 if (vis) {
1190 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1191 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1192 * largest depth buffer size, which is 32bits/value. Instead, we
1193 * return 16 to maintain performance with earlier versions of Mesa.
1194 */
1195 if (depth_size > 24)
1196 depth_size = 31; /* 32 causes int overflow problems */
1197 else if (depth_size > 16)
1198 depth_size = 24;
1199 else if (depth_size > 0) {
1200 depth_size = default_depth_bits();
1201 }
1202
1203 /* we only support one size of stencil and accum buffers. */
1204 if (stencil_size > 0)
1205 stencil_size = STENCIL_BITS;
1206 if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
1207 accumAlphaSize > 0) {
1208 accumRedSize = ACCUM_BITS;
1209 accumGreenSize = ACCUM_BITS;
1210 accumBlueSize = ACCUM_BITS;
1211 accumAlphaSize = alpha_flag ? ACCUM_BITS : 0;
1212 }
1213
1214 xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1215 stereo_flag, depth_size, stencil_size,
1216 accumRedSize, accumGreenSize,
1217 accumBlueSize, accumAlphaSize, level, numAux );
1218 }
1219
1220 return xmvis;
1221 }
1222
1223
1224 static XVisualInfo *
1225 Fake_glXChooseVisual( Display *dpy, int screen, int *list )
1226 {
1227 XMesaVisual xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1228 if (xmvis) {
1229 #if 0
1230 return xmvis->vishandle;
1231 #else
1232 /* create a new vishandle - the cached one may be stale */
1233 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1234 if (xmvis->vishandle) {
1235 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1236 }
1237 return xmvis->vishandle;
1238 #endif
1239 }
1240 else
1241 return NULL;
1242 }
1243
1244
1245 static GLXContext
1246 Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1247 GLXContext share_list, Bool direct )
1248 {
1249 XMesaVisual xmvis;
1250 struct fake_glx_context *glxCtx;
1251 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
1252
1253 if (!dpy || !visinfo)
1254 return 0;
1255
1256 glxCtx = CALLOC_STRUCT(fake_glx_context);
1257 if (!glxCtx)
1258 return 0;
1259
1260 /* deallocate unused windows/buffers */
1261 XMesaGarbageCollect();
1262
1263 xmvis = find_glx_visual( dpy, visinfo );
1264 if (!xmvis) {
1265 /* This visual wasn't found with glXChooseVisual() */
1266 xmvis = create_glx_visual( dpy, visinfo );
1267 if (!xmvis) {
1268 /* unusable visual */
1269 FREE(glxCtx);
1270 return NULL;
1271 }
1272 }
1273
1274 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
1275 shareCtx ? shareCtx->xmesaContext : NULL);
1276 if (!glxCtx->xmesaContext) {
1277 FREE(glxCtx);
1278 return NULL;
1279 }
1280
1281 glxCtx->xmesaContext->direct = GL_FALSE;
1282 glxCtx->glxContext.isDirect = GL_FALSE;
1283 glxCtx->glxContext.currentDpy = dpy;
1284 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
1285
1286 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
1287
1288 return (GLXContext) glxCtx;
1289 }
1290
1291
1292 /* XXX these may have to be removed due to thread-safety issues. */
1293 static GLXContext MakeCurrent_PrevContext = 0;
1294 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1295 static GLXDrawable MakeCurrent_PrevReadable = 0;
1296 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1297 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1298
1299
1300 /* GLX 1.3 and later */
1301 static Bool
1302 Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1303 GLXDrawable read, GLXContext ctx )
1304 {
1305 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1306
1307 if (ctx && draw && read) {
1308 XMesaBuffer drawBuffer, readBuffer;
1309 XMesaContext xmctx = glxCtx->xmesaContext;
1310
1311 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1312 if (ctx == MakeCurrent_PrevContext
1313 && draw == MakeCurrent_PrevDrawable) {
1314 drawBuffer = MakeCurrent_PrevDrawBuffer;
1315 }
1316 else {
1317 drawBuffer = XMesaFindBuffer( dpy, draw );
1318 }
1319 if (!drawBuffer) {
1320 /* drawable must be a new window! */
1321 drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx);
1322 if (!drawBuffer) {
1323 /* Out of memory, or context/drawable depth mismatch */
1324 return False;
1325 }
1326 }
1327
1328 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1329 if (ctx == MakeCurrent_PrevContext
1330 && read == MakeCurrent_PrevReadable) {
1331 readBuffer = MakeCurrent_PrevReadBuffer;
1332 }
1333 else {
1334 readBuffer = XMesaFindBuffer( dpy, read );
1335 }
1336 if (!readBuffer) {
1337 /* drawable must be a new window! */
1338 readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual,
1339 read, xmctx);
1340 if (!readBuffer) {
1341 /* Out of memory, or context/drawable depth mismatch */
1342 return False;
1343 }
1344 }
1345
1346 MakeCurrent_PrevContext = ctx;
1347 MakeCurrent_PrevDrawable = draw;
1348 MakeCurrent_PrevReadable = read;
1349 MakeCurrent_PrevDrawBuffer = drawBuffer;
1350 MakeCurrent_PrevReadBuffer = readBuffer;
1351
1352 /* Now make current! */
1353 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1354 ((__GLXcontext *) ctx)->currentDpy = dpy;
1355 ((__GLXcontext *) ctx)->currentDrawable = draw;
1356 #ifndef GLX_BUILT_IN_XMESA
1357 ((__GLXcontext *) ctx)->currentReadable = read;
1358 #else
1359 __glXSetCurrentContext(ctx);
1360 #endif
1361 return True;
1362 }
1363 else {
1364 return False;
1365 }
1366 }
1367 else if (!ctx && !draw && !read) {
1368 /* release current context w/out assigning new one. */
1369 XMesaMakeCurrent( NULL, NULL );
1370 MakeCurrent_PrevContext = 0;
1371 MakeCurrent_PrevDrawable = 0;
1372 MakeCurrent_PrevReadable = 0;
1373 MakeCurrent_PrevDrawBuffer = 0;
1374 MakeCurrent_PrevReadBuffer = 0;
1375 #ifdef GLX_BUILT_IN_XMESA
1376 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1377 #endif
1378 return True;
1379 }
1380 else {
1381 /* The args must either all be non-zero or all zero.
1382 * This is an error.
1383 */
1384 return False;
1385 }
1386 }
1387
1388
1389 static Bool
1390 Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1391 {
1392 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1393 }
1394
1395
1396 static GLXPixmap
1397 Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1398 {
1399 XMesaVisual v;
1400 XMesaBuffer b;
1401
1402 v = find_glx_visual( dpy, visinfo );
1403 if (!v) {
1404 v = create_glx_visual( dpy, visinfo );
1405 if (!v) {
1406 /* unusable visual */
1407 return 0;
1408 }
1409 }
1410
1411 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1412 if (!b) {
1413 return 0;
1414 }
1415 return b->frontbuffer;
1416 }
1417
1418
1419 /*** GLX_MESA_pixmap_colormap ***/
1420
1421 static GLXPixmap
1422 Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1423 Pixmap pixmap, Colormap cmap )
1424 {
1425 XMesaVisual v;
1426 XMesaBuffer b;
1427
1428 v = find_glx_visual( dpy, visinfo );
1429 if (!v) {
1430 v = create_glx_visual( dpy, visinfo );
1431 if (!v) {
1432 /* unusable visual */
1433 return 0;
1434 }
1435 }
1436
1437 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1438 if (!b) {
1439 return 0;
1440 }
1441 return b->frontbuffer;
1442 }
1443
1444
1445 static void
1446 Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1447 {
1448 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1449 if (b) {
1450 XMesaDestroyBuffer(b);
1451 }
1452 else if (_mesa_getenv("MESA_DEBUG")) {
1453 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1454 }
1455 }
1456
1457
1458 static void
1459 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1460 unsigned long mask )
1461 {
1462 struct fake_glx_context *fakeSrc = (struct fake_glx_context *) src;
1463 struct fake_glx_context *fakeDst = (struct fake_glx_context *) dst;
1464 XMesaContext xm_src = fakeSrc->xmesaContext;
1465 XMesaContext xm_dst = fakeDst->xmesaContext;
1466 (void) dpy;
1467 _mesa_copy_context( &(xm_src->mesa), &(xm_dst->mesa), (GLuint) mask );
1468 }
1469
1470
1471 static Bool
1472 Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1473 {
1474 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1475 (void) dpy;
1476 (void) errorb;
1477 (void) event;
1478 return True;
1479 }
1480
1481
1482 extern void _kw_ungrab_all( Display *dpy );
1483 void _kw_ungrab_all( Display *dpy )
1484 {
1485 XUngrabPointer( dpy, CurrentTime );
1486 XUngrabKeyboard( dpy, CurrentTime );
1487 }
1488
1489
1490 static void
1491 Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1492 {
1493 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1494 (void) dpy;
1495 MakeCurrent_PrevContext = 0;
1496 MakeCurrent_PrevDrawable = 0;
1497 MakeCurrent_PrevReadable = 0;
1498 MakeCurrent_PrevDrawBuffer = 0;
1499 MakeCurrent_PrevReadBuffer = 0;
1500 XMesaDestroyContext( glxCtx->xmesaContext );
1501 XMesaGarbageCollect();
1502 }
1503
1504
1505 static Bool
1506 Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1507 {
1508 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1509 (void) dpy;
1510 return glxCtx->xmesaContext->direct;
1511 }
1512
1513
1514
1515 static void
1516 Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1517 {
1518 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1519
1520 if (buffer) {
1521 XMesaSwapBuffers(buffer);
1522 }
1523 else if (_mesa_getenv("MESA_DEBUG")) {
1524 _mesa_warning(NULL, "Mesa: glXSwapBuffers: invalid drawable\n");
1525 }
1526 }
1527
1528
1529
1530 /*** GLX_MESA_copy_sub_buffer ***/
1531
1532 static void
1533 Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1534 int x, int y, int width, int height )
1535 {
1536 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1537 if (buffer) {
1538 XMesaCopySubBuffer(buffer, x, y, width, height);
1539 }
1540 else if (_mesa_getenv("MESA_DEBUG")) {
1541 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1542 }
1543 }
1544
1545
1546 static Bool
1547 Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1548 {
1549 (void) dpy;
1550 /* Return GLX version, not Mesa version */
1551 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1552 *maj = CLIENT_MAJOR_VERSION;
1553 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1554 return True;
1555 }
1556
1557
1558 /*
1559 * Query the GLX attributes of the given XVisualInfo.
1560 */
1561 static int
1562 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1563 {
1564 ASSERT(xmvis);
1565 switch(attrib) {
1566 case GLX_USE_GL:
1567 if (fbconfig)
1568 return GLX_BAD_ATTRIBUTE;
1569 *value = (int) True;
1570 return 0;
1571 case GLX_BUFFER_SIZE:
1572 *value = xmvis->visinfo->depth;
1573 return 0;
1574 case GLX_LEVEL:
1575 *value = xmvis->mesa_visual.level;
1576 return 0;
1577 case GLX_RGBA:
1578 if (fbconfig)
1579 return GLX_BAD_ATTRIBUTE;
1580 if (xmvis->mesa_visual.rgbMode) {
1581 *value = True;
1582 }
1583 else {
1584 *value = False;
1585 }
1586 return 0;
1587 case GLX_DOUBLEBUFFER:
1588 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1589 return 0;
1590 case GLX_STEREO:
1591 *value = (int) xmvis->mesa_visual.stereoMode;
1592 return 0;
1593 case GLX_AUX_BUFFERS:
1594 *value = xmvis->mesa_visual.numAuxBuffers;
1595 return 0;
1596 case GLX_RED_SIZE:
1597 *value = xmvis->mesa_visual.redBits;
1598 return 0;
1599 case GLX_GREEN_SIZE:
1600 *value = xmvis->mesa_visual.greenBits;
1601 return 0;
1602 case GLX_BLUE_SIZE:
1603 *value = xmvis->mesa_visual.blueBits;
1604 return 0;
1605 case GLX_ALPHA_SIZE:
1606 *value = xmvis->mesa_visual.alphaBits;
1607 return 0;
1608 case GLX_DEPTH_SIZE:
1609 *value = xmvis->mesa_visual.depthBits;
1610 return 0;
1611 case GLX_STENCIL_SIZE:
1612 *value = xmvis->mesa_visual.stencilBits;
1613 return 0;
1614 case GLX_ACCUM_RED_SIZE:
1615 *value = xmvis->mesa_visual.accumRedBits;
1616 return 0;
1617 case GLX_ACCUM_GREEN_SIZE:
1618 *value = xmvis->mesa_visual.accumGreenBits;
1619 return 0;
1620 case GLX_ACCUM_BLUE_SIZE:
1621 *value = xmvis->mesa_visual.accumBlueBits;
1622 return 0;
1623 case GLX_ACCUM_ALPHA_SIZE:
1624 *value = xmvis->mesa_visual.accumAlphaBits;
1625 return 0;
1626
1627 /*
1628 * GLX_EXT_visual_info extension
1629 */
1630 case GLX_X_VISUAL_TYPE_EXT:
1631 switch (xmvis->visinfo->CLASS) {
1632 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1633 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1634 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1635 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1636 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1637 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1638 }
1639 return 0;
1640 case GLX_TRANSPARENT_TYPE_EXT:
1641 if (xmvis->mesa_visual.level==0) {
1642 /* normal planes */
1643 *value = GLX_NONE_EXT;
1644 }
1645 else if (xmvis->mesa_visual.level>0) {
1646 /* overlay */
1647 if (xmvis->mesa_visual.rgbMode) {
1648 *value = GLX_TRANSPARENT_RGB_EXT;
1649 }
1650 else {
1651 *value = GLX_TRANSPARENT_INDEX_EXT;
1652 }
1653 }
1654 else if (xmvis->mesa_visual.level<0) {
1655 /* underlay */
1656 *value = GLX_NONE_EXT;
1657 }
1658 return 0;
1659 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1660 {
1661 int pixel = transparent_pixel( xmvis );
1662 if (pixel>=0) {
1663 *value = pixel;
1664 }
1665 /* else undefined */
1666 }
1667 return 0;
1668 case GLX_TRANSPARENT_RED_VALUE_EXT:
1669 /* undefined */
1670 return 0;
1671 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1672 /* undefined */
1673 return 0;
1674 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1675 /* undefined */
1676 return 0;
1677 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1678 /* undefined */
1679 return 0;
1680
1681 /*
1682 * GLX_EXT_visual_info extension
1683 */
1684 case GLX_VISUAL_CAVEAT_EXT:
1685 /* test for zero, just in case */
1686 if (xmvis->mesa_visual.visualRating > 0)
1687 *value = xmvis->mesa_visual.visualRating;
1688 else
1689 *value = GLX_NONE_EXT;
1690 return 0;
1691
1692 /*
1693 * GLX_ARB_multisample
1694 */
1695 case GLX_SAMPLE_BUFFERS_ARB:
1696 *value = 0;
1697 return 0;
1698 case GLX_SAMPLES_ARB:
1699 *value = 0;
1700 return 0;
1701
1702 /*
1703 * For FBConfigs:
1704 */
1705 case GLX_SCREEN_EXT:
1706 if (!fbconfig)
1707 return GLX_BAD_ATTRIBUTE;
1708 *value = xmvis->visinfo->screen;
1709 break;
1710 case GLX_DRAWABLE_TYPE: /*SGIX too */
1711 if (!fbconfig)
1712 return GLX_BAD_ATTRIBUTE;
1713 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1714 break;
1715 case GLX_RENDER_TYPE_SGIX:
1716 if (!fbconfig)
1717 return GLX_BAD_ATTRIBUTE;
1718 if (xmvis->mesa_visual.rgbMode)
1719 *value = GLX_RGBA_BIT;
1720 else
1721 *value = GLX_COLOR_INDEX_BIT;
1722 break;
1723 case GLX_X_RENDERABLE_SGIX:
1724 if (!fbconfig)
1725 return GLX_BAD_ATTRIBUTE;
1726 *value = True; /* XXX really? */
1727 break;
1728 case GLX_FBCONFIG_ID_SGIX:
1729 if (!fbconfig)
1730 return GLX_BAD_ATTRIBUTE;
1731 *value = xmvis->visinfo->visualid;
1732 break;
1733 case GLX_MAX_PBUFFER_WIDTH:
1734 if (!fbconfig)
1735 return GLX_BAD_ATTRIBUTE;
1736 /* XXX or MAX_WIDTH? */
1737 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1738 break;
1739 case GLX_MAX_PBUFFER_HEIGHT:
1740 if (!fbconfig)
1741 return GLX_BAD_ATTRIBUTE;
1742 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1743 break;
1744 case GLX_MAX_PBUFFER_PIXELS:
1745 if (!fbconfig)
1746 return GLX_BAD_ATTRIBUTE;
1747 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1748 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1749 break;
1750 case GLX_VISUAL_ID:
1751 if (!fbconfig)
1752 return GLX_BAD_ATTRIBUTE;
1753 *value = xmvis->visinfo->visualid;
1754 break;
1755
1756 default:
1757 return GLX_BAD_ATTRIBUTE;
1758 }
1759 return Success;
1760 }
1761
1762
1763 static int
1764 Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1765 int attrib, int *value )
1766 {
1767 XMesaVisual xmvis;
1768
1769 if (!dpy || !visinfo)
1770 return GLX_BAD_ATTRIBUTE;
1771
1772 xmvis = find_glx_visual( dpy, visinfo );
1773 if (!xmvis) {
1774 /* this visual wasn't obtained with glXChooseVisual */
1775 xmvis = create_glx_visual( dpy, visinfo );
1776 if (!xmvis) {
1777 /* this visual can't be used for GL rendering */
1778 if (attrib==GLX_USE_GL) {
1779 *value = (int) False;
1780 return 0;
1781 }
1782 else {
1783 return GLX_BAD_VISUAL;
1784 }
1785 }
1786 }
1787
1788 return get_config(xmvis, attrib, value, GL_FALSE);
1789 }
1790
1791
1792 static void
1793 Fake_glXWaitGL( void )
1794 {
1795 XMesaContext xmesa = XMesaGetCurrentContext();
1796 XMesaFlush( xmesa );
1797 }
1798
1799
1800
1801 static void
1802 Fake_glXWaitX( void )
1803 {
1804 XMesaContext xmesa = XMesaGetCurrentContext();
1805 XMesaFlush( xmesa );
1806 }
1807
1808
1809 static const char *
1810 get_extensions( void )
1811 {
1812 #ifdef FX
1813 const char *fx = _mesa_getenv("MESA_GLX_FX");
1814 if (fx && fx[0] != 'd') {
1815 return EXTENSIONS;
1816 }
1817 #endif
1818 return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
1819 }
1820
1821
1822
1823 /* GLX 1.1 and later */
1824 static const char *
1825 Fake_glXQueryExtensionsString( Display *dpy, int screen )
1826 {
1827 (void) dpy;
1828 (void) screen;
1829 return get_extensions();
1830 }
1831
1832
1833
1834 /* GLX 1.1 and later */
1835 static const char *
1836 Fake_glXQueryServerString( Display *dpy, int screen, int name )
1837 {
1838 static char version[1000];
1839 _mesa_sprintf(version, "%d.%d %s",
1840 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
1841
1842 (void) dpy;
1843 (void) screen;
1844
1845 switch (name) {
1846 case GLX_EXTENSIONS:
1847 return get_extensions();
1848 case GLX_VENDOR:
1849 return VENDOR;
1850 case GLX_VERSION:
1851 return version;
1852 default:
1853 return NULL;
1854 }
1855 }
1856
1857
1858
1859 /* GLX 1.1 and later */
1860 static const char *
1861 Fake_glXGetClientString( Display *dpy, int name )
1862 {
1863 static char version[1000];
1864 _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1865 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
1866
1867 (void) dpy;
1868
1869 switch (name) {
1870 case GLX_EXTENSIONS:
1871 return get_extensions();
1872 case GLX_VENDOR:
1873 return VENDOR;
1874 case GLX_VERSION:
1875 return version;
1876 default:
1877 return NULL;
1878 }
1879 }
1880
1881
1882
1883 /*
1884 * GLX 1.3 and later
1885 */
1886
1887
1888 static GLXFBConfig *
1889 Fake_glXChooseFBConfig( Display *dpy, int screen,
1890 const int *attribList, int *nitems )
1891 {
1892 XMesaVisual xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1893 if (xmvis) {
1894 GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
1895 if (!config) {
1896 *nitems = 0;
1897 return NULL;
1898 }
1899 *nitems = 1;
1900 config[0] = (GLXFBConfig) xmvis;
1901 return (GLXFBConfig *) config;
1902 }
1903 else {
1904 *nitems = 0;
1905 return NULL;
1906 }
1907 }
1908
1909
1910 static int
1911 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1912 int attribute, int *value )
1913 {
1914 XMesaVisual v = (XMesaVisual) config;
1915 (void) dpy;
1916 (void) config;
1917
1918 if (!dpy || !config || !value)
1919 return -1;
1920
1921 return get_config(v, attribute, value, GL_TRUE);
1922 }
1923
1924
1925 static GLXFBConfig *
1926 Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1927 {
1928 XVisualInfo *visuals, visTemplate;
1929 const long visMask = VisualScreenMask;
1930 int i;
1931
1932 /* Get list of all X visuals */
1933 visTemplate.screen = screen;
1934 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1935 if (*nelements > 0) {
1936 XMesaVisual *results;
1937 results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
1938 if (!results) {
1939 *nelements = 0;
1940 return NULL;
1941 }
1942 for (i = 0; i < *nelements; i++) {
1943 results[i] = create_glx_visual(dpy, visuals + i);
1944 }
1945 return (GLXFBConfig *) results;
1946 }
1947 return NULL;
1948 }
1949
1950
1951 static XVisualInfo *
1952 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1953 {
1954 if (dpy && config) {
1955 XMesaVisual xmvis = (XMesaVisual) config;
1956 #if 0
1957 return xmvis->vishandle;
1958 #else
1959 /* create a new vishandle - the cached one may be stale */
1960 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1961 if (xmvis->vishandle) {
1962 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1963 }
1964 return xmvis->vishandle;
1965 #endif
1966 }
1967 else {
1968 return NULL;
1969 }
1970 }
1971
1972
1973 static GLXWindow
1974 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1975 const int *attribList )
1976 {
1977 XMesaVisual xmvis = (XMesaVisual) config;
1978 XMesaBuffer xmbuf;
1979 if (!xmvis)
1980 return 0;
1981
1982 xmbuf = XMesaCreateWindowBuffer2(xmvis, win, NULL);
1983 if (!xmbuf)
1984 return 0;
1985
1986 (void) dpy;
1987 (void) attribList; /* Ignored in GLX 1.3 */
1988
1989 return win; /* A hack for now */
1990 }
1991
1992
1993 static void
1994 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1995 {
1996 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1997 if (b)
1998 XMesaDestroyBuffer(b);
1999 /* don't destroy X window */
2000 }
2001
2002
2003 /* XXX untested */
2004 static GLXPixmap
2005 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
2006 const int *attribList )
2007 {
2008 XMesaVisual v = (XMesaVisual) config;
2009 XMesaBuffer b;
2010
2011 (void) dpy;
2012 (void) config;
2013 (void) pixmap;
2014 (void) attribList; /* Ignored in GLX 1.3 */
2015
2016 if (!dpy || !config || !pixmap)
2017 return 0;
2018
2019 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2020 if (!b) {
2021 return 0;
2022 }
2023
2024 return pixmap;
2025 }
2026
2027
2028 static void
2029 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2030 {
2031 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
2032 if (b)
2033 XMesaDestroyBuffer(b);
2034 /* don't destroy X pixmap */
2035 }
2036
2037
2038 static GLXPbuffer
2039 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2040 const int *attribList )
2041 {
2042 XMesaVisual xmvis = (XMesaVisual) config;
2043 XMesaBuffer xmbuf;
2044 const int *attrib;
2045 int width = 0, height = 0;
2046 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2047
2048 (void) dpy;
2049
2050 for (attrib = attribList; *attrib; attrib++) {
2051 switch (*attrib) {
2052 case GLX_PBUFFER_WIDTH:
2053 attrib++;
2054 width = *attrib;
2055 break;
2056 case GLX_PBUFFER_HEIGHT:
2057 attrib++;
2058 height = *attrib;
2059 break;
2060 case GLX_PRESERVED_CONTENTS:
2061 attrib++;
2062 preserveContents = *attrib; /* ignored */
2063 break;
2064 case GLX_LARGEST_PBUFFER:
2065 attrib++;
2066 useLargest = *attrib; /* ignored */
2067 break;
2068 default:
2069 return 0;
2070 }
2071 }
2072
2073 /* not used at this time */
2074 (void) useLargest;
2075 (void) preserveContents;
2076
2077 if (width == 0 || height == 0)
2078 return 0;
2079
2080 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2081 /* A GLXPbuffer handle must be an X Drawable because that's what
2082 * glXMakeCurrent takes.
2083 */
2084 return (GLXPbuffer) xmbuf->frontbuffer;
2085 }
2086
2087
2088 static void
2089 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2090 {
2091 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2092 if (b) {
2093 XMesaDestroyBuffer(b);
2094 }
2095 }
2096
2097
2098 static void
2099 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2100 unsigned int *value )
2101 {
2102 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2103 if (!xmbuf)
2104 return;
2105
2106 switch (attribute) {
2107 case GLX_WIDTH:
2108 *value = xmbuf->mesa_buffer.Width;
2109 break;
2110 case GLX_HEIGHT:
2111 *value = xmbuf->mesa_buffer.Height;
2112 break;
2113 case GLX_PRESERVED_CONTENTS:
2114 *value = True;
2115 break;
2116 case GLX_LARGEST_PBUFFER:
2117 *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
2118 break;
2119 case GLX_FBCONFIG_ID:
2120 *value = xmbuf->xm_visual->visinfo->visualid;
2121 return;
2122 default:
2123 return; /* GLX_BAD_ATTRIBUTE? */
2124 }
2125 }
2126
2127
2128 static GLXContext
2129 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2130 int renderType, GLXContext shareList, Bool direct )
2131 {
2132 struct fake_glx_context *glxCtx;
2133 struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList;
2134 XMesaVisual xmvis = (XMesaVisual) config;
2135
2136 if (!dpy || !config ||
2137 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2138 return 0;
2139
2140 glxCtx = CALLOC_STRUCT(fake_glx_context);
2141 if (!glxCtx)
2142 return 0;
2143
2144 /* deallocate unused windows/buffers */
2145 XMesaGarbageCollect();
2146
2147 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2148 shareCtx ? shareCtx->xmesaContext : NULL);
2149 if (!glxCtx->xmesaContext) {
2150 FREE(glxCtx);
2151 return NULL;
2152 }
2153
2154 glxCtx->xmesaContext->direct = GL_FALSE;
2155 glxCtx->glxContext.isDirect = GL_FALSE;
2156 glxCtx->glxContext.currentDpy = dpy;
2157 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2158
2159 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2160
2161 return (GLXContext) glxCtx;
2162 }
2163
2164
2165 static int
2166 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2167 {
2168 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
2169 XMesaContext xmctx = glxCtx->xmesaContext;
2170
2171 (void) dpy;
2172 (void) ctx;
2173
2174 switch (attribute) {
2175 case GLX_FBCONFIG_ID:
2176 *value = xmctx->xm_visual->visinfo->visualid;
2177 break;
2178 case GLX_RENDER_TYPE:
2179 if (xmctx->xm_visual->mesa_visual.rgbMode)
2180 *value = GLX_RGBA_BIT;
2181 else
2182 *value = GLX_COLOR_INDEX_BIT;
2183 break;
2184 case GLX_SCREEN:
2185 *value = 0;
2186 return Success;
2187 default:
2188 return GLX_BAD_ATTRIBUTE;
2189 }
2190 return 0;
2191 }
2192
2193
2194 static void
2195 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2196 {
2197 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2198 if (xmbuf)
2199 xmbuf->selectedEvents = mask;
2200 }
2201
2202
2203 static void
2204 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2205 unsigned long *mask )
2206 {
2207 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2208 if (xmbuf)
2209 *mask = xmbuf->selectedEvents;
2210 else
2211 *mask = 0;
2212 }
2213
2214
2215
2216 /*** GLX_SGI_swap_control ***/
2217
2218 static int
2219 Fake_glXSwapIntervalSGI(int interval)
2220 {
2221 (void) interval;
2222 return 0;
2223 }
2224
2225
2226
2227 /*** GLX_SGI_video_sync ***/
2228
2229 static int
2230 Fake_glXGetVideoSyncSGI(unsigned int *count)
2231 {
2232 (void) count;
2233 return 0;
2234 }
2235
2236 static int
2237 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2238 {
2239 (void) divisor;
2240 (void) remainder;
2241 (void) count;
2242 return 0;
2243 }
2244
2245
2246
2247 /*** GLX_SGI_make_current_read ***/
2248
2249 static Bool
2250 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2251 {
2252 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
2253 }
2254
2255 /* not used
2256 static GLXDrawable
2257 Fake_glXGetCurrentReadDrawableSGI(void)
2258 {
2259 return 0;
2260 }
2261 */
2262
2263
2264 /*** GLX_SGIX_video_source ***/
2265 #if defined(_VL_H)
2266
2267 static GLXVideoSourceSGIX
2268 Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2269 {
2270 (void) dpy;
2271 (void) screen;
2272 (void) server;
2273 (void) path;
2274 (void) nodeClass;
2275 (void) drainNode;
2276 return 0;
2277 }
2278
2279 static void
2280 Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2281 {
2282 (void) dpy;
2283 (void) src;
2284 }
2285
2286 #endif
2287
2288
2289 /*** GLX_EXT_import_context ***/
2290
2291 static void
2292 Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2293 {
2294 (void) dpy;
2295 (void) context;
2296 }
2297
2298 static GLXContextID
2299 Fake_glXGetContextIDEXT(const GLXContext context)
2300 {
2301 (void) context;
2302 return 0;
2303 }
2304
2305 static GLXContext
2306 Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2307 {
2308 (void) dpy;
2309 (void) contextID;
2310 return 0;
2311 }
2312
2313 static int
2314 Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2315 {
2316 (void) dpy;
2317 (void) context;
2318 (void) attribute;
2319 (void) value;
2320 return 0;
2321 }
2322
2323
2324
2325 /*** GLX_SGIX_fbconfig ***/
2326
2327 static int
2328 Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2329 {
2330 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
2331 }
2332
2333 static GLXFBConfigSGIX *
2334 Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2335 {
2336 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2337 }
2338
2339
2340 static GLXPixmap
2341 Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2342 {
2343 XMesaVisual xmvis = (XMesaVisual) config;
2344 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2345 return xmbuf->frontbuffer; /* need to return an X ID */
2346 }
2347
2348
2349 static GLXContext
2350 Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2351 {
2352 XMesaVisual xmvis = (XMesaVisual) config;
2353 struct fake_glx_context *glxCtx;
2354 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
2355
2356 glxCtx = CALLOC_STRUCT(fake_glx_context);
2357 if (!glxCtx)
2358 return 0;
2359
2360 /* deallocate unused windows/buffers */
2361 XMesaGarbageCollect();
2362
2363 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2364 shareCtx ? shareCtx->xmesaContext : NULL);
2365 if (!glxCtx->xmesaContext) {
2366 FREE(glxCtx);
2367 return NULL;
2368 }
2369
2370 glxCtx->xmesaContext->direct = GL_FALSE;
2371 glxCtx->glxContext.isDirect = GL_FALSE;
2372 glxCtx->glxContext.currentDpy = dpy;
2373 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2374
2375 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2376
2377 return (GLXContext) glxCtx;
2378 }
2379
2380
2381 static XVisualInfo *
2382 Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2383 {
2384 return Fake_glXGetVisualFromFBConfig(dpy, config);
2385 }
2386
2387
2388 static GLXFBConfigSGIX
2389 Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2390 {
2391 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2392 if (!xmvis) {
2393 /* This visual wasn't found with glXChooseVisual() */
2394 xmvis = create_glx_visual(dpy, vis);
2395 }
2396
2397 return (GLXFBConfigSGIX) xmvis;
2398 }
2399
2400
2401
2402 /*** GLX_SGIX_pbuffer ***/
2403
2404 static GLXPbufferSGIX
2405 Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2406 unsigned int width, unsigned int height,
2407 int *attribList)
2408 {
2409 XMesaVisual xmvis = (XMesaVisual) config;
2410 XMesaBuffer xmbuf;
2411 const int *attrib;
2412 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2413
2414 (void) dpy;
2415
2416 for (attrib = attribList; attrib && *attrib; attrib++) {
2417 switch (*attrib) {
2418 case GLX_PRESERVED_CONTENTS_SGIX:
2419 attrib++;
2420 preserveContents = *attrib; /* ignored */
2421 break;
2422 case GLX_LARGEST_PBUFFER_SGIX:
2423 attrib++;
2424 useLargest = *attrib; /* ignored */
2425 break;
2426 default:
2427 return 0;
2428 }
2429 }
2430
2431 /* not used at this time */
2432 (void) useLargest;
2433 (void) preserveContents;
2434
2435 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2436 /* A GLXPbuffer handle must be an X Drawable because that's what
2437 * glXMakeCurrent takes.
2438 */
2439 return (GLXPbuffer) xmbuf->frontbuffer;
2440 }
2441
2442
2443 static void
2444 Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2445 {
2446 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2447 if (xmbuf) {
2448 XMesaDestroyBuffer(xmbuf);
2449 }
2450 }
2451
2452
2453 static int
2454 Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2455 {
2456 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2457
2458 if (!xmbuf) {
2459 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2460 return 0;
2461 }
2462
2463 switch (attribute) {
2464 case GLX_PRESERVED_CONTENTS_SGIX:
2465 *value = True;
2466 break;
2467 case GLX_LARGEST_PBUFFER_SGIX:
2468 *value = xmbuf->mesa_buffer.Width * xmbuf->mesa_buffer.Height;
2469 break;
2470 case GLX_WIDTH_SGIX:
2471 *value = xmbuf->mesa_buffer.Width;
2472 break;
2473 case GLX_HEIGHT_SGIX:
2474 *value = xmbuf->mesa_buffer.Height;
2475 break;
2476 case GLX_EVENT_MASK_SGIX:
2477 *value = 0; /* XXX might be wrong */
2478 break;
2479 default:
2480 *value = 0;
2481 }
2482 return 0;
2483 }
2484
2485
2486 static void
2487 Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2488 {
2489 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2490 if (xmbuf) {
2491 /* Note: we'll never generate clobber events */
2492 xmbuf->selectedEvents = mask;
2493 }
2494 }
2495
2496
2497 static void
2498 Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2499 {
2500 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2501 if (xmbuf) {
2502 *mask = xmbuf->selectedEvents;
2503 }
2504 else {
2505 *mask = 0;
2506 }
2507 }
2508
2509
2510
2511 /*** GLX_SGI_cushion ***/
2512
2513 static void
2514 Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2515 {
2516 (void) dpy;
2517 (void) win;
2518 (void) cushion;
2519 }
2520
2521
2522
2523 /*** GLX_SGIX_video_resize ***/
2524
2525 static int
2526 Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2527 {
2528 (void) dpy;
2529 (void) screen;
2530 (void) channel;
2531 (void) window;
2532 return 0;
2533 }
2534
2535 static int
2536 Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2537 {
2538 (void) dpy;
2539 (void) screen;
2540 (void) channel;
2541 (void) x;
2542 (void) y;
2543 (void) w;
2544 (void) h;
2545 return 0;
2546 }
2547
2548 static int
2549 Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2550 {
2551 (void) dpy;
2552 (void) screen;
2553 (void) channel;
2554 (void) x;
2555 (void) y;
2556 (void) w;
2557 (void) h;
2558 return 0;
2559 }
2560
2561 static int
2562 Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2563 {
2564 (void) dpy;
2565 (void) screen;
2566 (void) channel;
2567 (void) dx;
2568 (void) dy;
2569 (void) dw;
2570 (void) dh;
2571 return 0;
2572 }
2573
2574 static int
2575 Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2576 {
2577 (void) dpy;
2578 (void) screen;
2579 (void) channel;
2580 (void) synctype;
2581 return 0;
2582 }
2583
2584
2585
2586 /*** GLX_SGIX_dmbuffer **/
2587
2588 #if defined(_DM_BUFFER_H_)
2589 static Bool
2590 Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2591 {
2592 (void) dpy;
2593 (void) pbuffer;
2594 (void) params;
2595 (void) dmbuffer;
2596 return False;
2597 }
2598 #endif
2599
2600
2601 /*** GLX_SGIX_swap_group ***/
2602
2603 static void
2604 Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2605 {
2606 (void) dpy;
2607 (void) drawable;
2608 (void) member;
2609 }
2610
2611
2612
2613 /*** GLX_SGIX_swap_barrier ***/
2614
2615 static void
2616 Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2617 {
2618 (void) dpy;
2619 (void) drawable;
2620 (void) barrier;
2621 }
2622
2623 static Bool
2624 Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2625 {
2626 (void) dpy;
2627 (void) screen;
2628 (void) max;
2629 return False;
2630 }
2631
2632
2633
2634 /*** GLX_SUN_get_transparent_index ***/
2635
2636 static Status
2637 Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2638 {
2639 (void) dpy;
2640 (void) overlay;
2641 (void) underlay;
2642 (void) pTransparent;
2643 return 0;
2644 }
2645
2646
2647
2648 /*** GLX_MESA_release_buffers ***/
2649
2650 /*
2651 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2652 * (a window or pixmap) prior to destroying the GLXDrawable.
2653 */
2654 static Bool
2655 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2656 {
2657 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2658 if (b) {
2659 XMesaDestroyBuffer(b);
2660 return True;
2661 }
2662 return False;
2663 }
2664
2665
2666
2667 /*** GLX_MESA_set_3dfx_mode ***/
2668
2669 static Bool
2670 Fake_glXSet3DfxModeMESA( int mode )
2671 {
2672 return XMesaSetFXmode( mode );
2673 }
2674
2675
2676
2677 /*** GLX_NV_vertex_array range ***/
2678 static void *
2679 Fake_glXAllocateMemoryNV( GLsizei size,
2680 GLfloat readFrequency,
2681 GLfloat writeFrequency,
2682 GLfloat priority )
2683 {
2684 (void) size;
2685 (void) readFrequency;
2686 (void) writeFrequency;
2687 (void) priority;
2688 return NULL;
2689 }
2690
2691
2692 static void
2693 Fake_glXFreeMemoryNV( GLvoid *pointer )
2694 {
2695 (void) pointer;
2696 }
2697
2698
2699 /*** GLX_MESA_agp_offset ***/
2700
2701 static GLuint
2702 Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2703 {
2704 (void) pointer;
2705 return ~0;
2706 }
2707
2708
2709 /* silence warning */
2710 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
2711
2712
2713 /**
2714 * Create a new GLX API dispatch table with its function pointers
2715 * initialized to point to Mesa's "fake" GLX API functions.
2716 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2717 * returns a new dispatch table with all pointers initalized to point
2718 * to "real" GLX functions (which understand GLX wire protocol, etc).
2719 */
2720 struct _glxapi_table *
2721 _mesa_GetGLXDispatchTable(void)
2722 {
2723 static struct _glxapi_table glx;
2724
2725 /* be sure our dispatch table size <= libGL's table */
2726 {
2727 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
2728 (void) size;
2729 assert(_glxapi_get_dispatch_table_size() >= size);
2730 }
2731
2732 /* initialize the whole table to no-ops */
2733 _glxapi_set_no_op_table(&glx);
2734
2735 /* now initialize the table with the functions I implement */
2736 glx.ChooseVisual = Fake_glXChooseVisual;
2737 glx.CopyContext = Fake_glXCopyContext;
2738 glx.CreateContext = Fake_glXCreateContext;
2739 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2740 glx.DestroyContext = Fake_glXDestroyContext;
2741 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2742 glx.GetConfig = Fake_glXGetConfig;
2743 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2744 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2745 glx.IsDirect = Fake_glXIsDirect;
2746 glx.MakeCurrent = Fake_glXMakeCurrent;
2747 glx.QueryExtension = Fake_glXQueryExtension;
2748 glx.QueryVersion = Fake_glXQueryVersion;
2749 glx.SwapBuffers = Fake_glXSwapBuffers;
2750 glx.UseXFont = Fake_glXUseXFont;
2751 glx.WaitGL = Fake_glXWaitGL;
2752 glx.WaitX = Fake_glXWaitX;
2753
2754 /*** GLX_VERSION_1_1 ***/
2755 glx.GetClientString = Fake_glXGetClientString;
2756 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2757 glx.QueryServerString = Fake_glXQueryServerString;
2758
2759 /*** GLX_VERSION_1_2 ***/
2760 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2761
2762 /*** GLX_VERSION_1_3 ***/
2763 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2764 glx.CreateNewContext = Fake_glXCreateNewContext;
2765 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2766 glx.CreatePixmap = Fake_glXCreatePixmap;
2767 glx.CreateWindow = Fake_glXCreateWindow;
2768 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2769 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2770 glx.DestroyWindow = Fake_glXDestroyWindow;
2771 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2772 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
2773 glx.GetFBConfigs = Fake_glXGetFBConfigs;
2774 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2775 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2776 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2777 glx.QueryContext = Fake_glXQueryContext;
2778 glx.QueryDrawable = Fake_glXQueryDrawable;
2779 glx.SelectEvent = Fake_glXSelectEvent;
2780
2781 /*** GLX_SGI_swap_control ***/
2782 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
2783
2784 /*** GLX_SGI_video_sync ***/
2785 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2786 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
2787
2788 /*** GLX_SGI_make_current_read ***/
2789 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
2790 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2791
2792 /*** GLX_SGIX_video_source ***/
2793 #if defined(_VL_H)
2794 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2795 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2796 #endif
2797
2798 /*** GLX_EXT_import_context ***/
2799 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2800 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
2801 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2802 glx.ImportContextEXT = Fake_glXImportContextEXT;
2803 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
2804
2805 /*** GLX_SGIX_fbconfig ***/
2806 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2807 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2808 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2809 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2810 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2811 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
2812
2813 /*** GLX_SGIX_pbuffer ***/
2814 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2815 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2816 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2817 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2818 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
2819
2820 /*** GLX_SGI_cushion ***/
2821 glx.CushionSGI = Fake_glXCushionSGI;
2822
2823 /*** GLX_SGIX_video_resize ***/
2824 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2825 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2826 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2827 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2828 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
2829
2830 /*** GLX_SGIX_dmbuffer **/
2831 #if defined(_DM_BUFFER_H_)
2832 glx.AssociateDMPbufferSGIX = NULL;
2833 #endif
2834
2835 /*** GLX_SGIX_swap_group ***/
2836 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
2837
2838 /*** GLX_SGIX_swap_barrier ***/
2839 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2840 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
2841
2842 /*** GLX_SUN_get_transparent_index ***/
2843 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
2844
2845 /*** GLX_MESA_copy_sub_buffer ***/
2846 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
2847
2848 /*** GLX_MESA_release_buffers ***/
2849 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
2850
2851 /*** GLX_MESA_pixmap_colormap ***/
2852 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
2853
2854 /*** GLX_MESA_set_3dfx_mode ***/
2855 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
2856
2857 /*** GLX_NV_vertex_array_range ***/
2858 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
2859 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
2860
2861 /*** GLX_MESA_agp_offset ***/
2862 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
2863
2864 return &glx;
2865 }