063cc9c3575a67292f65f70a18961f462f999b47
[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->mesa_visual.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->mesa_visual.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->mesa_visual.level==0) {
1627 /* normal planes */
1628 *value = GLX_NONE_EXT;
1629 }
1630 else if (xmvis->mesa_visual.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->mesa_visual.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->mesa_visual.visualRating > 0)
1672 *value = xmvis->mesa_visual.visualRating;
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 XMesaVisual xmvis = (XMesaVisual) config;
1963 XMesaBuffer xmbuf;
1964 if (!xmvis)
1965 return 0;
1966
1967 xmbuf = XMesaCreateWindowBuffer2(xmvis, win, NULL);
1968 if (!xmbuf)
1969 return 0;
1970
1971 (void) dpy;
1972 (void) attribList; /* Ignored in GLX 1.3 */
1973
1974 return win; /* A hack for now */
1975 }
1976
1977
1978 static void
1979 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1980 {
1981 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1982 if (b)
1983 XMesaDestroyBuffer(b);
1984 /* don't destroy X window */
1985 }
1986
1987
1988 /* XXX untested */
1989 static GLXPixmap
1990 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1991 const int *attribList )
1992 {
1993 XMesaVisual v = (XMesaVisual) config;
1994 XMesaBuffer b;
1995
1996 (void) dpy;
1997 (void) config;
1998 (void) pixmap;
1999 (void) attribList; /* Ignored in GLX 1.3 */
2000
2001 if (!dpy || !config || !pixmap)
2002 return 0;
2003
2004 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2005 if (!b) {
2006 return 0;
2007 }
2008
2009 return pixmap;
2010 }
2011
2012
2013 static void
2014 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2015 {
2016 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
2017 if (b)
2018 XMesaDestroyBuffer(b);
2019 /* don't destroy X pixmap */
2020 }
2021
2022
2023 static GLXPbuffer
2024 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2025 const int *attribList )
2026 {
2027 XMesaVisual xmvis = (XMesaVisual) config;
2028 XMesaBuffer xmbuf;
2029 const int *attrib;
2030 int width = 0, height = 0;
2031 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2032
2033 (void) dpy;
2034
2035 for (attrib = attribList; *attrib; attrib++) {
2036 switch (*attrib) {
2037 case GLX_PBUFFER_WIDTH:
2038 attrib++;
2039 width = *attrib;
2040 break;
2041 case GLX_PBUFFER_HEIGHT:
2042 attrib++;
2043 height = *attrib;
2044 break;
2045 case GLX_PRESERVED_CONTENTS:
2046 attrib++;
2047 preserveContents = *attrib; /* ignored */
2048 break;
2049 case GLX_LARGEST_PBUFFER:
2050 attrib++;
2051 useLargest = *attrib; /* ignored */
2052 break;
2053 default:
2054 return 0;
2055 }
2056 }
2057
2058 /* not used at this time */
2059 (void) useLargest;
2060 (void) preserveContents;
2061
2062 if (width == 0 || height == 0)
2063 return 0;
2064
2065 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2066 /* A GLXPbuffer handle must be an X Drawable because that's what
2067 * glXMakeCurrent takes.
2068 */
2069 return (GLXPbuffer) xmbuf->frontbuffer;
2070 }
2071
2072
2073 static void
2074 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2075 {
2076 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2077 if (b) {
2078 XMesaDestroyBuffer(b);
2079 }
2080 }
2081
2082
2083 static void
2084 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2085 unsigned int *value )
2086 {
2087 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2088 if (!xmbuf)
2089 return;
2090
2091 switch (attribute) {
2092 case GLX_WIDTH:
2093 *value = xmbuf->width;
2094 break;
2095 case GLX_HEIGHT:
2096 *value = xmbuf->height;
2097 break;
2098 case GLX_PRESERVED_CONTENTS:
2099 *value = True;
2100 break;
2101 case GLX_LARGEST_PBUFFER:
2102 *value = xmbuf->width * xmbuf->height;
2103 break;
2104 case GLX_FBCONFIG_ID:
2105 *value = xmbuf->xm_visual->visinfo->visualid;
2106 return;
2107 default:
2108 return; /* GLX_BAD_ATTRIBUTE? */
2109 }
2110 }
2111
2112
2113 static GLXContext
2114 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2115 int renderType, GLXContext shareList, Bool direct )
2116 {
2117 struct fake_glx_context *glxCtx;
2118 struct fake_glx_context *shareCtx = (struct fake_glx_context *) shareList;
2119 XMesaVisual xmvis = (XMesaVisual) config;
2120
2121 if (!dpy || !config ||
2122 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2123 return 0;
2124
2125 glxCtx = CALLOC_STRUCT(fake_glx_context);
2126 if (!glxCtx)
2127 return 0;
2128
2129 /* deallocate unused windows/buffers */
2130 XMesaGarbageCollect();
2131
2132 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2133 shareCtx ? shareCtx->xmesaContext : NULL);
2134 if (!glxCtx->xmesaContext) {
2135 FREE(glxCtx);
2136 return NULL;
2137 }
2138
2139 glxCtx->xmesaContext->direct = GL_FALSE;
2140 glxCtx->glxContext.isDirect = GL_FALSE;
2141 glxCtx->glxContext.currentDpy = dpy;
2142 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2143
2144 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2145
2146 return (GLXContext) glxCtx;
2147 }
2148
2149
2150 static int
2151 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2152 {
2153 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
2154 XMesaContext xmctx = glxCtx->xmesaContext;
2155
2156 (void) dpy;
2157 (void) ctx;
2158
2159 switch (attribute) {
2160 case GLX_FBCONFIG_ID:
2161 *value = xmctx->xm_visual->visinfo->visualid;
2162 break;
2163 case GLX_RENDER_TYPE:
2164 if (xmctx->xm_visual->mesa_visual.rgbMode)
2165 *value = GLX_RGBA_BIT;
2166 else
2167 *value = GLX_COLOR_INDEX_BIT;
2168 break;
2169 case GLX_SCREEN:
2170 *value = 0;
2171 return Success;
2172 default:
2173 return GLX_BAD_ATTRIBUTE;
2174 }
2175 return 0;
2176 }
2177
2178
2179 static void
2180 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2181 {
2182 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2183 if (xmbuf)
2184 xmbuf->selectedEvents = mask;
2185 }
2186
2187
2188 static void
2189 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2190 unsigned long *mask )
2191 {
2192 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2193 if (xmbuf)
2194 *mask = xmbuf->selectedEvents;
2195 else
2196 *mask = 0;
2197 }
2198
2199
2200
2201 /*** GLX_SGI_swap_control ***/
2202
2203 static int
2204 Fake_glXSwapIntervalSGI(int interval)
2205 {
2206 (void) interval;
2207 return 0;
2208 }
2209
2210
2211
2212 /*** GLX_SGI_video_sync ***/
2213
2214 static int
2215 Fake_glXGetVideoSyncSGI(unsigned int *count)
2216 {
2217 (void) count;
2218 return 0;
2219 }
2220
2221 static int
2222 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2223 {
2224 (void) divisor;
2225 (void) remainder;
2226 (void) count;
2227 return 0;
2228 }
2229
2230
2231
2232 /*** GLX_SGI_make_current_read ***/
2233
2234 static Bool
2235 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2236 {
2237 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
2238 }
2239
2240 /* not used
2241 static GLXDrawable
2242 Fake_glXGetCurrentReadDrawableSGI(void)
2243 {
2244 return 0;
2245 }
2246 */
2247
2248
2249 /*** GLX_SGIX_video_source ***/
2250 #if defined(_VL_H)
2251
2252 static GLXVideoSourceSGIX
2253 Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2254 {
2255 (void) dpy;
2256 (void) screen;
2257 (void) server;
2258 (void) path;
2259 (void) nodeClass;
2260 (void) drainNode;
2261 return 0;
2262 }
2263
2264 static void
2265 Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2266 {
2267 (void) dpy;
2268 (void) src;
2269 }
2270
2271 #endif
2272
2273
2274 /*** GLX_EXT_import_context ***/
2275
2276 static void
2277 Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2278 {
2279 (void) dpy;
2280 (void) context;
2281 }
2282
2283 static GLXContextID
2284 Fake_glXGetContextIDEXT(const GLXContext context)
2285 {
2286 (void) context;
2287 return 0;
2288 }
2289
2290 static GLXContext
2291 Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2292 {
2293 (void) dpy;
2294 (void) contextID;
2295 return 0;
2296 }
2297
2298 static int
2299 Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2300 {
2301 (void) dpy;
2302 (void) context;
2303 (void) attribute;
2304 (void) value;
2305 return 0;
2306 }
2307
2308
2309
2310 /*** GLX_SGIX_fbconfig ***/
2311
2312 static int
2313 Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2314 {
2315 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
2316 }
2317
2318 static GLXFBConfigSGIX *
2319 Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2320 {
2321 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2322 }
2323
2324
2325 static GLXPixmap
2326 Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2327 {
2328 XMesaVisual xmvis = (XMesaVisual) config;
2329 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2330 return xmbuf->frontbuffer; /* need to return an X ID */
2331 }
2332
2333
2334 static GLXContext
2335 Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2336 {
2337 XMesaVisual xmvis = (XMesaVisual) config;
2338 struct fake_glx_context *glxCtx;
2339 struct fake_glx_context *shareCtx = (struct fake_glx_context *) share_list;
2340
2341 glxCtx = CALLOC_STRUCT(fake_glx_context);
2342 if (!glxCtx)
2343 return 0;
2344
2345 /* deallocate unused windows/buffers */
2346 XMesaGarbageCollect();
2347
2348 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2349 shareCtx ? shareCtx->xmesaContext : NULL);
2350 if (!glxCtx->xmesaContext) {
2351 FREE(glxCtx);
2352 return NULL;
2353 }
2354
2355 glxCtx->xmesaContext->direct = GL_FALSE;
2356 glxCtx->glxContext.isDirect = GL_FALSE;
2357 glxCtx->glxContext.currentDpy = dpy;
2358 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
2359
2360 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
2361
2362 return (GLXContext) glxCtx;
2363 }
2364
2365
2366 static XVisualInfo *
2367 Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2368 {
2369 return Fake_glXGetVisualFromFBConfig(dpy, config);
2370 }
2371
2372
2373 static GLXFBConfigSGIX
2374 Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2375 {
2376 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2377 if (!xmvis) {
2378 /* This visual wasn't found with glXChooseVisual() */
2379 xmvis = create_glx_visual(dpy, vis);
2380 }
2381
2382 return (GLXFBConfigSGIX) xmvis;
2383 }
2384
2385
2386
2387 /*** GLX_SGIX_pbuffer ***/
2388
2389 static GLXPbufferSGIX
2390 Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2391 unsigned int width, unsigned int height,
2392 int *attribList)
2393 {
2394 XMesaVisual xmvis = (XMesaVisual) config;
2395 XMesaBuffer xmbuf;
2396 const int *attrib;
2397 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2398
2399 (void) dpy;
2400
2401 for (attrib = attribList; *attrib; attrib++) {
2402 switch (*attrib) {
2403 case GLX_PRESERVED_CONTENTS_SGIX:
2404 attrib++;
2405 preserveContents = *attrib; /* ignored */
2406 break;
2407 case GLX_LARGEST_PBUFFER_SGIX:
2408 attrib++;
2409 useLargest = *attrib; /* ignored */
2410 break;
2411 default:
2412 return 0;
2413 }
2414 }
2415
2416 /* not used at this time */
2417 (void) useLargest;
2418 (void) preserveContents;
2419
2420 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2421 /* A GLXPbuffer handle must be an X Drawable because that's what
2422 * glXMakeCurrent takes.
2423 */
2424 return (GLXPbuffer) xmbuf->frontbuffer;
2425 }
2426
2427
2428 static void
2429 Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2430 {
2431 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2432 if (xmbuf) {
2433 XMesaDestroyBuffer(xmbuf);
2434 }
2435 }
2436
2437
2438 static int
2439 Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2440 {
2441 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2442
2443 if (!xmbuf) {
2444 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2445 return 0;
2446 }
2447
2448 switch (attribute) {
2449 case GLX_PRESERVED_CONTENTS_SGIX:
2450 *value = True;
2451 break;
2452 case GLX_LARGEST_PBUFFER_SGIX:
2453 *value = xmbuf->width * xmbuf->height;
2454 break;
2455 case GLX_WIDTH_SGIX:
2456 *value = xmbuf->width;
2457 break;
2458 case GLX_HEIGHT_SGIX:
2459 *value = xmbuf->height;
2460 break;
2461 case GLX_EVENT_MASK_SGIX:
2462 *value = 0; /* XXX might be wrong */
2463 break;
2464 default:
2465 *value = 0;
2466 }
2467 return 0;
2468 }
2469
2470
2471 static void
2472 Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2473 {
2474 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2475 if (xmbuf) {
2476 /* Note: we'll never generate clobber events */
2477 xmbuf->selectedEvents = mask;
2478 }
2479 }
2480
2481
2482 static void
2483 Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2484 {
2485 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2486 if (xmbuf) {
2487 *mask = xmbuf->selectedEvents;
2488 }
2489 else {
2490 *mask = 0;
2491 }
2492 }
2493
2494
2495
2496 /*** GLX_SGI_cushion ***/
2497
2498 static void
2499 Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2500 {
2501 (void) dpy;
2502 (void) win;
2503 (void) cushion;
2504 }
2505
2506
2507
2508 /*** GLX_SGIX_video_resize ***/
2509
2510 static int
2511 Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2512 {
2513 (void) dpy;
2514 (void) screen;
2515 (void) channel;
2516 (void) window;
2517 return 0;
2518 }
2519
2520 static int
2521 Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2522 {
2523 (void) dpy;
2524 (void) screen;
2525 (void) channel;
2526 (void) x;
2527 (void) y;
2528 (void) w;
2529 (void) h;
2530 return 0;
2531 }
2532
2533 static int
2534 Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2535 {
2536 (void) dpy;
2537 (void) screen;
2538 (void) channel;
2539 (void) x;
2540 (void) y;
2541 (void) w;
2542 (void) h;
2543 return 0;
2544 }
2545
2546 static int
2547 Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2548 {
2549 (void) dpy;
2550 (void) screen;
2551 (void) channel;
2552 (void) dx;
2553 (void) dy;
2554 (void) dw;
2555 (void) dh;
2556 return 0;
2557 }
2558
2559 static int
2560 Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2561 {
2562 (void) dpy;
2563 (void) screen;
2564 (void) channel;
2565 (void) synctype;
2566 return 0;
2567 }
2568
2569
2570
2571 /*** GLX_SGIX_dmbuffer **/
2572
2573 #if defined(_DM_BUFFER_H_)
2574 static Bool
2575 Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2576 {
2577 (void) dpy;
2578 (void) pbuffer;
2579 (void) params;
2580 (void) dmbuffer;
2581 return False;
2582 }
2583 #endif
2584
2585
2586 /*** GLX_SGIX_swap_group ***/
2587
2588 static void
2589 Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2590 {
2591 (void) dpy;
2592 (void) drawable;
2593 (void) member;
2594 }
2595
2596
2597
2598 /*** GLX_SGIX_swap_barrier ***/
2599
2600 static void
2601 Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2602 {
2603 (void) dpy;
2604 (void) drawable;
2605 (void) barrier;
2606 }
2607
2608 static Bool
2609 Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2610 {
2611 (void) dpy;
2612 (void) screen;
2613 (void) max;
2614 return False;
2615 }
2616
2617
2618
2619 /*** GLX_SUN_get_transparent_index ***/
2620
2621 static Status
2622 Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2623 {
2624 (void) dpy;
2625 (void) overlay;
2626 (void) underlay;
2627 (void) pTransparent;
2628 return 0;
2629 }
2630
2631
2632
2633 /*** GLX_MESA_release_buffers ***/
2634
2635 /*
2636 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2637 * (a window or pixmap) prior to destroying the GLXDrawable.
2638 */
2639 static Bool
2640 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2641 {
2642 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2643 if (b) {
2644 XMesaDestroyBuffer(b);
2645 return True;
2646 }
2647 return False;
2648 }
2649
2650
2651
2652 /*** GLX_MESA_set_3dfx_mode ***/
2653
2654 static Bool
2655 Fake_glXSet3DfxModeMESA( int mode )
2656 {
2657 return XMesaSetFXmode( mode );
2658 }
2659
2660
2661
2662 /*** GLX_NV_vertex_array range ***/
2663 static void *
2664 Fake_glXAllocateMemoryNV( GLsizei size,
2665 GLfloat readFrequency,
2666 GLfloat writeFrequency,
2667 GLfloat priority )
2668 {
2669 (void) size;
2670 (void) readFrequency;
2671 (void) writeFrequency;
2672 (void) priority;
2673 return NULL;
2674 }
2675
2676
2677 static void
2678 Fake_glXFreeMemoryNV( GLvoid *pointer )
2679 {
2680 (void) pointer;
2681 }
2682
2683
2684 /*** GLX_MESA_agp_offset ***/
2685
2686 static GLuint
2687 Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2688 {
2689 (void) pointer;
2690 return ~0;
2691 }
2692
2693
2694 /*** GLX_ARB_render_texture ***/
2695
2696 static Bool
2697 Fake_glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer )
2698 {
2699 return False;
2700 }
2701
2702
2703 static Bool
2704 Fake_glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer )
2705 {
2706 return False;
2707 }
2708
2709
2710 static Bool
2711 Fake_glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList )
2712 {
2713 return False;
2714 }
2715
2716
2717
2718 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
2719 struct _glxapi_table *_mesa_GetGLXDispatchTable(void)
2720 {
2721 static struct _glxapi_table glx;
2722
2723 /* be sure our dispatch table size <= libGL's table */
2724 {
2725 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
2726 (void) size;
2727 assert(_glxapi_get_dispatch_table_size() >= size);
2728 }
2729
2730 /* initialize the whole table to no-ops */
2731 _glxapi_set_no_op_table(&glx);
2732
2733 /* now initialize the table with the functions I implement */
2734 glx.ChooseVisual = Fake_glXChooseVisual;
2735 glx.CopyContext = Fake_glXCopyContext;
2736 glx.CreateContext = Fake_glXCreateContext;
2737 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2738 glx.DestroyContext = Fake_glXDestroyContext;
2739 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2740 glx.GetConfig = Fake_glXGetConfig;
2741 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2742 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2743 glx.IsDirect = Fake_glXIsDirect;
2744 glx.MakeCurrent = Fake_glXMakeCurrent;
2745 glx.QueryExtension = Fake_glXQueryExtension;
2746 glx.QueryVersion = Fake_glXQueryVersion;
2747 glx.SwapBuffers = Fake_glXSwapBuffers;
2748 glx.UseXFont = Fake_glXUseXFont;
2749 glx.WaitGL = Fake_glXWaitGL;
2750 glx.WaitX = Fake_glXWaitX;
2751
2752 /*** GLX_VERSION_1_1 ***/
2753 glx.GetClientString = Fake_glXGetClientString;
2754 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2755 glx.QueryServerString = Fake_glXQueryServerString;
2756
2757 /*** GLX_VERSION_1_2 ***/
2758 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2759
2760 /*** GLX_VERSION_1_3 ***/
2761 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2762 glx.CreateNewContext = Fake_glXCreateNewContext;
2763 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2764 glx.CreatePixmap = Fake_glXCreatePixmap;
2765 glx.CreateWindow = Fake_glXCreateWindow;
2766 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2767 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2768 glx.DestroyWindow = Fake_glXDestroyWindow;
2769 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2770 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
2771 glx.GetFBConfigs = Fake_glXGetFBConfigs;
2772 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2773 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2774 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2775 glx.QueryContext = Fake_glXQueryContext;
2776 glx.QueryDrawable = Fake_glXQueryDrawable;
2777 glx.SelectEvent = Fake_glXSelectEvent;
2778
2779 /*** GLX_SGI_swap_control ***/
2780 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
2781
2782 /*** GLX_SGI_video_sync ***/
2783 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2784 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
2785
2786 /*** GLX_SGI_make_current_read ***/
2787 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
2788 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2789
2790 /*** GLX_SGIX_video_source ***/
2791 #if defined(_VL_H)
2792 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2793 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2794 #endif
2795
2796 /*** GLX_EXT_import_context ***/
2797 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2798 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
2799 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2800 glx.ImportContextEXT = Fake_glXImportContextEXT;
2801 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
2802
2803 /*** GLX_SGIX_fbconfig ***/
2804 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2805 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2806 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2807 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2808 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2809 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
2810
2811 /*** GLX_SGIX_pbuffer ***/
2812 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2813 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2814 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2815 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2816 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
2817
2818 /*** GLX_SGI_cushion ***/
2819 glx.CushionSGI = Fake_glXCushionSGI;
2820
2821 /*** GLX_SGIX_video_resize ***/
2822 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2823 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2824 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2825 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2826 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
2827
2828 /*** GLX_SGIX_dmbuffer **/
2829 #if defined(_DM_BUFFER_H_)
2830 glx.AssociateDMPbufferSGIX = NULL;
2831 #endif
2832
2833 /*** GLX_SGIX_swap_group ***/
2834 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
2835
2836 /*** GLX_SGIX_swap_barrier ***/
2837 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2838 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
2839
2840 /*** GLX_SUN_get_transparent_index ***/
2841 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
2842
2843 /*** GLX_MESA_copy_sub_buffer ***/
2844 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
2845
2846 /*** GLX_MESA_release_buffers ***/
2847 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
2848
2849 /*** GLX_MESA_pixmap_colormap ***/
2850 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
2851
2852 /*** GLX_MESA_set_3dfx_mode ***/
2853 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
2854
2855 /*** GLX_NV_vertex_array_range ***/
2856 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
2857 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
2858
2859 /*** GLX_MESA_agp_offset ***/
2860 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
2861
2862 /*** GLX_ARB_render_texture ***/
2863 glx.BindTexImageARB = Fake_glXBindTexImageARB;
2864 glx.ReleaseTexImageARB = Fake_glXReleaseTexImageARB;
2865 glx.DrawableAttribARB = Fake_glXDrawableAttribARB;
2866
2867 return &glx;
2868 }