added missing functions in GLX_functions[] array
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
1 /* $Id: fakeglx.c,v 1.19 1999/11/28 20:15:04 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
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 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
30 * to run on X servers which do not have the real GLX extension.
31 *
32 * Thanks to the contributors:
33 *
34 * Initial version: Philip Brown (philb@CSUA.Berkeley.EDU)
35 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
36 * Further visual-handling refinements: Wolfram Gloger
37 * (wmglo@Dent.MED.Uni-Muenchen.DE).
38 *
39 * Notes:
40 * Don't be fooled, stereo isn't supported yet.
41 */
42
43
44
45 #include "glxheader.h"
46 #include "glxapi.h"
47 #include "GL/xmesa.h"
48 #include "context.h"
49 #include "config.h"
50 #include "macros.h"
51 #include "types.h"
52 #include "xmesaP.h"
53
54
55 /* This indicates the client-side GLX API and GLX encoder version. */
56 #define CLIENT_MAJOR_VERSION 1
57 #define CLIENT_MINOR_VERSION 2
58
59 /* This indicates the server-side GLX decoder version.
60 * GLX 1.3 indicates OpenGL 1.2 support
61 */
62 #define SERVER_MAJOR_VERSION 1
63 #define SERVER_MINOR_VERSION 3
64
65 /* This is appended onto the glXGetClient/ServerString version strings. */
66 #define MESA_GLX_VERSION "Mesa 3.1"
67
68 /* Who implemented this GLX? */
69 #define VENDOR "Brian Paul"
70
71
72
73 /* Silence compiler warnings */
74 void Fake_glXDummyFunc( void )
75 {
76 (void) kernel8;
77 (void) DitherValues;
78 (void) HPCR_DRGB;
79 (void) kernel1;
80 }
81
82
83
84 #define DONT_CARE -1
85
86
87
88 #define MAX_VISUALS 100
89 static XMesaVisual VisualTable[MAX_VISUALS];
90 static int NumVisuals = 0;
91
92
93
94 /*
95 * This struct and some code fragments borrowed
96 * from Mark Kilgard's GLUT library.
97 */
98 typedef struct _OverlayInfo {
99 /* Avoid 64-bit portability problems by being careful to use
100 longs due to the way XGetWindowProperty is specified. Note
101 that these parameters are passed as CARD32s over X
102 protocol. */
103 unsigned long overlay_visual;
104 long transparent_type;
105 long value;
106 long layer;
107 } OverlayInfo;
108
109
110
111 /* Macro to handle c_class vs class field name in XVisualInfo struct */
112 #if defined(__cplusplus) || defined(c_plusplus)
113 #define CLASS c_class
114 #else
115 #define CLASS class
116 #endif
117
118
119
120
121 /*
122 * Test if the given XVisualInfo is usable for Mesa rendering.
123 */
124 static GLboolean is_usable_visual( XVisualInfo *vinfo )
125 {
126 switch (vinfo->CLASS) {
127 case StaticGray:
128 case GrayScale:
129 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
130 return GL_TRUE;
131 case StaticColor:
132 case PseudoColor:
133 /* Any StaticColor/PseudoColor visual of at least 4 bits */
134 if (vinfo->depth>=4) {
135 return GL_TRUE;
136 }
137 else {
138 return GL_FALSE;
139 }
140 case TrueColor:
141 case DirectColor:
142 /* Any depth of TrueColor or DirectColor works in RGB mode */
143 return GL_TRUE;
144 default:
145 /* This should never happen */
146 return GL_FALSE;
147 }
148 }
149
150
151
152 /*
153 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
154 * Input: dpy - the X display
155 * vinfo - the XVisualInfo to test
156 * Return: level of the visual:
157 * 0 = normal planes
158 * >0 = overlay planes
159 * <0 = underlay planes
160 */
161 static int level_of_visual( Display *dpy, XVisualInfo *vinfo )
162 {
163 Atom overlayVisualsAtom;
164 OverlayInfo *overlay_info = NULL;
165 int numOverlaysPerScreen;
166 Status status;
167 Atom actualType;
168 int actualFormat;
169 unsigned long sizeData, bytesLeft;
170 int i;
171
172 /*
173 * The SERVER_OVERLAY_VISUALS property on the root window contains
174 * a list of overlay visuals. Get that list now.
175 */
176 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
177 if (overlayVisualsAtom == None) {
178 return 0;
179 }
180
181 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
182 overlayVisualsAtom, 0L, (long) 10000, False,
183 overlayVisualsAtom, &actualType, &actualFormat,
184 &sizeData, &bytesLeft,
185 (unsigned char **) &overlay_info );
186
187 if (status != Success || actualType != overlayVisualsAtom ||
188 actualFormat != 32 || sizeData < 4) {
189 /* something went wrong */
190 XFree((void *) overlay_info);
191 return 0;
192 }
193
194 /* search the overlay visual list for the visual ID of interest */
195 numOverlaysPerScreen = (int) (sizeData / 4);
196 for (i=0;i<numOverlaysPerScreen;i++) {
197 OverlayInfo *ov;
198 ov = overlay_info + i;
199 if (ov->overlay_visual==vinfo->visualid) {
200 /* found the visual */
201 if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
202 int level = ov->layer;
203 XFree((void *) overlay_info);
204 return level;
205 }
206 else {
207 XFree((void *) overlay_info);
208 return 0;
209 }
210 }
211 }
212
213 /* The visual ID was not found in the overlay list. */
214 XFree((void *) overlay_info);
215 return 0;
216 }
217
218
219
220
221 /*
222 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
223 * configuration in our list of GLX visuals.
224 */
225 static XMesaVisual
226 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
227 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
228 GLboolean stereoFlag,
229 GLint depth_size, GLint stencil_size,
230 GLint accum_size, GLint level )
231 {
232 GLboolean ximageFlag = GL_TRUE;
233 XMesaVisual xmvis;
234 GLint i;
235 GLboolean comparePointers;
236
237 if (dbFlag) {
238 /* Check if the MESA_BACK_BUFFER env var is set */
239 char *backbuffer = getenv("MESA_BACK_BUFFER");
240 if (backbuffer) {
241 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
242 ximageFlag = GL_FALSE;
243 }
244 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
245 ximageFlag = GL_TRUE;
246 }
247 else {
248 fprintf(stderr, "Mesa: invalid value for MESA_BACK_BUFFER ");
249 fprintf(stderr, "environment variable, using an XImage.\n");
250 }
251 }
252 }
253
254 /* Comparing IDs uses less memory but sometimes fails. */
255 /* XXX revisit this after 3.0 is finished. */
256 if (getenv("MESA_GLX_VISUAL_HACK"))
257 comparePointers = GL_TRUE;
258 else
259 comparePointers = GL_FALSE;
260
261 /* First check if a matching visual is already in the list */
262 for (i=0; i<NumVisuals; i++) {
263 XMesaVisual v = VisualTable[i];
264 if (v->display == dpy
265 && v->level == level
266 && v->ximage_flag == ximageFlag
267 && v->gl_visual->RGBAflag == rgbFlag
268 && v->gl_visual->DBflag == dbFlag
269 && v->gl_visual->StereoFlag == stereoFlag
270 && (v->gl_visual->AlphaBits > 0) == alphaFlag
271 && (v->gl_visual->DepthBits >= depth_size || depth_size == 0)
272 && (v->gl_visual->StencilBits >= stencil_size || stencil_size == 0)
273 && (v->gl_visual->AccumBits >= accum_size || accum_size == 0)) {
274 /* now either compare XVisualInfo pointers or visual IDs */
275 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
276 || (comparePointers && v->vishandle == vinfo)) {
277 return v;
278 }
279 }
280 }
281
282 /* Create a new visual and add it to the list. */
283
284 if (NumVisuals>=MAX_VISUALS) {
285 fprintf( stderr, "GLX Error: maximum number of visuals exceeded\n");
286 return NULL;
287 }
288
289 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
290 stereoFlag, ximageFlag,
291 depth_size, stencil_size, accum_size, level );
292 if (xmvis) {
293 VisualTable[NumVisuals] = xmvis;
294 NumVisuals++;
295 }
296 return xmvis;
297 }
298
299
300
301 /*
302 * Create a GLX visual from a regular XVisualInfo.
303 */
304 static XMesaVisual
305 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
306 {
307 int vislevel;
308
309 vislevel = level_of_visual( dpy, visinfo );
310 if (vislevel) {
311 /* Configure this visual as a CI, single-buffered overlay */
312 return save_glx_visual( dpy, visinfo,
313 GL_FALSE, /* rgb */
314 GL_FALSE, /* alpha */
315 GL_FALSE, /* double */
316 GL_FALSE, /* stereo */
317 0, /* depth bits */
318 0, /* stencil bits */
319 0, /* accum bits */
320 vislevel /* level */
321 );
322 }
323 else if (is_usable_visual( visinfo )) {
324 /* Configure this visual as RGB, double-buffered, depth-buffered. */
325 /* This is surely wrong for some people's needs but what else */
326 /* can be done? They should use glXChooseVisual(). */
327 return save_glx_visual( dpy, visinfo,
328 GL_TRUE, /* rgb */
329 GL_FALSE, /* alpha */
330 GL_TRUE, /* double */
331 GL_FALSE, /* stereo */
332 8*sizeof(GLdepth),
333 8*sizeof(GLstencil),
334 8*sizeof(GLaccum),
335 0 /* level */
336 );
337 }
338 else {
339 fprintf(stderr,"Mesa: error in glXCreateContext: bad visual\n");
340 return NULL;
341 }
342 }
343
344
345
346 /*
347 * Find the GLX visual associated with an XVisualInfo.
348 */
349 static XMesaVisual
350 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
351 {
352 int i;
353
354 /* First try to match pointers */
355 for (i=0;i<NumVisuals;i++) {
356 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
357 return VisualTable[i];
358 }
359 }
360 /* try to match visual id */
361 for (i=0;i<NumVisuals;i++) {
362 if (VisualTable[i]->display==dpy
363 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
364 return VisualTable[i];
365 }
366 }
367 return NULL;
368 }
369
370
371
372 /*
373 * Return the transparent pixel value for a GLX visual.
374 * Input: glxvis - the glx_visual
375 * Return: a pixel value or -1 if no transparent pixel
376 */
377 static int transparent_pixel( XMesaVisual glxvis )
378 {
379 Display *dpy = glxvis->display;
380 XVisualInfo *vinfo = glxvis->visinfo;
381 Atom overlayVisualsAtom;
382 OverlayInfo *overlay_info = NULL;
383 int numOverlaysPerScreen;
384 Status status;
385 Atom actualType;
386 int actualFormat;
387 unsigned long sizeData, bytesLeft;
388 int i;
389
390 /*
391 * The SERVER_OVERLAY_VISUALS property on the root window contains
392 * a list of overlay visuals. Get that list now.
393 */
394 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
395 if (overlayVisualsAtom == None) {
396 return -1;
397 }
398
399 status = XGetWindowProperty(dpy, RootWindow( dpy, vinfo->screen ),
400 overlayVisualsAtom, 0L, (long) 10000, False,
401 overlayVisualsAtom, &actualType, &actualFormat,
402 &sizeData, &bytesLeft,
403 (unsigned char **) &overlay_info );
404
405 if (status != Success || actualType != overlayVisualsAtom ||
406 actualFormat != 32 || sizeData < 4) {
407 /* something went wrong */
408 XFree((void *) overlay_info);
409 return -1;
410 }
411
412 /* search the overlay visual list for the visual ID of interest */
413 numOverlaysPerScreen = (int) (sizeData / 4);
414 for (i=0;i<numOverlaysPerScreen;i++) {
415 OverlayInfo *ov;
416 ov = overlay_info + i;
417 if (ov->overlay_visual==vinfo->visualid) {
418 /* found it! */
419 if (ov->transparent_type==0) {
420 /* type 0 indicates no transparency */
421 XFree((void *) overlay_info);
422 return -1;
423 }
424 else {
425 /* ov->value is the transparent pixel */
426 XFree((void *) overlay_info);
427 return ov->value;
428 }
429 }
430 }
431
432 /* The visual ID was not found in the overlay list. */
433 XFree((void *) overlay_info);
434 return -1;
435 }
436
437
438
439 /*
440 * Return number of bits set in n.
441 */
442 static int bitcount( unsigned long n )
443 {
444 int bits;
445 for (bits=0; n>0; n=n>>1) {
446 if (n&1) {
447 bits++;
448 }
449 }
450 return bits;
451 }
452
453
454 /*
455 * Try to get an X visual which matches the given arguments.
456 */
457 static XVisualInfo *get_visual( Display *dpy, int scr,
458 unsigned int depth, int xclass )
459 {
460 XVisualInfo temp, *vis;
461 long mask;
462 int n;
463 unsigned int default_depth;
464 int default_class;
465
466 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
467 temp.screen = scr;
468 temp.depth = depth;
469 temp.CLASS = xclass;
470
471 default_depth = DefaultDepth(dpy,scr);
472 default_class = DefaultVisual(dpy,scr)->CLASS;
473
474 if (depth==default_depth && xclass==default_class) {
475 /* try to get root window's visual */
476 temp.visualid = DefaultVisual(dpy,scr)->visualid;
477 mask |= VisualIDMask;
478 }
479
480 vis = XGetVisualInfo( dpy, mask, &temp, &n );
481
482 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
483 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
484 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
485 */
486 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
487 if (bitcount(vis->red_mask) <= 8
488 && bitcount(vis->green_mask) <= 8
489 && bitcount(vis->blue_mask) <= 8) {
490 return vis;
491 }
492 else {
493 XFree((void *) vis);
494 return NULL;
495 }
496 }
497
498 return vis;
499 }
500
501
502
503 /*
504 * Retrieve the value of the given environment variable and find
505 * the X visual which matches it.
506 * Input: dpy - the display
507 * screen - the screen number
508 * varname - the name of the environment variable
509 * Return: an XVisualInfo pointer to NULL if error.
510 */
511 static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname)
512 {
513 char value[100], type[100];
514 int depth, xclass = -1;
515 XVisualInfo *vis;
516
517 if (!getenv( varname )) {
518 return NULL;
519 }
520
521 strncpy( value, getenv(varname), 100 );
522 value[99] = 0;
523
524 sscanf( value, "%s %d", type, &depth );
525
526 if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
527 else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
528 else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
529 else if (strcmp(type,"StaticColor")==0) xclass = StaticColor;
530 else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
531 else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
532
533 if (xclass>-1 && depth>0) {
534 vis = get_visual( dpy, scr, depth, xclass );
535 if (vis) {
536 return vis;
537 }
538 }
539
540 fprintf( stderr, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
541 type, depth );
542 return NULL;
543 }
544
545
546
547 /*
548 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
549 * Input: dpy, screen - X display and screen number
550 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
551 * min_depth - minimum visual depth
552 * preferred_class - preferred GLX visual class or DONT_CARE
553 * Return: pointer to an XVisualInfo or NULL.
554 */
555 static XVisualInfo *choose_x_visual( Display *dpy, int screen,
556 GLboolean rgba, int min_depth,
557 int preferred_class )
558 {
559 XVisualInfo *vis;
560 int xclass, visclass;
561 int depth;
562
563 if (rgba) {
564 Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True);
565 /* First see if the MESA_RGB_VISUAL env var is defined */
566 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
567 if (vis) {
568 return vis;
569 }
570 /* Otherwise, search for a suitable visual */
571 if (preferred_class==DONT_CARE) {
572 for (xclass=0;xclass<6;xclass++) {
573 switch (xclass) {
574 case 0: visclass = TrueColor; break;
575 case 1: visclass = DirectColor; break;
576 case 2: visclass = PseudoColor; break;
577 case 3: visclass = StaticColor; break;
578 case 4: visclass = GrayScale; break;
579 case 5: visclass = StaticGray; break;
580 }
581 if (min_depth==0) {
582 /* start with shallowest */
583 for (depth=0;depth<=32;depth++) {
584 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
585 /* Special case: try to get 8-bit PseudoColor before */
586 /* 8-bit TrueColor */
587 vis = get_visual( dpy, screen, 8, PseudoColor );
588 if (vis) {
589 return vis;
590 }
591 }
592 vis = get_visual( dpy, screen, depth, visclass );
593 if (vis) {
594 return vis;
595 }
596 }
597 }
598 else {
599 /* start with deepest */
600 for (depth=32;depth>=min_depth;depth--) {
601 if (visclass==TrueColor && depth==8 && !hp_cr_maps) {
602 /* Special case: try to get 8-bit PseudoColor before */
603 /* 8-bit TrueColor */
604 vis = get_visual( dpy, screen, 8, PseudoColor );
605 if (vis) {
606 return vis;
607 }
608 }
609 vis = get_visual( dpy, screen, depth, visclass );
610 if (vis) {
611 return vis;
612 }
613 }
614 }
615 }
616 }
617 else {
618 /* search for a specific visual class */
619 switch (preferred_class) {
620 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
621 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
622 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
623 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
624 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
625 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
626 default: return NULL;
627 }
628 if (min_depth==0) {
629 /* start with shallowest */
630 for (depth=0;depth<=32;depth++) {
631 vis = get_visual( dpy, screen, depth, visclass );
632 if (vis) {
633 return vis;
634 }
635 }
636 }
637 else {
638 /* start with deepest */
639 for (depth=32;depth>=min_depth;depth--) {
640 vis = get_visual( dpy, screen, depth, visclass );
641 if (vis) {
642 return vis;
643 }
644 }
645 }
646 }
647 }
648 else {
649 /* First see if the MESA_CI_VISUAL env var is defined */
650 vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" );
651 if (vis) {
652 return vis;
653 }
654 /* Otherwise, search for a suitable visual, starting with shallowest */
655 if (preferred_class==DONT_CARE) {
656 for (xclass=0;xclass<4;xclass++) {
657 switch (xclass) {
658 case 0: visclass = PseudoColor; break;
659 case 1: visclass = StaticColor; break;
660 case 2: visclass = GrayScale; break;
661 case 3: visclass = StaticGray; break;
662 }
663 /* try 8-bit up through 16-bit */
664 for (depth=8;depth<=16;depth++) {
665 vis = get_visual( dpy, screen, depth, visclass );
666 if (vis) {
667 return vis;
668 }
669 }
670 /* try min_depth up to 8-bit */
671 for (depth=min_depth;depth<8;depth++) {
672 vis = get_visual( dpy, screen, depth, visclass );
673 if (vis) {
674 return vis;
675 }
676 }
677 }
678 }
679 else {
680 /* search for a specific visual class */
681 switch (preferred_class) {
682 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
683 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
684 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
685 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
686 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
687 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
688 default: return NULL;
689 }
690 /* try 8-bit up through 16-bit */
691 for (depth=8;depth<=16;depth++) {
692 vis = get_visual( dpy, screen, depth, visclass );
693 if (vis) {
694 return vis;
695 }
696 }
697 /* try min_depth up to 8-bit */
698 for (depth=min_depth;depth<8;depth++) {
699 vis = get_visual( dpy, screen, depth, visclass );
700 if (vis) {
701 return vis;
702 }
703 }
704 }
705 }
706
707 /* didn't find a visual */
708 return NULL;
709 }
710
711
712
713 /*
714 * Find the deepest X over/underlay visual of at least min_depth.
715 * Input: dpy, screen - X display and screen number
716 * level - the over/underlay level
717 * trans_type - transparent pixel type: GLX_NONE_EXT,
718 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
719 * or DONT_CARE
720 * trans_value - transparent pixel value or DONT_CARE
721 * min_depth - minimum visual depth
722 * preferred_class - preferred GLX visual class or DONT_CARE
723 * Return: pointer to an XVisualInfo or NULL.
724 */
725 static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr,
726 GLboolean rgbFlag,
727 int level, int trans_type,
728 int trans_value,
729 int min_depth,
730 int preferred_class )
731 {
732 Atom overlayVisualsAtom;
733 OverlayInfo *overlay_info;
734 int numOverlaysPerScreen;
735 Status status;
736 Atom actualType;
737 int actualFormat;
738 unsigned long sizeData, bytesLeft;
739 int i;
740 XVisualInfo *deepvis;
741 int deepest;
742
743 /*DEBUG int tt, tv; */
744
745 switch (preferred_class) {
746 case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break;
747 case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break;
748 case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break;
749 case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break;
750 case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break;
751 case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break;
752 default: preferred_class = DONT_CARE;
753 }
754
755 /*
756 * The SERVER_OVERLAY_VISUALS property on the root window contains
757 * a list of overlay visuals. Get that list now.
758 */
759 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
760 if (overlayVisualsAtom == (Atom) None) {
761 return NULL;
762 }
763
764 status = XGetWindowProperty(dpy, RootWindow( dpy, scr ),
765 overlayVisualsAtom, 0L, (long) 10000, False,
766 overlayVisualsAtom, &actualType, &actualFormat,
767 &sizeData, &bytesLeft,
768 (unsigned char **) &overlay_info );
769
770 if (status != Success || actualType != overlayVisualsAtom ||
771 actualFormat != 32 || sizeData < 4) {
772 /* something went wrong */
773 return NULL;
774 }
775
776 /* Search for the deepest overlay which satisifies all criteria. */
777 deepest = min_depth;
778 deepvis = NULL;
779
780 numOverlaysPerScreen = (int) (sizeData / 4);
781 for (i=0;i<numOverlaysPerScreen;i++) {
782 XVisualInfo *vislist, vistemplate;
783 int count;
784 OverlayInfo *ov;
785 ov = overlay_info + i;
786
787 if (ov->layer!=level) {
788 /* failed overlay level criteria */
789 continue;
790 }
791 if (!(trans_type==DONT_CARE
792 || (trans_type==GLX_TRANSPARENT_INDEX_EXT
793 && ov->transparent_type>0)
794 || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
795 /* failed transparent pixel type criteria */
796 continue;
797 }
798 if (trans_value!=DONT_CARE && trans_value!=ov->value) {
799 /* failed transparent pixel value criteria */
800 continue;
801 }
802
803 /* get XVisualInfo and check the depth */
804 vistemplate.visualid = ov->overlay_visual;
805 vistemplate.screen = scr;
806 vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
807 &vistemplate, &count );
808
809 if (count!=1) {
810 /* something went wrong */
811 continue;
812 }
813 if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
814 /* wrong visual class */
815 continue;
816 }
817
818 /* if RGB was requested, make sure we have True/DirectColor */
819 if (rgbFlag && vislist->CLASS != TrueColor
820 && vislist->CLASS != DirectColor)
821 continue;
822
823 /* if CI was requested, make sure we have a color indexed visual */
824 if (!rgbFlag
825 && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor))
826 continue;
827
828 if (deepvis==NULL || vislist->depth > deepest) {
829 /* YES! found a satisfactory visual */
830 if (deepvis) {
831 XFree( deepvis );
832 }
833 deepest = vislist->depth;
834 deepvis = vislist;
835 /* DEBUG tt = ov->transparent_type;*/
836 /* DEBUG tv = ov->value; */
837 }
838 }
839
840 /*DEBUG
841 if (deepvis) {
842 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
843 deepvis->visualid, level, deepvis->depth, tt, tv );
844 }
845 */
846 return deepvis;
847 }
848
849
850
851 static XVisualInfo *
852 Fake_glXChooseVisual( Display *dpy, int screen, int *list )
853 {
854 int *parselist;
855 XVisualInfo *vis;
856 int min_ci = 0;
857 int min_red=0, min_green=0, min_blue=0;
858 GLboolean rgb_flag = GL_FALSE;
859 GLboolean alpha_flag = GL_FALSE;
860 GLboolean double_flag = GL_FALSE;
861 GLboolean stereo_flag = GL_FALSE;
862 GLint depth_size = 0;
863 GLint stencil_size = 0;
864 GLint accum_size = 0;
865 int level = 0;
866 int visual_type = DONT_CARE;
867 int trans_type = DONT_CARE;
868 int trans_value = DONT_CARE;
869
870 parselist = list;
871
872 while (*parselist) {
873
874 switch (*parselist) {
875 case GLX_USE_GL:
876 /* ignore */
877 parselist++;
878 break;
879 case GLX_BUFFER_SIZE:
880 parselist++;
881 min_ci = *parselist++;
882 break;
883 case GLX_LEVEL:
884 parselist++;
885 level = *parselist++;
886 break;
887 case GLX_RGBA:
888 rgb_flag = GL_TRUE;
889 parselist++;
890 break;
891 case GLX_DOUBLEBUFFER:
892 double_flag = GL_TRUE;
893 parselist++;
894 break;
895 case GLX_STEREO:
896 stereo_flag = GL_TRUE;
897 return NULL;
898 case GLX_AUX_BUFFERS:
899 /* ignore */
900 parselist++;
901 parselist++;
902 break;
903 case GLX_RED_SIZE:
904 parselist++;
905 min_red = *parselist++;
906 break;
907 case GLX_GREEN_SIZE:
908 parselist++;
909 min_green = *parselist++;
910 break;
911 case GLX_BLUE_SIZE:
912 parselist++;
913 min_blue = *parselist++;
914 break;
915 case GLX_ALPHA_SIZE:
916 parselist++;
917 {
918 GLint size = *parselist++;
919 alpha_flag = size>0 ? 1 : 0;
920 }
921 break;
922 case GLX_DEPTH_SIZE:
923 parselist++;
924 depth_size = *parselist++;
925 break;
926 case GLX_STENCIL_SIZE:
927 parselist++;
928 stencil_size = *parselist++;
929 break;
930 case GLX_ACCUM_RED_SIZE:
931 case GLX_ACCUM_GREEN_SIZE:
932 case GLX_ACCUM_BLUE_SIZE:
933 case GLX_ACCUM_ALPHA_SIZE:
934 parselist++;
935 {
936 GLint size = *parselist++;
937 accum_size = MAX2( accum_size, size );
938 }
939 break;
940
941 /*
942 * GLX_EXT_visual_info extension
943 */
944 case GLX_X_VISUAL_TYPE_EXT:
945 parselist++;
946 visual_type = *parselist++;
947 break;
948 case GLX_TRANSPARENT_TYPE_EXT:
949 parselist++;
950 trans_type = *parselist++;
951 break;
952 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
953 parselist++;
954 trans_value = *parselist++;
955 break;
956 case GLX_TRANSPARENT_RED_VALUE_EXT:
957 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
958 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
959 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
960 /* ignore */
961 parselist++;
962 parselist++;
963 break;
964
965 case None:
966 break;
967 default:
968 /* undefined attribute */
969 return NULL;
970 }
971 }
972
973 /*
974 * Since we're only simulating the GLX extension this function will never
975 * find any real GL visuals. Instead, all we can do is try to find an RGB
976 * or CI visual of appropriate depth. Other requested attributes such as
977 * double buffering, depth buffer, etc. will be associated with the X
978 * visual and stored in the VisualTable[].
979 */
980 if (level==0) {
981 /* normal color planes */
982 if (rgb_flag) {
983 /* Get an RGB visual */
984 int min_rgb = min_red + min_green + min_blue;
985 if (min_rgb>1 && min_rgb<8) {
986 /* a special case to be sure we can get a monochrome visual */
987 min_rgb = 1;
988 }
989 vis = choose_x_visual( dpy, screen, rgb_flag, min_rgb, visual_type );
990 }
991 else {
992 /* Get a color index visual */
993 vis = choose_x_visual( dpy, screen, rgb_flag, min_ci, visual_type );
994 accum_size = 0;
995 }
996 }
997 else {
998 /* over/underlay planes */
999 if (rgb_flag) {
1000 /* rgba overlay */
1001 int min_rgb = min_red + min_green + min_blue;
1002 if (min_rgb>1 && min_rgb<8) {
1003 /* a special case to be sure we can get a monochrome visual */
1004 min_rgb = 1;
1005 }
1006 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1007 trans_type, trans_value, min_rgb, visual_type );
1008 }
1009 else {
1010 /* color index overlay */
1011 vis = choose_x_overlay_visual( dpy, screen, rgb_flag, level,
1012 trans_type, trans_value, min_ci, visual_type );
1013 }
1014 }
1015
1016 if (vis) {
1017 if (!save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1018 stereo_flag,
1019 depth_size, stencil_size, accum_size, level ))
1020 return NULL;
1021 }
1022
1023 return vis;
1024 }
1025
1026
1027
1028
1029 static GLXContext
1030 Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1031 GLXContext share_list, Bool direct )
1032 {
1033 XMesaVisual glxvis;
1034 XMesaContext xmctx;
1035
1036 /* deallocate unused windows/buffers */
1037 XMesaGarbageCollect();
1038
1039 glxvis = find_glx_visual( dpy, visinfo );
1040 if (!glxvis) {
1041 /* This visual wasn't found with glXChooseVisual() */
1042 glxvis = create_glx_visual( dpy, visinfo );
1043 if (!glxvis) {
1044 /* unusable visual */
1045 return NULL;
1046 }
1047 }
1048
1049 xmctx = XMesaCreateContext( glxvis, (XMesaContext) share_list );
1050 if (xmctx) {
1051 /* set the direct/indirect flag */
1052 xmctx->direct = direct;
1053 }
1054 return (GLXContext) xmctx;
1055 }
1056
1057
1058 static GLXContext MakeCurrent_PrevContext = 0;
1059 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1060 static GLXDrawable MakeCurrent_PrevReadable = 0;
1061 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1062 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1063
1064 /* GLX 1.3 and later */
1065 static Bool
1066 Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1067 GLXDrawable read, GLXContext ctx )
1068 {
1069 if (ctx && draw && read) {
1070 XMesaBuffer drawBuffer, readBuffer;
1071 XMesaContext xmctx = (XMesaContext) ctx;
1072
1073 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1074 if (ctx == MakeCurrent_PrevContext
1075 && draw == MakeCurrent_PrevDrawable) {
1076 drawBuffer = MakeCurrent_PrevDrawBuffer;
1077 }
1078 else {
1079 drawBuffer = XMesaFindBuffer( dpy, draw );
1080 }
1081 if (!drawBuffer) {
1082 /* drawable must be a new window! */
1083 drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, ctx );
1084 if (!drawBuffer) {
1085 /* Out of memory, or context/drawable depth mismatch */
1086 return False;
1087 }
1088 }
1089
1090 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1091 if (ctx == MakeCurrent_PrevContext
1092 && read == MakeCurrent_PrevReadable) {
1093 readBuffer = MakeCurrent_PrevReadBuffer;
1094 }
1095 else {
1096 readBuffer = XMesaFindBuffer( dpy, read );
1097 }
1098 if (!readBuffer) {
1099 /* drawable must be a new window! */
1100 readBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, read, ctx );
1101 if (!readBuffer) {
1102 /* Out of memory, or context/drawable depth mismatch */
1103 return False;
1104 }
1105 }
1106
1107 MakeCurrent_PrevContext = ctx;
1108 MakeCurrent_PrevDrawable = draw;
1109 MakeCurrent_PrevReadable = read;
1110 MakeCurrent_PrevDrawBuffer = drawBuffer;
1111 MakeCurrent_PrevReadBuffer = readBuffer;
1112
1113 /* Now make current! */
1114 return (Bool) XMesaMakeCurrent2((XMesaContext) ctx, drawBuffer, readBuffer);
1115 }
1116 else if (!ctx && !draw && !read) {
1117 /* release current context w/out assigning new one. */
1118 XMesaMakeCurrent( NULL, NULL );
1119 MakeCurrent_PrevContext = 0;
1120 MakeCurrent_PrevDrawable = 0;
1121 MakeCurrent_PrevReadable = 0;
1122 MakeCurrent_PrevDrawBuffer = 0;
1123 MakeCurrent_PrevReadBuffer = 0;
1124 return True;
1125 }
1126 else {
1127 /* The args must either all be non-zero or all zero.
1128 * This is an error.
1129 */
1130 return False;
1131 }
1132 }
1133
1134
1135
1136 static Bool
1137 Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1138 {
1139 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1140 }
1141
1142
1143
1144 static GLXPixmap
1145 Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1146 {
1147 XMesaVisual v;
1148 XMesaBuffer b;
1149
1150 v = find_glx_visual( dpy, visinfo );
1151 if (!v) {
1152 v = create_glx_visual( dpy, visinfo );
1153 if (!v) {
1154 /* unusable visual */
1155 return 0;
1156 }
1157 }
1158
1159 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1160 if (!b) {
1161 return 0;
1162 }
1163 return b->frontbuffer;
1164 }
1165
1166
1167 #ifdef GLX_MESA_pixmap_colormap
1168
1169 static GLXPixmap
1170 Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1171 Pixmap pixmap, Colormap cmap )
1172 {
1173 XMesaVisual v;
1174 XMesaBuffer b;
1175
1176 v = find_glx_visual( dpy, visinfo );
1177 if (!v) {
1178 v = create_glx_visual( dpy, visinfo );
1179 if (!v) {
1180 /* unusable visual */
1181 return 0;
1182 }
1183 }
1184
1185 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1186 if (!b) {
1187 return 0;
1188 }
1189 return b->frontbuffer;
1190 }
1191
1192 #endif
1193
1194
1195 static void
1196 Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1197 {
1198 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1199 if (b) {
1200 XMesaDestroyBuffer(b);
1201 }
1202 else if (getenv("MESA_DEBUG")) {
1203 fprintf( stderr, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1204 }
1205 }
1206
1207
1208 static void
1209 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1210 GLuint mask )
1211 {
1212 XMesaContext xm_src = (XMesaContext) src;
1213 XMesaContext xm_dst = (XMesaContext) dst;
1214 (void) dpy;
1215 gl_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, mask );
1216 }
1217
1218
1219
1220 static Bool
1221 Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1222 {
1223 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1224 (void) dpy;
1225 (void) errorb;
1226 (void) event;
1227 return True;
1228 }
1229
1230
1231 void _kw_ungrab_all( Display *dpy )
1232 {
1233 XUngrabPointer( dpy, CurrentTime );
1234 XUngrabKeyboard( dpy, CurrentTime );
1235 }
1236
1237
1238 static void
1239 Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1240 {
1241 (void) dpy;
1242 MakeCurrent_PrevContext = 0;
1243 MakeCurrent_PrevDrawable = 0;
1244 MakeCurrent_PrevReadable = 0;
1245 MakeCurrent_PrevDrawBuffer = 0;
1246 MakeCurrent_PrevReadBuffer = 0;
1247 XMesaDestroyContext( (XMesaContext) ctx );
1248 XMesaGarbageCollect();
1249 }
1250
1251
1252
1253 static Bool
1254 Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1255 {
1256 (void) dpy;
1257 return ((XMesaContext) ctx)->direct;
1258 }
1259
1260
1261
1262 static void
1263 Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1264 {
1265 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1266
1267 if (buffer) {
1268 XMesaSwapBuffers(buffer);
1269 }
1270 else if (getenv("MESA_DEBUG")) {
1271 fprintf(stderr, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1272 }
1273 }
1274
1275
1276 static void
1277 Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1278 int x, int y, int width, int height )
1279 {
1280 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1281 if (buffer) {
1282 XMesaCopySubBuffer(buffer, x, y, width, height);
1283 }
1284 else if (getenv("MESA_DEBUG")) {
1285 fprintf(stderr, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1286 }
1287 }
1288
1289
1290
1291 static Bool
1292 Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1293 {
1294 (void) dpy;
1295 /* Return GLX version, not Mesa version */
1296 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1297 *maj = CLIENT_MAJOR_VERSION;
1298 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1299 return True;
1300 }
1301
1302
1303
1304 /*
1305 * Query the GLX attributes of the given XVisualInfo.
1306 */
1307 static int
1308 Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1309 int attrib, int *value )
1310 {
1311 XMesaVisual glxvis;
1312
1313 glxvis = find_glx_visual( dpy, visinfo );
1314 if (!glxvis) {
1315 /* this visual wasn't obtained with glXChooseVisual */
1316 glxvis = create_glx_visual( dpy, visinfo );
1317 if (!glxvis) {
1318 /* this visual can't be used for GL rendering */
1319 if (attrib==GLX_USE_GL) {
1320 *value = (int) False;
1321 return 0;
1322 }
1323 else {
1324 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1325 return GLX_BAD_VISUAL;
1326 }
1327 }
1328 }
1329
1330 switch(attrib) {
1331 case GLX_USE_GL:
1332 *value = (int) True;
1333 return 0;
1334 case GLX_BUFFER_SIZE:
1335 *value = visinfo->depth;
1336 return 0;
1337 case GLX_LEVEL:
1338 *value = glxvis->level;
1339 return 0;
1340 case GLX_RGBA:
1341 if (glxvis->gl_visual->RGBAflag) {
1342 *value = True;
1343 }
1344 else {
1345 *value = False;
1346 }
1347 return 0;
1348 case GLX_DOUBLEBUFFER:
1349 *value = (int) glxvis->gl_visual->DBflag;
1350 return 0;
1351 case GLX_STEREO:
1352 *value = (int) glxvis->gl_visual->StereoFlag;
1353 return 0;
1354 case GLX_AUX_BUFFERS:
1355 *value = (int) False;
1356 return 0;
1357 case GLX_RED_SIZE:
1358 *value = glxvis->gl_visual->RedBits;
1359 return 0;
1360 case GLX_GREEN_SIZE:
1361 *value = glxvis->gl_visual->GreenBits;
1362 return 0;
1363 case GLX_BLUE_SIZE:
1364 *value = glxvis->gl_visual->BlueBits;
1365 return 0;
1366 case GLX_ALPHA_SIZE:
1367 *value = glxvis->gl_visual->AlphaBits;
1368 return 0;
1369 case GLX_DEPTH_SIZE:
1370 *value = glxvis->gl_visual->DepthBits;
1371 return 0;
1372 case GLX_STENCIL_SIZE:
1373 *value = glxvis->gl_visual->StencilBits;
1374 return 0;
1375 case GLX_ACCUM_RED_SIZE:
1376 case GLX_ACCUM_GREEN_SIZE:
1377 case GLX_ACCUM_BLUE_SIZE:
1378 *value = glxvis->gl_visual->AccumBits;
1379 return 0;
1380 case GLX_ACCUM_ALPHA_SIZE:
1381 if (glxvis->gl_visual->AlphaBits > 0)
1382 *value = glxvis->gl_visual->AccumBits;
1383 else
1384 *value = 0;
1385 return 0;
1386
1387 /*
1388 * GLX_EXT_visual_info extension
1389 */
1390 case GLX_X_VISUAL_TYPE_EXT:
1391 switch (glxvis->visinfo->CLASS) {
1392 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1393 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1394 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1395 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1396 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1397 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1398 }
1399 return 0;
1400 case GLX_TRANSPARENT_TYPE_EXT:
1401 if (glxvis->level==0) {
1402 /* normal planes */
1403 *value = GLX_NONE_EXT;
1404 }
1405 else if (glxvis->level>0) {
1406 /* overlay */
1407 if (glxvis->gl_visual->RGBAflag) {
1408 *value = GLX_TRANSPARENT_RGB_EXT;
1409 }
1410 else {
1411 *value = GLX_TRANSPARENT_INDEX_EXT;
1412 }
1413 }
1414 else if (glxvis->level<0) {
1415 /* underlay */
1416 *value = GLX_NONE_EXT;
1417 }
1418 return 0;
1419 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1420 {
1421 int pixel = transparent_pixel( glxvis );
1422 if (pixel>=0) {
1423 *value = pixel;
1424 }
1425 /* else undefined */
1426 }
1427 return 0;
1428 case GLX_TRANSPARENT_RED_VALUE_EXT:
1429 /* undefined */
1430 return 0;
1431 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1432 /* undefined */
1433 return 0;
1434 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1435 /* undefined */
1436 return 0;
1437 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1438 /* undefined */
1439 return 0;
1440
1441 /*
1442 * Extensions
1443 */
1444 default:
1445 return GLX_BAD_ATTRIBUTE;
1446 }
1447 }
1448
1449
1450
1451 static void
1452 Fake_glXWaitGL( void )
1453 {
1454 XMesaContext xmesa = XMesaGetCurrentContext();
1455 XMesaFlush( xmesa );
1456 }
1457
1458
1459
1460 static void
1461 Fake_glXWaitX( void )
1462 {
1463 XMesaContext xmesa = XMesaGetCurrentContext();
1464 XMesaFlush( xmesa );
1465 }
1466
1467
1468 /*
1469 * Return the extensions string, which is 3Dfx-dependant.
1470 */
1471 static const char *get_extensions( void )
1472 {
1473 #ifdef FX
1474 const char *fx = getenv("MESA_GLX_FX");
1475 if (fx && fx[0] != 'd') {
1476 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync GLX_MESA_set_3dfx_mode";
1477 }
1478 #endif
1479 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync";
1480 }
1481
1482
1483
1484 /* GLX 1.1 and later */
1485 static const char *
1486 Fake_glXQueryExtensionsString( Display *dpy, int screen )
1487 {
1488 (void) dpy;
1489 (void) screen;
1490 return get_extensions();
1491 }
1492
1493
1494
1495 /* GLX 1.1 and later */
1496 static const char *
1497 Fake_glXQueryServerString( Display *dpy, int screen, int name )
1498 {
1499 static char version[1000];
1500 sprintf(version, "%d.%d %s", SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION,
1501 MESA_GLX_VERSION);
1502
1503 (void) dpy;
1504 (void) screen;
1505
1506 switch (name) {
1507 case GLX_EXTENSIONS:
1508 return get_extensions();
1509 case GLX_VENDOR:
1510 return VENDOR;
1511 case GLX_VERSION:
1512 return version;
1513 default:
1514 return NULL;
1515 }
1516 }
1517
1518
1519
1520 /* GLX 1.1 and later */
1521 static const char *
1522 Fake_glXGetClientString( Display *dpy, int name )
1523 {
1524 static char version[1000];
1525 sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, CLIENT_MINOR_VERSION,
1526 MESA_GLX_VERSION);
1527
1528 (void) dpy;
1529
1530 switch (name) {
1531 case GLX_EXTENSIONS:
1532 return get_extensions();
1533 case GLX_VENDOR:
1534 return VENDOR;
1535 case GLX_VERSION:
1536 return version;
1537 default:
1538 return NULL;
1539 }
1540 }
1541
1542
1543
1544 /*
1545 * GLX 1.3 and later
1546 */
1547
1548 static GLXFBConfig
1549 Fake_glXChooseFBConfig( Display *dpy, int screen,
1550 const int *attribList, int *nitems )
1551 {
1552 (void) dpy;
1553 (void) screen;
1554 (void) attribList;
1555 (void) nitems;
1556 return 0;
1557 }
1558
1559
1560 static int
1561 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1562 int attribute, int *value )
1563 {
1564 (void) dpy;
1565 (void) config;
1566 (void) attribute;
1567 (void) value;
1568 return 0;
1569 }
1570
1571
1572 static XVisualInfo *
1573 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1574 {
1575 (void) dpy;
1576 (void) config;
1577 return 0;
1578 }
1579
1580
1581 static GLXWindow
1582 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1583 const int *attribList )
1584 {
1585 (void) dpy;
1586 (void) config;
1587 (void) win;
1588 (void) attribList;
1589 return 0;
1590 }
1591
1592
1593 static void
1594 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1595 {
1596 (void) dpy;
1597 (void) window;
1598 return;
1599 }
1600
1601
1602 static GLXPixmap
1603 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1604 const int *attribList )
1605 {
1606 (void) dpy;
1607 (void) config;
1608 (void) pixmap;
1609 (void) attribList;
1610 return 0;
1611 }
1612
1613
1614 static void
1615 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1616 {
1617 (void) dpy;
1618 (void) pixmap;
1619 return;
1620 }
1621
1622
1623 static GLXPbuffer
1624 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1625 const int *attribList )
1626 {
1627 (void) dpy;
1628 (void) config;
1629 (void) attribList;
1630 return 0;
1631 }
1632
1633
1634 static void
1635 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
1636 {
1637 (void) dpy;
1638 (void) pbuf;
1639 }
1640
1641
1642 static void
1643 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
1644 unsigned int *value )
1645 {
1646 (void) dpy;
1647 (void) draw;
1648 (void) attribute;
1649 (void) value;
1650 }
1651
1652
1653 static GLXContext
1654 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
1655 int renderType, GLXContext shareList, Bool direct )
1656 {
1657 (void) dpy;
1658 (void) config;
1659 (void) renderType;
1660 (void) shareList;
1661 (void) direct;
1662 return 0;
1663 }
1664
1665
1666 static int
1667 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
1668 {
1669 (void) dpy;
1670 (void) ctx;
1671 (void) attribute;
1672 (void) value;
1673 return 0;
1674 }
1675
1676
1677 static void
1678 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
1679 {
1680 (void) dpy;
1681 (void) drawable;
1682 (void) mask;
1683 }
1684
1685
1686 static void
1687 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
1688 unsigned long *mask )
1689 {
1690 (void) dpy;
1691 (void) drawable;
1692 (void) mask;
1693 }
1694
1695
1696
1697 /*
1698 * Release the depth, stencil, accum buffers attached to a GLXDrawable
1699 * (a window or pixmap) prior to destroying the GLXDrawable.
1700 */
1701 static Bool
1702 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
1703 {
1704 XMesaBuffer b = XMesaFindBuffer(dpy, d);
1705 if (b) {
1706 XMesaDestroyBuffer(b);
1707 return True;
1708 }
1709 return False;
1710 }
1711
1712
1713 /*
1714 * GLX_MESA_set_3dfx_mode
1715 */
1716 static GLboolean
1717 Fake_glXSet3DfxModeMESA( GLint mode )
1718 {
1719 return XMesaSetFXmode( mode );
1720 }
1721
1722
1723 /*
1724 * GLX_SGI_video_sync
1725 */
1726
1727 #ifdef GLX_SGI_video_sync
1728
1729 static int
1730 Fake_glXGetVideoSyncSGI(unsigned int *count)
1731 {
1732 return 0;
1733 }
1734
1735
1736 static int
1737 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1738 {
1739 return 0;
1740 }
1741
1742 #endif
1743
1744
1745
1746 extern void Fake_glXUseXFont( Font font, int first, int count, int listbase );
1747
1748
1749 struct _glxapi_table *_mesa_GetGLXDispatchTable(void)
1750 {
1751 static struct _glxapi_table glx;
1752
1753 /* be sure our dispatch table size <= libGL's table */
1754 {
1755 int size = sizeof(struct _glxapi_table) / sizeof(void *);
1756 (void) size;
1757 assert(_glxapi_get_dispatch_table_size() >= size);
1758 }
1759
1760 /* initialize the whole table to no-ops */
1761 _glxapi_set_no_op_table(&glx);
1762
1763 /* now initialize the table with the functions I implement */
1764 glx.ChooseVisual = Fake_glXChooseVisual;
1765 glx.CopyContext = Fake_glXCopyContext;
1766 glx.CreateContext = Fake_glXCreateContext;
1767 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
1768 glx.DestroyContext = Fake_glXDestroyContext;
1769 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
1770 glx.GetConfig = Fake_glXGetConfig;
1771 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
1772 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
1773 glx.IsDirect = Fake_glXIsDirect;
1774 glx.MakeCurrent = Fake_glXMakeCurrent;
1775 glx.QueryExtension = Fake_glXQueryExtension;
1776 glx.QueryVersion = Fake_glXQueryVersion;
1777 glx.SwapBuffers = Fake_glXSwapBuffers;
1778 glx.UseXFont = Fake_glXUseXFont;
1779 glx.WaitGL = Fake_glXWaitGL;
1780 glx.WaitX = Fake_glXWaitX;
1781
1782 #ifdef _GLXAPI_VERSION_1_1
1783 glx.GetClientString = Fake_glXGetClientString;
1784 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
1785 glx.QueryServerString = Fake_glXQueryServerString;
1786 #endif
1787
1788 #ifdef _GLXAPI_VERSION_1_2
1789 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
1790 #endif
1791
1792 #ifdef _GLXAPI_VERSION_1_3
1793 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
1794 glx.CreateNewContext = Fake_glXCreateNewContext;
1795 glx.CreatePbuffer = Fake_glXCreatePbuffer;
1796 glx.CreatePixmap = Fake_glXCreatePixmap;
1797 glx.CreateWindow = Fake_glXCreateWindow;
1798 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
1799 glx.DestroyPixmap = Fake_glXDestroyPixmap;
1800 glx.DestroyWindow = Fake_glXDestroyWindow;
1801 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
1802 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
1803 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
1804 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
1805 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
1806 glx.QueryContext = Fake_glXQueryContext;
1807 glx.QueryDrawable = Fake_glXQueryDrawable;
1808 glx.SelectEvent = Fake_glXSelectEvent;
1809 #endif
1810
1811 #ifdef _GLXAPI_SGI_video_sync
1812 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
1813 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
1814 #endif
1815
1816 #ifdef _GLXAPI_MESA_copy_sub_buffer
1817 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
1818 #endif
1819
1820 #ifdef _GLXAPI_MESA_release_buffers
1821 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
1822 #endif
1823
1824 #ifdef _GLXAPI_MESA_pixmap_colormap
1825 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
1826 #endif
1827
1828 #ifdef _GLXAPI_MESA_set_3dfx_mode
1829 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
1830 #endif
1831
1832 return &glx;
1833 }