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