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