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