bbd23686d49322c94d9f7b63422a93e71f389c5a
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
1 /* $Id: fakeglx.c,v 1.12 1999/10/27 09:50:10 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.1
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28
29
30
31 /*
32 * A pseudo-GLX implementation to allow OpenGL/GLX programs to work with Mesa.
33 * The Fake_glX*() functions implemented here are called from glxapi.c
34 *
35 * Thanks to the contributors:
36 *
37 * Initial version: Philip Brown (philb@CSUA.Berkeley.EDU)
38 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
39 * Further visual-handling refinements: Wolfram Gloger
40 * (wmglo@Dent.MED.Uni-Muenchen.DE).
41 *
42 * Notes:
43 * Don't be fooled, stereo isn't supported yet.
44 */
45
46
47
48 #ifdef HAVE_CONFIG_H
49 #include "conf.h"
50 #endif
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <X11/Xlib.h>
56 #include <X11/Xutil.h>
57 #include "GL/gl.h"
58 #include "GL/xmesa.h"
59 #include "context.h"
60 #include "config.h"
61 #include "fakeglx.h"
62 #include "macros.h"
63 #include "types.h"
64 #include "xmesaP.h"
65
66
67
68 /* Silence compiler warnings */
69 void Fake_glXDummyFunc( void )
70 {
71 (void) kernel8;
72 (void) DitherValues;
73 (void) HPCR_DRGB;
74 (void) kernel1;
75 }
76
77
78
79 #define DONT_CARE -1
80
81
82
83 #define MAX_VISUALS 100
84 static XMesaVisual VisualTable[MAX_VISUALS];
85 static int NumVisuals = 0;
86
87
88
89 /*
90 * This struct and some code fragments borrowed
91 * from Mark Kilgard's GLUT library.
92 */
93 typedef struct _OverlayInfo {
94 /* Avoid 64-bit portability problems by being careful to use
95 longs due to the way XGetWindowProperty is specified. Note
96 that these parameters are passed as CARD32s over X
97 protocol. */
98 unsigned long overlay_visual;
99 long transparent_type;
100 long value;
101 long layer;
102 } OverlayInfo;
103
104
105
106 /* Macro to handle c_class vs class field name in XVisualInfo struct */
107 #if defined(__cplusplus) || defined(c_plusplus)
108 #define CLASS c_class
109 #else
110 #define CLASS class
111 #endif
112
113
114
115
116 /*
117 * Test if the given XVisualInfo is usable for Mesa rendering.
118 */
119 static GLboolean is_usable_visual( XVisualInfo *vinfo )
120 {
121 switch (vinfo->CLASS) {
122 case StaticGray:
123 case GrayScale:
124 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
125 return GL_TRUE;
126 case StaticColor:
127 case PseudoColor:
128 /* Any StaticColor/PseudoColor visual of at least 4 bits */
129 if (vinfo->depth>=4) {
130 return GL_TRUE;
131 }
132 else {
133 return GL_FALSE;
134 }
135 case TrueColor:
136 case DirectColor:
137 /* Any depth of TrueColor or DirectColor works in RGB mode */
138 return GL_TRUE;
139 default:
140 /* This should never happen */
141 return GL_FALSE;
142 }
143 }
144
145
146
147 /*
148 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
149 * Input: dpy - the X display
150 * vinfo - the XVisualInfo to test
151 * Return: level of the visual:
152 * 0 = normal planes
153 * >0 = overlay planes
154 * <0 = underlay planes
155 */
156 static int level_of_visual( Display *dpy, XVisualInfo *vinfo )
157 {
158 Atom overlayVisualsAtom;
159 OverlayInfo *overlay_info = NULL;
160 int numOverlaysPerScreen;
161 Status status;
162 Atom actualType;
163 int actualFormat;
164 unsigned long sizeData, bytesLeft;
165 int i;
166
167 /*
168 * The SERVER_OVERLAY_VISUALS property on the root window contains
169 * a list of overlay visuals. Get that list now.
170 */
171 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
172 if (overlayVisualsAtom == None) {
173 return 0;
174 }
175
176 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
177 overlayVisualsAtom, 0L, (long) 10000, False,
178 overlayVisualsAtom, &actualType, &actualFormat,
179 &sizeData, &bytesLeft,
180 (unsigned char **) &overlay_info );
181
182 if (status != Success || actualType != overlayVisualsAtom ||
183 actualFormat != 32 || sizeData < 4) {
184 /* something went wrong */
185 XFree((void *) overlay_info);
186 return 0;
187 }
188
189 /* search the overlay visual list for the visual ID of interest */
190 numOverlaysPerScreen = (int) (sizeData / 4);
191 for (i=0;i<numOverlaysPerScreen;i++) {
192 OverlayInfo *ov;
193 ov = overlay_info + i;
194 if (ov->overlay_visual==vinfo->visualid) {
195 /* found the visual */
196 if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
197 int level = ov->layer;
198 XFree((void *) overlay_info);
199 return level;
200 }
201 else {
202 XFree((void *) overlay_info);
203 return 0;
204 }
205 }
206 }
207
208 /* The visual ID was not found in the overlay list. */
209 XFree((void *) overlay_info);
210 return 0;
211 }
212
213
214
215
216 /*
217 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
218 * configuration in our list of GLX visuals.
219 */
220 static XMesaVisual
221 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
222 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
223 GLboolean stereoFlag,
224 GLint depth_size, GLint stencil_size,
225 GLint accum_size, GLint level )
226 {
227 GLboolean ximageFlag = GL_TRUE;
228 XMesaVisual xmvis;
229 GLint i;
230 GLboolean comparePointers;
231
232 if (dbFlag) {
233 /* Check if the MESA_BACK_BUFFER env var is set */
234 char *backbuffer = getenv("MESA_BACK_BUFFER");
235 if (backbuffer) {
236 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
237 ximageFlag = GL_FALSE;
238 }
239 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
240 ximageFlag = GL_TRUE;
241 }
242 else {
243 fprintf(stderr, "Mesa: invalid value for MESA_BACK_BUFFER ");
244 fprintf(stderr, "environment variable, using an XImage.\n");
245 }
246 }
247 }
248
249 /* Comparing IDs uses less memory but sometimes fails. */
250 /* XXX revisit this after 3.0 is finished. */
251 if (getenv("MESA_GLX_VISUAL_HACK"))
252 comparePointers = GL_TRUE;
253 else
254 comparePointers = GL_FALSE;
255
256 /* First check if a matching visual is already in the list */
257 for (i=0; i<NumVisuals; i++) {
258 XMesaVisual v = VisualTable[i];
259 if (v->display == dpy
260 && v->level == level
261 && v->ximage_flag == ximageFlag
262 && v->gl_visual->RGBAflag == rgbFlag
263 && v->gl_visual->DBflag == dbFlag
264 && v->gl_visual->StereoFlag == stereoFlag
265 && (v->gl_visual->AlphaBits > 0) == alphaFlag
266 && (v->gl_visual->DepthBits >= depth_size || depth_size == 0)
267 && (v->gl_visual->StencilBits >= stencil_size || stencil_size == 0)
268 && (v->gl_visual->AccumBits >= accum_size || accum_size == 0)) {
269 /* now either compare XVisualInfo pointers or visual IDs */
270 if ((!comparePointers && v->vishandle->visualid == vinfo->visualid)
271 || (comparePointers && v->vishandle == vinfo)) {
272 return v;
273 }
274 }
275 }
276
277 /* Create a new visual and add it to the list. */
278
279 if (NumVisuals>=MAX_VISUALS) {
280 fprintf( stderr, "GLX Error: maximum number of visuals exceeded\n");
281 return NULL;
282 }
283
284 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
285 stereoFlag, ximageFlag,
286 depth_size, stencil_size, accum_size, level );
287 if (xmvis) {
288 VisualTable[NumVisuals] = xmvis;
289 NumVisuals++;
290 }
291 return xmvis;
292 }
293
294
295
296 /*
297 * Create a GLX visual from a regular XVisualInfo.
298 */
299 static XMesaVisual
300 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
301 {
302 int vislevel;
303
304 vislevel = level_of_visual( dpy, visinfo );
305 if (vislevel) {
306 /* Configure this visual as a CI, single-buffered overlay */
307 return save_glx_visual( dpy, visinfo,
308 GL_FALSE, /* rgb */
309 GL_FALSE, /* alpha */
310 GL_FALSE, /* double */
311 GL_FALSE, /* stereo */
312 0, /* depth bits */
313 0, /* stencil bits */
314 0, /* accum bits */
315 vislevel /* level */
316 );
317 }
318 else if (is_usable_visual( visinfo )) {
319 /* Configure this visual as RGB, double-buffered, depth-buffered. */
320 /* This is surely wrong for some people's needs but what else */
321 /* can be done? They should use glXChooseVisual(). */
322 return save_glx_visual( dpy, visinfo,
323 GL_TRUE, /* rgb */
324 GL_FALSE, /* alpha */
325 GL_TRUE, /* double */
326 GL_FALSE, /* stereo */
327 8*sizeof(GLdepth),
328 8*sizeof(GLstencil),
329 8*sizeof(GLaccum),
330 0 /* level */
331 );
332 }
333 else {
334 fprintf(stderr,"Mesa: error in glXCreateContext: bad visual\n");
335 return NULL;
336 }
337 }
338
339
340
341 /*
342 * Find the GLX visual associated with an XVisualInfo.
343 */
344 static XMesaVisual
345 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
346 {
347 int i;
348
349 /* First try to match pointers */
350 for (i=0;i<NumVisuals;i++) {
351 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
352 return VisualTable[i];
353 }
354 }
355 /* try to match visual id */
356 for (i=0;i<NumVisuals;i++) {
357 if (VisualTable[i]->display==dpy
358 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
359 return VisualTable[i];
360 }
361 }
362 return NULL;
363 }
364
365
366
367 /*
368 * Return the transparent pixel value for a GLX visual.
369 * Input: glxvis - the glx_visual
370 * Return: a pixel value or -1 if no transparent pixel
371 */
372 static int transparent_pixel( XMesaVisual glxvis )
373 {
374 Display *dpy = glxvis->display;
375 XVisualInfo *vinfo = glxvis->visinfo;
376 Atom overlayVisualsAtom;
377 OverlayInfo *overlay_info = NULL;
378 int numOverlaysPerScreen;
379 Status status;
380 Atom actualType;
381 int actualFormat;
382 unsigned long sizeData, bytesLeft;
383 int i;
384
385 /*
386 * The SERVER_OVERLAY_VISUALS property on the root window contains
387 * a list of overlay visuals. Get that list now.
388 */
389 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
390 if (overlayVisualsAtom == None) {
391 return -1;
392 }
393
394 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
395 overlayVisualsAtom, 0L, (long) 10000, False,
396 overlayVisualsAtom, &actualType, &actualFormat,
397 &sizeData, &bytesLeft,
398 (unsigned char **) &overlay_info );
399
400 if (status != Success || actualType != overlayVisualsAtom ||
401 actualFormat != 32 || sizeData < 4) {
402 /* something went wrong */
403 XFree((void *) overlay_info);
404 return -1;
405 }
406
407 /* search the overlay visual list for the visual ID of interest */
408 numOverlaysPerScreen = (int) (sizeData / 4);
409 for (i=0;i<numOverlaysPerScreen;i++) {
410 OverlayInfo *ov;
411 ov = overlay_info + i;
412 if (ov->overlay_visual==vinfo->visualid) {
413 /* found it! */
414 if (ov->transparent_type==0) {
415 /* type 0 indicates no transparency */
416 XFree((void *) overlay_info);
417 return -1;
418 }
419 else {
420 /* ov->value is the transparent pixel */
421 XFree((void *) overlay_info);
422 return ov->value;
423 }
424 }
425 }
426
427 /* The visual ID was not found in the overlay list. */
428 XFree((void *) overlay_info);
429 return -1;
430 }
431
432
433
434 /*
435 * Return number of bits set in n.
436 */
437 static int bitcount( unsigned long n )
438 {
439 int bits;
440 for (bits=0; n>0; n=n>>1) {
441 if (n&1) {
442 bits++;
443 }
444 }
445 return bits;
446 }
447
448
449 /*
450 * Try to get an X visual which matches the given arguments.
451 */
452 static XVisualInfo *get_visual( Display *dpy, int scr,
453 unsigned int depth, int xclass )
454 {
455 XVisualInfo temp, *vis;
456 long mask;
457 int n;
458 unsigned int default_depth;
459 int default_class;
460
461 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
462 temp.screen = scr;
463 temp.depth = depth;
464 temp.CLASS = xclass;
465
466 default_depth = DefaultDepth(dpy,scr);
467 default_class = DefaultVisual(dpy,scr)->CLASS;
468
469 if (depth==default_depth && xclass==default_class) {
470 /* try to get root window's visual */
471 temp.visualid = DefaultVisual(dpy,scr)->visualid;
472 mask |= VisualIDMask;
473 }
474
475 vis = XGetVisualInfo( dpy, mask, &temp, &n );
476
477 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
478 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
479 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
480 */
481 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
482 if (bitcount(vis->red_mask) <= 8
483 && bitcount(vis->green_mask) <= 8
484 && bitcount(vis->blue_mask) <= 8) {
485 return vis;
486 }
487 else {
488 XFree((void *) vis);
489 return NULL;
490 }
491 }
492
493 return vis;
494 }
495
496
497
498 /*
499 * Retrieve the value of the given environment variable and find
500 * the X visual which matches it.
501 * Input: dpy - the display
502 * screen - the screen number
503 * varname - the name of the environment variable
504 * Return: an XVisualInfo pointer to NULL if error.
505 */
506 static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname)
507 {
508 char value[100], type[100];
509 int depth, xclass = -1;
510 XVisualInfo *vis;
511
512 if (!getenv( varname )) {
513 return NULL;
514 }
515
516 strncpy( value, getenv(varname), 100 );
517 value[99] = 0;
518
519 sscanf( value, "%s %d", type, &depth );
520
521 if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
522 else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
523 else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
524 else if (strcmp(type,"StaticColor")==0) xclass = StaticColor;
525 else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
526 else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
527
528 if (xclass>-1 && depth>0) {
529 vis = get_visual( dpy, scr, depth, xclass );
530 if (vis) {
531 return vis;
532 }
533 }
534
535 fprintf( stderr, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
536 type, depth );
537 return NULL;
538 }
539
540
541
542 /*
543 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
544 * Input: dpy, screen - X display and screen number
545 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
546 * min_depth - minimum visual depth
547 * preferred_class - preferred GLX visual class or DONT_CARE
548 * Return: pointer to an XVisualInfo or NULL.
549 */
550 static XVisualInfo *choose_x_visual( Display *dpy, int screen,
551 GLboolean rgba, int min_depth,
552 int preferred_class )
553 {
554 XVisualInfo *vis;
555 int xclass, visclass;
556 int depth;
557
558 if (rgba) {
559 Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True);
560 /* First see if the MESA_RGB_VISUAL env var is defined */
561 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
562 if (vis) {
563 return vis;
564 }
565 /* Otherwise, search for a suitable visual */
566 if (preferred_class==DONT_CARE) {
567 for (xclass=0;xclass<6;xclass++) {
568 switch (xclass) {
569 case 0: visclass = TrueColor; break;
570 case 1: visclass = DirectColor; break;
571 case 2: visclass = PseudoColor; break;
572 case 3: visclass = StaticColor; break;
573 case 4: visclass = GrayScale; break;
574 case 5: visclass = StaticGray; break;
575 }
576 if (min_depth==0) {
577 /* start with shallowest */
578 for (depth=0;depth<=32;depth++) {
579 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
580 /* Special case: try to get 8-bit PseudoColor before */
581 /* 8-bit TrueColor */
582 vis = get_visual( dpy, screen, 8, PseudoColor );
583 if (vis) {
584 return vis;
585 }
586 }
587 vis = get_visual( dpy, screen, depth, visclass );
588 if (vis) {
589 return vis;
590 }
591 }
592 }
593 else {
594 /* start with deepest */
595 for (depth=32;depth>=min_depth;depth--) {
596 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
597 /* Special case: try to get 8-bit PseudoColor before */
598 /* 8-bit TrueColor */
599 vis = get_visual( dpy, screen, 8, PseudoColor );
600 if (vis) {
601 return vis;
602 }
603 }
604 vis = get_visual( dpy, screen, depth, visclass );
605 if (vis) {
606 return vis;
607 }
608 }
609 }
610 }
611 }
612 else {
613 /* search for a specific visual class */
614 switch (preferred_class) {
615 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
616 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
617 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
618 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
619 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
620 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
621 default: return NULL;
622 }
623 if (min_depth==0) {
624 /* start with shallowest */
625 for (depth=0;depth<=32;depth++) {
626 vis = get_visual( dpy, screen, depth, visclass );
627 if (vis) {
628 return vis;
629 }
630 }
631 }
632 else {
633 /* start with deepest */
634 for (depth=32;depth>=min_depth;depth--) {
635 vis = get_visual( dpy, screen, depth, visclass );
636 if (vis) {
637 return vis;
638 }
639 }
640 }
641 }
642 }
643 else {
644 /* First see if the MESA_CI_VISUAL env var is defined */
645 vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" );
646 if (vis) {
647 return vis;
648 }
649 /* Otherwise, search for a suitable visual, starting with shallowest */
650 if (preferred_class==DONT_CARE) {
651 for (xclass=0;xclass<4;xclass++) {
652 switch (xclass) {
653 case 0: visclass = PseudoColor; break;
654 case 1: visclass = StaticColor; break;
655 case 2: visclass = GrayScale; break;
656 case 3: visclass = StaticGray; break;
657 }
658 /* try 8-bit up through 16-bit */
659 for (depth=8;depth<=16;depth++) {
660 vis = get_visual( dpy, screen, depth, visclass );
661 if (vis) {
662 return vis;
663 }
664 }
665 /* try min_depth up to 8-bit */
666 for (depth=min_depth;depth<8;depth++) {
667 vis = get_visual( dpy, screen, depth, visclass );
668 if (vis) {
669 return vis;
670 }
671 }
672 }
673 }
674 else {
675 /* search for a specific visual class */
676 switch (preferred_class) {
677 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
678 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
679 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
680 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
681 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
682 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
683 default: return NULL;
684 }
685 /* try 8-bit up through 16-bit */
686 for (depth=8;depth<=16;depth++) {
687 vis = get_visual( dpy, screen, depth, visclass );
688 if (vis) {
689 return vis;
690 }
691 }
692 /* try min_depth up to 8-bit */
693 for (depth=min_depth;depth<8;depth++) {
694 vis = get_visual( dpy, screen, depth, visclass );
695 if (vis) {
696 return vis;
697 }
698 }
699 }
700 }
701
702 /* didn't find a visual */
703 return NULL;
704 }
705
706
707
708 /*
709 * Find the deepest X over/underlay visual of at least min_depth.
710 * Input: dpy, screen - X display and screen number
711 * level - the over/underlay level
712 * trans_type - transparent pixel type: GLX_NONE_EXT,
713 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
714 * or DONT_CARE
715 * trans_value - transparent pixel value or DONT_CARE
716 * min_depth - minimum visual depth
717 * preferred_class - preferred GLX visual class or DONT_CARE
718 * Return: pointer to an XVisualInfo or NULL.
719 */
720 static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr,
721 GLboolean rgbFlag,
722 int level, int trans_type,
723 int trans_value,
724 int min_depth,
725 int preferred_class )
726 {
727 Atom overlayVisualsAtom;
728 OverlayInfo *overlay_info;
729 int numOverlaysPerScreen;
730 Status status;
731 Atom actualType;
732 int actualFormat;
733 unsigned long sizeData, bytesLeft;
734 int i;
735 XVisualInfo *deepvis;
736 int deepest;
737
738 /*DEBUG int tt, tv; */
739
740 switch (preferred_class) {
741 case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break;
742 case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break;
743 case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break;
744 case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break;
745 case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break;
746 case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break;
747 default: preferred_class = DONT_CARE;
748 }
749
750 /*
751 * The SERVER_OVERLAY_VISUALS property on the root window contains
752 * a list of overlay visuals. Get that list now.
753 */
754 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
755 if (overlayVisualsAtom == (Atom) None) {
756 return NULL;
757 }
758
759 status = XGetWindowProperty(dpy, RootWindow( dpy, scr ),
760 overlayVisualsAtom, 0L, (long) 10000, False,
761 overlayVisualsAtom, &actualType, &actualFormat,
762 &sizeData, &bytesLeft,
763 (unsigned char **) &overlay_info );
764
765 if (status != Success || actualType != overlayVisualsAtom ||
766 actualFormat != 32 || sizeData < 4) {
767 /* something went wrong */
768 return NULL;
769 }
770
771 /* Search for the deepest overlay which satisifies all criteria. */
772 deepest = min_depth;
773 deepvis = NULL;
774
775 numOverlaysPerScreen = (int) (sizeData / 4);
776 for (i=0;i<numOverlaysPerScreen;i++) {
777 XVisualInfo *vislist, vistemplate;
778 int count;
779 OverlayInfo *ov;
780 ov = overlay_info + i;
781
782 if (ov->layer!=level) {
783 /* failed overlay level criteria */
784 continue;
785 }
786 if (!(trans_type==DONT_CARE
787 || (trans_type==GLX_TRANSPARENT_INDEX_EXT
788 && ov->transparent_type>0)
789 || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
790 /* failed transparent pixel type criteria */
791 continue;
792 }
793 if (trans_value!=DONT_CARE && trans_value!=ov->value) {
794 /* failed transparent pixel value criteria */
795 continue;
796 }
797
798 /* get XVisualInfo and check the depth */
799 vistemplate.visualid = ov->overlay_visual;
800 vistemplate.screen = scr;
801 vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
802 &vistemplate, &count );
803
804 if (count!=1) {
805 /* something went wrong */
806 continue;
807 }
808 if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
809 /* wrong visual class */
810 continue;
811 }
812
813 /* if RGB was requested, make sure we have True/DirectColor */
814 if (rgbFlag && vislist->CLASS != TrueColor
815 && vislist->CLASS != DirectColor)
816 continue;
817
818 /* if CI was requested, make sure we have a color indexed visual */
819 if (!rgbFlag
820 && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor))
821 continue;
822
823 if (deepvis==NULL || vislist->depth > deepest) {
824 /* YES! found a satisfactory visual */
825 if (deepvis) {
826 XFree( deepvis );
827 }
828 deepest = vislist->depth;
829 deepvis = vislist;
830 /* DEBUG tt = ov->transparent_type;*/
831 /* DEBUG tv = ov->value; */
832 }
833 }
834
835 /*DEBUG
836 if (deepvis) {
837 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
838 deepvis->visualid, level, deepvis->depth, tt, tv );
839 }
840 */
841 return deepvis;
842 }
843
844
845
846 XVisualInfo *Fake_glXChooseVisual( Display *dpy, int screen, int *list )
847 {
848 int *parselist;
849 XVisualInfo *vis;
850 int min_ci = 0;
851 int min_red=0, min_green=0, min_blue=0;
852 GLboolean rgb_flag = GL_FALSE;
853 GLboolean alpha_flag = GL_FALSE;
854 GLboolean double_flag = GL_FALSE;
855 GLboolean stereo_flag = GL_FALSE;
856 GLint depth_size = 0;
857 GLint stencil_size = 0;
858 GLint accum_size = 0;
859 int level = 0;
860 int visual_type = DONT_CARE;
861 int trans_type = DONT_CARE;
862 int trans_value = DONT_CARE;
863
864 parselist = list;
865
866 while (*parselist) {
867
868 switch (*parselist) {
869 case GLX_USE_GL:
870 /* ignore */
871 parselist++;
872 break;
873 case GLX_BUFFER_SIZE:
874 parselist++;
875 min_ci = *parselist++;
876 break;
877 case GLX_LEVEL:
878 parselist++;
879 level = *parselist++;
880 break;
881 case GLX_RGBA:
882 rgb_flag = GL_TRUE;
883 parselist++;
884 break;
885 case GLX_DOUBLEBUFFER:
886 double_flag = GL_TRUE;
887 parselist++;
888 break;
889 case GLX_STEREO:
890 stereo_flag = GL_TRUE;
891 return NULL;
892 case GLX_AUX_BUFFERS:
893 /* ignore */
894 parselist++;
895 parselist++;
896 break;
897 case GLX_RED_SIZE:
898 parselist++;
899 min_red = *parselist++;
900 break;
901 case GLX_GREEN_SIZE:
902 parselist++;
903 min_green = *parselist++;
904 break;
905 case GLX_BLUE_SIZE:
906 parselist++;
907 min_blue = *parselist++;
908 break;
909 case GLX_ALPHA_SIZE:
910 parselist++;
911 {
912 GLint size = *parselist++;
913 alpha_flag = size>0 ? 1 : 0;
914 }
915 break;
916 case GLX_DEPTH_SIZE:
917 parselist++;
918 depth_size = *parselist++;
919 break;
920 case GLX_STENCIL_SIZE:
921 parselist++;
922 stencil_size = *parselist++;
923 break;
924 case GLX_ACCUM_RED_SIZE:
925 case GLX_ACCUM_GREEN_SIZE:
926 case GLX_ACCUM_BLUE_SIZE:
927 case GLX_ACCUM_ALPHA_SIZE:
928 parselist++;
929 {
930 GLint size = *parselist++;
931 accum_size = MAX2( accum_size, size );
932 }
933 break;
934
935 /*
936 * GLX_EXT_visual_info extension
937 */
938 case GLX_X_VISUAL_TYPE_EXT:
939 parselist++;
940 visual_type = *parselist++;
941 break;
942 case GLX_TRANSPARENT_TYPE_EXT:
943 parselist++;
944 trans_type = *parselist++;
945 break;
946 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
947 parselist++;
948 trans_value = *parselist++;
949 break;
950 case GLX_TRANSPARENT_RED_VALUE_EXT:
951 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
952 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
953 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
954 /* ignore */
955 parselist++;
956 parselist++;
957 break;
958
959 case None:
960 break;
961 default:
962 /* undefined attribute */
963 return NULL;
964 }
965 }
966
967 /*
968 * Since we're only simulating the GLX extension this function will never
969 * find any real GL visuals. Instead, all we can do is try to find an RGB
970 * or CI visual of appropriate depth. Other requested attributes such as
971 * double buffering, depth buffer, etc. will be associated with the X
972 * visual and stored in the VisualTable[].
973 */
974 if (level==0) {
975 /* normal color planes */
976 if (rgb_flag) {
977 /* Get an RGB visual */
978 int min_rgb = min_red + min_green + min_blue;
979 if (min_rgb>1 && min_rgb<8) {
980 /* a special case to be sure we can get a monochrome visual */
981 min_rgb = 1;
982 }
983 vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type );
984 }
985 else {
986 /* Get a color index visual */
987 vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type );
988 accum_size = 0;
989 }
990 }
991 else {
992 /* over/underlay planes */
993 if (rgb_flag) {
994 /* rgba overlay */
995 int min_rgb = min_red + min_green + min_blue;
996 if (min_rgb>1 && min_rgb<8) {
997 /* a special case to be sure we can get a monochrome visual */
998 min_rgb = 1;
999 }
1000 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1001 trans_type, trans_value, min_rgb, visual_type );
1002 }
1003 else {
1004 /* color index overlay */
1005 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1006 trans_type, trans_value, min_ci, visual_type );
1007 }
1008 }
1009
1010 if (vis) {
1011 if (!save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1012 stereo_flag,
1013 depth_size, stencil_size, accum_size, level ))
1014 return NULL;
1015 }
1016
1017 return vis;
1018 }
1019
1020
1021
1022
1023 GLXContext Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1024 GLXContext share_list, Bool direct )
1025 {
1026 XMesaVisual glxvis;
1027 XMesaContext xmctx;
1028
1029 /* deallocate unused windows/buffers */
1030 XMesaGarbageCollect();
1031
1032 glxvis = find_glx_visual( dpy, visinfo );
1033 if (!glxvis) {
1034 /* This visual wasn't found with glXChooseVisual() */
1035 glxvis = create_glx_visual( dpy, visinfo );
1036 if (!glxvis) {
1037 /* unusable visual */
1038 return NULL;
1039 }
1040 }
1041
1042 xmctx = XMesaCreateContext( glxvis, (XMesaContext) share_list );
1043 if (xmctx) {
1044 /* set the direct/indirect flag */
1045 xmctx->direct = direct;
1046 }
1047 return (GLXContext) xmctx;
1048 }
1049
1050
1051 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1052 static GLXContext MakeCurrent_PrevContext = 0;
1053 static XMesaBuffer MakeCurrent_PrevBuffer = 0;
1054
1055 Bool Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1056 {
1057 if (ctx && drawable) {
1058 XMesaBuffer buffer;
1059
1060 if (drawable==MakeCurrent_PrevDrawable && ctx==MakeCurrent_PrevContext) {
1061 buffer = MakeCurrent_PrevBuffer;
1062 }
1063 else {
1064 buffer = XMesaFindBuffer( dpy, drawable );
1065 }
1066 if (!buffer) {
1067 /* drawable must be a new window! */
1068 buffer = XMesaCreateWindowBuffer2( ctx->xm_visual, drawable, ctx );
1069 if (!buffer) {
1070 /* Out of memory, or context/drawable depth mismatch */
1071 return False;
1072 }
1073 }
1074 MakeCurrent_PrevContext = ctx;
1075 MakeCurrent_PrevDrawable = drawable;
1076 MakeCurrent_PrevBuffer = buffer;
1077
1078 /* Now make current! */
1079 return (Bool) XMesaMakeCurrent( (XMesaContext) ctx, buffer );
1080 }
1081 else if (!ctx && !drawable) {
1082 /* release current context w/out assigning new one. */
1083 XMesaMakeCurrent( NULL, NULL );
1084 MakeCurrent_PrevContext = 0;
1085 MakeCurrent_PrevDrawable = 0;
1086 MakeCurrent_PrevBuffer = 0;
1087 return True;
1088 }
1089 else {
1090 /* ctx XOR drawable is NULL, this is an error */
1091 return False;
1092 }
1093 }
1094
1095
1096
1097 GLXPixmap Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo,
1098 Pixmap pixmap )
1099 {
1100 XMesaVisual v;
1101 XMesaBuffer b;
1102
1103 v = find_glx_visual( dpy, visinfo );
1104 if (!v) {
1105 v = create_glx_visual( dpy, visinfo );
1106 if (!v) {
1107 /* unusable visual */
1108 return 0;
1109 }
1110 }
1111
1112 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1113 if (!b) {
1114 return 0;
1115 }
1116 return b->frontbuffer;
1117 }
1118
1119
1120 #ifdef GLX_MESA_pixmap_colormap
1121
1122 GLXPixmap Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1123 Pixmap pixmap, Colormap cmap )
1124 {
1125 XMesaVisual v;
1126 XMesaBuffer b;
1127
1128 v = find_glx_visual( dpy, visinfo );
1129 if (!v) {
1130 v = create_glx_visual( dpy, visinfo );
1131 if (!v) {
1132 /* unusable visual */
1133 return 0;
1134 }
1135 }
1136
1137 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1138 if (!b) {
1139 return 0;
1140 }
1141 return b->frontbuffer;
1142 }
1143
1144 #endif
1145
1146
1147 void Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1148 {
1149 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1150 if (b) {
1151 XMesaDestroyBuffer(b);
1152 }
1153 else if (getenv("MESA_DEBUG")) {
1154 fprintf( stderr, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1155 }
1156 }
1157
1158
1159 void Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1160 GLuint mask )
1161 {
1162 XMesaContext xm_src = (XMesaContext) src;
1163 XMesaContext xm_dst = (XMesaContext) dst;
1164 (void) dpy;
1165 gl_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, mask );
1166 }
1167
1168
1169
1170 Bool Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1171 {
1172 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1173 (void) dpy;
1174 (void) errorb;
1175 (void) event;
1176 return True;
1177 }
1178
1179
1180 void _kw_ungrab_all( Display *dpy )
1181 {
1182 XUngrabPointer( dpy, CurrentTime );
1183 XUngrabKeyboard( dpy, CurrentTime );
1184 }
1185
1186
1187 void Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1188 {
1189 (void) dpy;
1190 MakeCurrent_PrevContext = 0;
1191 MakeCurrent_PrevDrawable = 0;
1192 MakeCurrent_PrevBuffer = 0;
1193 XMesaDestroyContext( (XMesaContext) ctx );
1194 XMesaGarbageCollect();
1195 }
1196
1197
1198
1199 Bool Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1200 {
1201 (void) dpy;
1202 return ((XMesaContext) ctx)->direct;
1203 }
1204
1205
1206
1207 void Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1208 {
1209 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1210
1211 if (buffer) {
1212 XMesaSwapBuffers(buffer);
1213 }
1214 else if (getenv("MESA_DEBUG")) {
1215 fprintf(stderr, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1216 }
1217 }
1218
1219
1220 void Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1221 int x, int y, int width, int height )
1222 {
1223 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1224 if (buffer) {
1225 XMesaCopySubBuffer(buffer, x, y, width, height);
1226 }
1227 else if (getenv("MESA_DEBUG")) {
1228 fprintf(stderr, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1229 }
1230 }
1231
1232
1233
1234 Bool Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1235 {
1236 (void) dpy;
1237 /* Return GLX version, not Mesa version */
1238 *maj = 1;
1239 *min = 1;
1240 return True;
1241 }
1242
1243
1244
1245 /*
1246 * Query the GLX attributes of the given XVisualInfo.
1247 */
1248 int Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1249 int attrib, int *value )
1250 {
1251 XMesaVisual glxvis;
1252
1253 glxvis = find_glx_visual( dpy, visinfo );
1254 if (!glxvis) {
1255 /* this visual wasn't obtained with glXChooseVisual */
1256 glxvis = create_glx_visual( dpy, visinfo );
1257 if (!glxvis) {
1258 /* this visual can't be used for GL rendering */
1259 if (attrib==GLX_USE_GL) {
1260 *value = (int) False;
1261 return 0;
1262 }
1263 else {
1264 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1265 return GLX_BAD_VISUAL;
1266 }
1267 }
1268 }
1269
1270 switch(attrib) {
1271 case GLX_USE_GL:
1272 *value = (int) True;
1273 return 0;
1274 case GLX_BUFFER_SIZE:
1275 *value = visinfo->depth;
1276 return 0;
1277 case GLX_LEVEL:
1278 *value = glxvis->level;
1279 return 0;
1280 case GLX_RGBA:
1281 if (glxvis->gl_visual->RGBAflag) {
1282 *value = True;
1283 }
1284 else {
1285 *value = False;
1286 }
1287 return 0;
1288 case GLX_DOUBLEBUFFER:
1289 *value = (int) glxvis->gl_visual->DBflag;
1290 return 0;
1291 case GLX_STEREO:
1292 *value = (int) glxvis->gl_visual->StereoFlag;
1293 return 0;
1294 case GLX_AUX_BUFFERS:
1295 *value = (int) False;
1296 return 0;
1297 case GLX_RED_SIZE:
1298 *value = glxvis->gl_visual->RedBits;
1299 return 0;
1300 case GLX_GREEN_SIZE:
1301 *value = glxvis->gl_visual->GreenBits;
1302 return 0;
1303 case GLX_BLUE_SIZE:
1304 *value = glxvis->gl_visual->BlueBits;
1305 return 0;
1306 case GLX_ALPHA_SIZE:
1307 *value = glxvis->gl_visual->AlphaBits;
1308 return 0;
1309 case GLX_DEPTH_SIZE:
1310 *value = glxvis->gl_visual->DepthBits;
1311 return 0;
1312 case GLX_STENCIL_SIZE:
1313 *value = glxvis->gl_visual->StencilBits;
1314 return 0;
1315 case GLX_ACCUM_RED_SIZE:
1316 case GLX_ACCUM_GREEN_SIZE:
1317 case GLX_ACCUM_BLUE_SIZE:
1318 *value = glxvis->gl_visual->AccumBits;
1319 return 0;
1320 case GLX_ACCUM_ALPHA_SIZE:
1321 if (glxvis->gl_visual->AlphaBits > 0)
1322 *value = glxvis->gl_visual->AccumBits;
1323 else
1324 *value = 0;
1325 return 0;
1326
1327 /*
1328 * GLX_EXT_visual_info extension
1329 */
1330 case GLX_X_VISUAL_TYPE_EXT:
1331 switch (glxvis->visinfo->CLASS) {
1332 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1333 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1334 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1335 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1336 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1337 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1338 }
1339 return 0;
1340 case GLX_TRANSPARENT_TYPE_EXT:
1341 if (glxvis->level==0) {
1342 /* normal planes */
1343 *value = GLX_NONE_EXT;
1344 }
1345 else if (glxvis->level>0) {
1346 /* overlay */
1347 if (glxvis->gl_visual->RGBAflag) {
1348 *value = GLX_TRANSPARENT_RGB_EXT;
1349 }
1350 else {
1351 *value = GLX_TRANSPARENT_INDEX_EXT;
1352 }
1353 }
1354 else if (glxvis->level<0) {
1355 /* underlay */
1356 *value = GLX_NONE_EXT;
1357 }
1358 return 0;
1359 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1360 {
1361 int pixel = transparent_pixel( glxvis );
1362 if (pixel>=0) {
1363 *value = pixel;
1364 }
1365 /* else undefined */
1366 }
1367 return 0;
1368 case GLX_TRANSPARENT_RED_VALUE_EXT:
1369 /* undefined */
1370 return 0;
1371 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1372 /* undefined */
1373 return 0;
1374 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1375 /* undefined */
1376 return 0;
1377 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1378 /* undefined */
1379 return 0;
1380
1381 /*
1382 * Extensions
1383 */
1384 default:
1385 return GLX_BAD_ATTRIBUTE;
1386 }
1387 }
1388
1389
1390
1391 GLXContext Fake_glXGetCurrentContext( void )
1392 {
1393 return (GLXContext) XMesaGetCurrentContext();
1394 }
1395
1396
1397
1398 GLXDrawable Fake_glXGetCurrentDrawable( void )
1399 {
1400 XMesaBuffer b = XMesaGetCurrentBuffer();
1401 if (b) {
1402 return b->frontbuffer;
1403 }
1404 else {
1405 return 0;
1406 }
1407 }
1408
1409
1410 void Fake_glXWaitGL( void )
1411 {
1412 XMesaContext xmesa = XMesaGetCurrentContext();
1413 XMesaFlush( xmesa );
1414 }
1415
1416
1417
1418 void Fake_glXWaitX( void )
1419 {
1420 XMesaContext xmesa = XMesaGetCurrentContext();
1421 XMesaFlush( xmesa );
1422 }
1423
1424
1425 /*
1426 * Return the extensions string, which is 3Dfx-dependant.
1427 */
1428 static const char *get_extensions( void )
1429 {
1430 #ifdef FX
1431 const char *fx = getenv("MESA_GLX_FX");
1432 if (fx && fx[0] != 'd') {
1433 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync GLX_EXT_get_proc_address GLX_MESA_set_3dfx_mode";
1434 }
1435 #endif
1436 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync GL_EXT_get_proc_address";
1437 }
1438
1439
1440
1441 /* GLX 1.1 and later */
1442 const char *Fake_glXQueryExtensionsString( Display *dpy, int screen )
1443 {
1444 (void) dpy;
1445 (void) screen;
1446 return get_extensions();
1447 }
1448
1449
1450
1451 /* GLX 1.1 and later */
1452 const char *Fake_glXQueryServerString( Display *dpy, int screen, int name )
1453 {
1454 static char *vendor = "Brian Paul";
1455 static char *version = "1.1 Mesa 3.1";
1456
1457 (void) dpy;
1458 (void) screen;
1459
1460 switch (name) {
1461 case GLX_EXTENSIONS:
1462 return get_extensions();
1463 case GLX_VENDOR:
1464 return vendor;
1465 case GLX_VERSION:
1466 return version;
1467 default:
1468 return NULL;
1469 }
1470 }
1471
1472
1473
1474 /* GLX 1.1 and later */
1475 const char *Fake_glXGetClientString( Display *dpy, int name )
1476 {
1477 static char *vendor = "Brian Paul";
1478 static char *version = "1.1 Mesa 3.1";
1479
1480 (void) dpy;
1481
1482 switch (name) {
1483 case GLX_EXTENSIONS:
1484 return get_extensions();
1485 case GLX_VENDOR:
1486 return vendor;
1487 case GLX_VERSION:
1488 return version;
1489 default:
1490 return NULL;
1491 }
1492 }
1493
1494
1495
1496 /*
1497 * Release the depth, stencil, accum buffers attached to a GLXDrawable
1498 * (a window or pixmap) prior to destroying the GLXDrawable.
1499 */
1500 Bool Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
1501 {
1502 XMesaBuffer b = XMesaFindBuffer(dpy, d);
1503 if (b) {
1504 XMesaDestroyBuffer(b);
1505 return True;
1506 }
1507 return False;
1508 }
1509
1510
1511 /*
1512 * GLX_MESA_set_3dfx_mode
1513 */
1514 GLboolean Fake_glXSet3DfxModeMESA( GLint mode )
1515 {
1516 return XMesaSetFXmode( mode );
1517 }
1518
1519
1520
1521 #if 0
1522 /*GLfunction Fake_glXGetProcAddress( const GLubyte *procName )*/
1523 void (*Fake_glXGetProcAddress( const GLubyte *procName ))()
1524 {
1525 typedef void (*GLfunction)();
1526 struct proc {
1527 const char *name;
1528 GLfunction address;
1529 };
1530 static struct proc procTable[] = {
1531 { "glXGetProcAddressEXT", (GLfunction) glXGetProcAddressEXT },
1532 { "glXCreateGLXPixmapMESA", (GLfunction) glXCreateGLXPixmapMESA },
1533 { "glXReleaseBuffersMESA", (GLfunction) glXReleaseBuffersMESA },
1534 { "glXCopySubBufferMESA", (GLfunction) glXCopySubBufferMESA },
1535 { "glXSet3DfxModeMESA", (GLfunction) glXSet3DfxModeMESA },
1536 /* NOTE: GLX_SGI_video_sync not implemented in Mesa */
1537 { NULL, NULL } /* end of list token */
1538 };
1539 GLuint i;
1540
1541 /* First, look for core library functions */
1542 GLfunction f = (GLfunction) gl_get_proc_address(procName);
1543 if (f)
1544 return f;
1545
1546 /* Second, look for GLX funtion */
1547 for (i = 0; procTable[i].address; i++) {
1548 if (strcmp((const char *) procName, procTable[i].name) == 0)
1549 return (GLfunction) procTable[i].address;
1550 }
1551
1552 return NULL;
1553 }
1554 #endif