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