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