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