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