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