return NULL from Fake_glXCreateContext() if dpy or visinfo are NULL
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
1 /* $Id: fakeglx.c,v 1.62 2002/04/02 23:52:53 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 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
1137 if (!dpy || !visinfo)
1138 return 0;
1139
1140 glxCtx = CALLOC_STRUCT(fake_glx_context);
1141 if (!glxCtx)
1142 return 0;
1143
1144 /* deallocate unused windows/buffers */
1145 XMesaGarbageCollect();
1146
1147 glxvis = find_glx_visual( dpy, visinfo );
1148 if (!glxvis) {
1149 /* This visual wasn't found with glXChooseVisual() */
1150 glxvis = create_glx_visual( dpy, visinfo );
1151 if (!glxvis) {
1152 /* unusable visual */
1153 FREE(glxCtx);
1154 return NULL;
1155 }
1156 }
1157
1158 glxCtx->xmesaContext = XMesaCreateContext(glxvis,
1159 shareCtx ? shareCtx->xmesaContext : NULL);
1160 if (!glxCtx->xmesaContext) {
1161 FREE(glxCtx);
1162 return NULL;
1163 }
1164
1165 glxCtx->xmesaContext->direct = GL_FALSE;
1166 glxCtx->glxContext.isDirect = GL_FALSE;
1167 glxCtx->glxContext.currentDpy = dpy;
1168 glxCtx->glxContext.xid = (XID) glxCtx; /* self pointer */
1169
1170 assert((void *) glxCtx == (void *) &(glxCtx->glxContext));
1171
1172 return (GLXContext) glxCtx;
1173 }
1174
1175
1176 /* XXX these may have to be removed due to thread-safety issues. */
1177 static GLXContext MakeCurrent_PrevContext = 0;
1178 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1179 static GLXDrawable MakeCurrent_PrevReadable = 0;
1180 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1181 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1182
1183
1184 /* GLX 1.3 and later */
1185 static Bool
1186 Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1187 GLXDrawable read, GLXContext ctx )
1188 {
1189 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1190
1191 if (ctx && draw && read) {
1192 XMesaBuffer drawBuffer, readBuffer;
1193 XMesaContext xmctx = glxCtx->xmesaContext;
1194
1195 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1196 if (ctx == MakeCurrent_PrevContext
1197 && draw == MakeCurrent_PrevDrawable) {
1198 drawBuffer = MakeCurrent_PrevDrawBuffer;
1199 }
1200 else {
1201 drawBuffer = XMesaFindBuffer( dpy, draw );
1202 }
1203 if (!drawBuffer) {
1204 /* drawable must be a new window! */
1205 drawBuffer = XMesaCreateWindowBuffer2( xmctx->xm_visual, draw, xmctx);
1206 if (!drawBuffer) {
1207 /* Out of memory, or context/drawable depth mismatch */
1208 return False;
1209 }
1210 }
1211
1212 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1213 if (ctx == MakeCurrent_PrevContext
1214 && read == MakeCurrent_PrevReadable) {
1215 readBuffer = MakeCurrent_PrevReadBuffer;
1216 }
1217 else {
1218 readBuffer = XMesaFindBuffer( dpy, read );
1219 }
1220 if (!readBuffer) {
1221 /* drawable must be a new window! */
1222 readBuffer = XMesaCreateWindowBuffer2(glxCtx->xmesaContext->xm_visual,
1223 read, xmctx);
1224 if (!readBuffer) {
1225 /* Out of memory, or context/drawable depth mismatch */
1226 return False;
1227 }
1228 }
1229
1230 MakeCurrent_PrevContext = ctx;
1231 MakeCurrent_PrevDrawable = draw;
1232 MakeCurrent_PrevReadable = read;
1233 MakeCurrent_PrevDrawBuffer = drawBuffer;
1234 MakeCurrent_PrevReadBuffer = readBuffer;
1235
1236 /* Now make current! */
1237 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1238 ((__GLXcontext *) ctx)->currentDpy = dpy;
1239 ((__GLXcontext *) ctx)->currentDrawable = draw;
1240 #ifndef GLX_BUILT_IN_XMESA
1241 ((__GLXcontext *) ctx)->currentReadable = read;
1242 #else
1243 __glXSetCurrentContext(ctx);
1244 #endif
1245 return True;
1246 }
1247 else {
1248 return False;
1249 }
1250 }
1251 else if (!ctx && !draw && !read) {
1252 /* release current context w/out assigning new one. */
1253 XMesaMakeCurrent( NULL, NULL );
1254 MakeCurrent_PrevContext = 0;
1255 MakeCurrent_PrevDrawable = 0;
1256 MakeCurrent_PrevReadable = 0;
1257 MakeCurrent_PrevDrawBuffer = 0;
1258 MakeCurrent_PrevReadBuffer = 0;
1259 #ifdef GLX_BUILT_IN_XMESA
1260 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1261 #endif
1262 return True;
1263 }
1264 else {
1265 /* The args must either all be non-zero or all zero.
1266 * This is an error.
1267 */
1268 return False;
1269 }
1270 }
1271
1272
1273
1274 static Bool
1275 Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1276 {
1277 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1278 }
1279
1280
1281
1282 static GLXPixmap
1283 Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1284 {
1285 XMesaVisual v;
1286 XMesaBuffer b;
1287
1288 v = find_glx_visual( dpy, visinfo );
1289 if (!v) {
1290 v = create_glx_visual( dpy, visinfo );
1291 if (!v) {
1292 /* unusable visual */
1293 return 0;
1294 }
1295 }
1296
1297 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1298 if (!b) {
1299 return 0;
1300 }
1301 return b->frontbuffer;
1302 }
1303
1304
1305 /*** GLX_MESA_pixmap_colormap ***/
1306
1307 static GLXPixmap
1308 Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1309 Pixmap pixmap, Colormap cmap )
1310 {
1311 XMesaVisual v;
1312 XMesaBuffer b;
1313
1314 v = find_glx_visual( dpy, visinfo );
1315 if (!v) {
1316 v = create_glx_visual( dpy, visinfo );
1317 if (!v) {
1318 /* unusable visual */
1319 return 0;
1320 }
1321 }
1322
1323 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1324 if (!b) {
1325 return 0;
1326 }
1327 return b->frontbuffer;
1328 }
1329
1330
1331 static void
1332 Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1333 {
1334 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1335 if (b) {
1336 XMesaDestroyBuffer(b);
1337 }
1338 else if (getenv("MESA_DEBUG")) {
1339 fprintf( stderr, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1340 }
1341 }
1342
1343
1344
1345 static void
1346 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1347 unsigned long mask )
1348 {
1349 XMesaContext xm_src = (XMesaContext) src;
1350 XMesaContext xm_dst = (XMesaContext) dst;
1351 (void) dpy;
1352 _mesa_copy_context( xm_src->gl_ctx, xm_dst->gl_ctx, (GLuint) mask );
1353 }
1354
1355
1356
1357 static Bool
1358 Fake_glXQueryExtension( Display *dpy, int *errorb, int *event )
1359 {
1360 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1361 (void) dpy;
1362 (void) errorb;
1363 (void) event;
1364 return True;
1365 }
1366
1367
1368 extern void _kw_ungrab_all( Display *dpy );
1369 void _kw_ungrab_all( Display *dpy )
1370 {
1371 XUngrabPointer( dpy, CurrentTime );
1372 XUngrabKeyboard( dpy, CurrentTime );
1373 }
1374
1375
1376 static void
1377 Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1378 {
1379 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1380 (void) dpy;
1381 MakeCurrent_PrevContext = 0;
1382 MakeCurrent_PrevDrawable = 0;
1383 MakeCurrent_PrevReadable = 0;
1384 MakeCurrent_PrevDrawBuffer = 0;
1385 MakeCurrent_PrevReadBuffer = 0;
1386 XMesaDestroyContext( glxCtx->xmesaContext );
1387 XMesaGarbageCollect();
1388 }
1389
1390
1391
1392 static Bool
1393 Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1394 {
1395 struct fake_glx_context *glxCtx = (struct fake_glx_context *) ctx;
1396 (void) dpy;
1397 return glxCtx->xmesaContext->direct;
1398 }
1399
1400
1401
1402 static void
1403 Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1404 {
1405 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1406
1407 if (buffer) {
1408 XMesaSwapBuffers(buffer);
1409 }
1410 else if (getenv("MESA_DEBUG")) {
1411 fprintf(stderr, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1412 }
1413 }
1414
1415
1416
1417 /*** GLX_MESA_copy_sub_buffer ***/
1418
1419 static void
1420 Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1421 int x, int y, int width, int height )
1422 {
1423 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1424 if (buffer) {
1425 XMesaCopySubBuffer(buffer, x, y, width, height);
1426 }
1427 else if (getenv("MESA_DEBUG")) {
1428 fprintf(stderr, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1429 }
1430 }
1431
1432
1433
1434 static Bool
1435 Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1436 {
1437 (void) dpy;
1438 /* Return GLX version, not Mesa version */
1439 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1440 *maj = CLIENT_MAJOR_VERSION;
1441 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1442 return True;
1443 }
1444
1445
1446
1447 /*
1448 * Query the GLX attributes of the given XVisualInfo.
1449 */
1450 static int
1451 Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1452 int attrib, int *value )
1453 {
1454 XMesaVisual glxvis;
1455
1456 glxvis = find_glx_visual( dpy, visinfo );
1457 if (!glxvis) {
1458 /* this visual wasn't obtained with glXChooseVisual */
1459 glxvis = create_glx_visual( dpy, visinfo );
1460 if (!glxvis) {
1461 /* this visual can't be used for GL rendering */
1462 if (attrib==GLX_USE_GL) {
1463 *value = (int) False;
1464 return 0;
1465 }
1466 else {
1467 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1468 return GLX_BAD_VISUAL;
1469 }
1470 }
1471 }
1472
1473 switch(attrib) {
1474 case GLX_USE_GL:
1475 *value = (int) True;
1476 return 0;
1477 case GLX_BUFFER_SIZE:
1478 *value = visinfo->depth;
1479 return 0;
1480 case GLX_LEVEL:
1481 *value = glxvis->level;
1482 return 0;
1483 case GLX_RGBA:
1484 if (glxvis->mesa_visual.rgbMode) {
1485 *value = True;
1486 }
1487 else {
1488 *value = False;
1489 }
1490 return 0;
1491 case GLX_DOUBLEBUFFER:
1492 *value = (int) glxvis->mesa_visual.doubleBufferMode;
1493 return 0;
1494 case GLX_STEREO:
1495 *value = (int) glxvis->mesa_visual.stereoMode;
1496 return 0;
1497 case GLX_AUX_BUFFERS:
1498 *value = (int) False;
1499 return 0;
1500 case GLX_RED_SIZE:
1501 *value = glxvis->mesa_visual.redBits;
1502 return 0;
1503 case GLX_GREEN_SIZE:
1504 *value = glxvis->mesa_visual.greenBits;
1505 return 0;
1506 case GLX_BLUE_SIZE:
1507 *value = glxvis->mesa_visual.blueBits;
1508 return 0;
1509 case GLX_ALPHA_SIZE:
1510 *value = glxvis->mesa_visual.alphaBits;
1511 return 0;
1512 case GLX_DEPTH_SIZE:
1513 *value = glxvis->mesa_visual.depthBits;
1514 return 0;
1515 case GLX_STENCIL_SIZE:
1516 *value = glxvis->mesa_visual.stencilBits;
1517 return 0;
1518 case GLX_ACCUM_RED_SIZE:
1519 *value = glxvis->mesa_visual.accumRedBits;
1520 return 0;
1521 case GLX_ACCUM_GREEN_SIZE:
1522 *value = glxvis->mesa_visual.accumGreenBits;
1523 return 0;
1524 case GLX_ACCUM_BLUE_SIZE:
1525 *value = glxvis->mesa_visual.accumBlueBits;
1526 return 0;
1527 case GLX_ACCUM_ALPHA_SIZE:
1528 *value = glxvis->mesa_visual.accumAlphaBits;
1529 return 0;
1530
1531 /*
1532 * GLX_EXT_visual_info extension
1533 */
1534 case GLX_X_VISUAL_TYPE_EXT:
1535 switch (glxvis->visinfo->CLASS) {
1536 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1537 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1538 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1539 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1540 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1541 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1542 }
1543 return 0;
1544 case GLX_TRANSPARENT_TYPE_EXT:
1545 if (glxvis->level==0) {
1546 /* normal planes */
1547 *value = GLX_NONE_EXT;
1548 }
1549 else if (glxvis->level>0) {
1550 /* overlay */
1551 if (glxvis->mesa_visual.rgbMode) {
1552 *value = GLX_TRANSPARENT_RGB_EXT;
1553 }
1554 else {
1555 *value = GLX_TRANSPARENT_INDEX_EXT;
1556 }
1557 }
1558 else if (glxvis->level<0) {
1559 /* underlay */
1560 *value = GLX_NONE_EXT;
1561 }
1562 return 0;
1563 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1564 {
1565 int pixel = transparent_pixel( glxvis );
1566 if (pixel>=0) {
1567 *value = pixel;
1568 }
1569 /* else undefined */
1570 }
1571 return 0;
1572 case GLX_TRANSPARENT_RED_VALUE_EXT:
1573 /* undefined */
1574 return 0;
1575 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1576 /* undefined */
1577 return 0;
1578 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1579 /* undefined */
1580 return 0;
1581 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1582 /* undefined */
1583 return 0;
1584
1585 /*
1586 * GLX_EXT_visual_info extension
1587 */
1588 case GLX_VISUAL_CAVEAT_EXT:
1589 /* test for zero, just in case */
1590 if (glxvis->VisualCaveat > 0)
1591 *value = glxvis->VisualCaveat;
1592 else
1593 *value = GLX_NONE_EXT;
1594 return 0;
1595
1596 /*
1597 * Extensions
1598 */
1599 default:
1600 return GLX_BAD_ATTRIBUTE;
1601 }
1602 }
1603
1604
1605
1606 static void
1607 Fake_glXWaitGL( void )
1608 {
1609 XMesaContext xmesa = XMesaGetCurrentContext();
1610 XMesaFlush( xmesa );
1611 }
1612
1613
1614
1615 static void
1616 Fake_glXWaitX( void )
1617 {
1618 XMesaContext xmesa = XMesaGetCurrentContext();
1619 XMesaFlush( xmesa );
1620 }
1621
1622
1623 /*
1624 * Return the extensions string, which is 3Dfx-dependant.
1625 */
1626 static const char *get_extensions( void )
1627 {
1628 #ifdef FX
1629 const char *fx = getenv("MESA_GLX_FX");
1630 if (fx && fx[0] != 'd') {
1631 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";
1632 }
1633 #endif
1634 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";
1635 }
1636
1637
1638
1639 /* GLX 1.1 and later */
1640 static const char *
1641 Fake_glXQueryExtensionsString( Display *dpy, int screen )
1642 {
1643 (void) dpy;
1644 (void) screen;
1645 return get_extensions();
1646 }
1647
1648
1649
1650 /* GLX 1.1 and later */
1651 static const char *
1652 Fake_glXQueryServerString( Display *dpy, int screen, int name )
1653 {
1654 static char version[1000];
1655 sprintf(version, "%d.%d %s", SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION,
1656 MESA_GLX_VERSION);
1657
1658 (void) dpy;
1659 (void) screen;
1660
1661 switch (name) {
1662 case GLX_EXTENSIONS:
1663 return get_extensions();
1664 case GLX_VENDOR:
1665 return VENDOR;
1666 case GLX_VERSION:
1667 return version;
1668 default:
1669 return NULL;
1670 }
1671 }
1672
1673
1674
1675 /* GLX 1.1 and later */
1676 static const char *
1677 Fake_glXGetClientString( Display *dpy, int name )
1678 {
1679 static char version[1000];
1680 sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, CLIENT_MINOR_VERSION,
1681 MESA_GLX_VERSION);
1682
1683 (void) dpy;
1684
1685 switch (name) {
1686 case GLX_EXTENSIONS:
1687 return get_extensions();
1688 case GLX_VENDOR:
1689 return VENDOR;
1690 case GLX_VERSION:
1691 return version;
1692 default:
1693 return NULL;
1694 }
1695 }
1696
1697
1698
1699 /*
1700 * GLX 1.3 and later
1701 */
1702
1703 /* XXX Move this when done.
1704 * Create an XMesaBuffer as a Pbuffer.
1705 * New in Mesa 4.0 but untested.
1706 */
1707 extern XMesaBuffer XMesaCreatePBuffer( XMesaVisual v, XMesaColormap cmap,
1708 unsigned int width, unsigned int height );
1709
1710
1711
1712 static GLXFBConfig *
1713 Fake_glXChooseFBConfig( Display *dpy, int screen,
1714 const int *attribList, int *nitems )
1715 {
1716 (void) dpy;
1717 (void) screen;
1718 (void) attribList;
1719 (void) nitems;
1720 return 0;
1721 }
1722
1723
1724 static int
1725 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1726 int attribute, int *value )
1727 {
1728 XMesaVisual v = NULL; /* XXX Fix this */
1729 (void) dpy;
1730 (void) config;
1731 (void) attribute;
1732 (void) value;
1733
1734 if (!dpy || !config || !value)
1735 return -1;
1736
1737 switch (attribute) {
1738 case GLX_FBCONFIG_ID:
1739 case GLX_BUFFER_SIZE:
1740 if (v->mesa_visual.rgbMode)
1741 *value = v->mesa_visual.redBits + v->mesa_visual.greenBits +
1742 v->mesa_visual.blueBits + v->mesa_visual.alphaBits;
1743 else
1744 *value = v->mesa_visual.indexBits;
1745 break;
1746 case GLX_LEVEL:
1747 *value = v->level;
1748 break;
1749 case GLX_DOUBLEBUFFER:
1750 *value = v->mesa_visual.doubleBufferMode;
1751 break;
1752 case GLX_STEREO:
1753 *value = v->mesa_visual.stereoMode;
1754 break;
1755 case GLX_AUX_BUFFERS:
1756 *value = v->mesa_visual.numAuxBuffers;
1757 break;
1758 case GLX_RED_SIZE:
1759 *value = v->mesa_visual.redBits;
1760 break;
1761 case GLX_GREEN_SIZE:
1762 *value = v->mesa_visual.greenBits;
1763 break;
1764 case GLX_BLUE_SIZE:
1765 *value = v->mesa_visual.blueBits;
1766 break;
1767 case GLX_ALPHA_SIZE:
1768 *value = v->mesa_visual.alphaBits;
1769 break;
1770 case GLX_DEPTH_SIZE:
1771 *value = v->mesa_visual.depthBits;
1772 break;
1773 case GLX_STENCIL_SIZE:
1774 *value = v->mesa_visual.stencilBits;
1775 break;
1776 case GLX_ACCUM_RED_SIZE:
1777 *value = v->mesa_visual.accumRedBits;
1778 break;
1779 case GLX_ACCUM_GREEN_SIZE:
1780 *value = v->mesa_visual.accumGreenBits;
1781 break;
1782 case GLX_ACCUM_BLUE_SIZE:
1783 *value = v->mesa_visual.accumBlueBits;
1784 break;
1785 case GLX_ACCUM_ALPHA_SIZE:
1786 *value = v->mesa_visual.accumAlphaBits;
1787 break;
1788 case GLX_RENDER_TYPE:
1789 *value = 0; /* XXX ??? */
1790 break;
1791 case GLX_DRAWABLE_TYPE:
1792 *value = GLX_PBUFFER_BIT; /* XXX fix? */
1793 break;
1794 case GLX_X_RENDERABLE:
1795 *value = False; /* XXX ??? */
1796 break;
1797 case GLX_X_VISUAL_TYPE:
1798 switch (v->vishandle->class) {
1799 case GrayScale:
1800 *value = GLX_GRAY_SCALE;
1801 break;
1802 case StaticGray:
1803 *value = GLX_STATIC_GRAY;
1804 break;
1805 case StaticColor:
1806 *value = GLX_STATIC_COLOR;
1807 break;
1808 case PseudoColor:
1809 *value = GLX_PSEUDO_COLOR;
1810 break;
1811 case TrueColor:
1812 *value = GLX_TRUE_COLOR;
1813 break;
1814 case DirectColor:
1815 *value = GLX_DIRECT_COLOR;
1816 break;
1817 default:
1818 *value = 0;
1819 }
1820 break;
1821 case GLX_CONFIG_CAVEAT:
1822 *value = 0; /* XXX ??? */
1823 break;
1824 case GLX_TRANSPARENT_TYPE:
1825 if (v->level == 0) {
1826 /* normal planes */
1827 *value = GLX_NONE_EXT;
1828 }
1829 else if (v->level > 0) {
1830 /* overlay */
1831 if (v->mesa_visual.rgbMode) {
1832 *value = GLX_TRANSPARENT_RGB_EXT;
1833 }
1834 else {
1835 *value = GLX_TRANSPARENT_INDEX_EXT;
1836 }
1837 }
1838 else if (v->level < 0) {
1839 /* underlay */
1840 *value = GLX_NONE_EXT;
1841 }
1842 break;
1843 case GLX_TRANSPARENT_INDEX_VALUE:
1844 *value = transparent_pixel( v );
1845 break;
1846 case GLX_TRANSPARENT_RED_VALUE:
1847 *value = 0; /* not implemented */
1848 break;
1849 case GLX_TRANSPARENT_GREEN_VALUE:
1850 *value = 0; /* not implemented */
1851 break;
1852 case GLX_TRANSPARENT_BLUE_VALUE:
1853 *value = 0; /* not implemented */
1854 break;
1855 case GLX_TRANSPARENT_ALPHA_VALUE:
1856 *value = 0; /* not implemented */
1857 break;
1858 case GLX_MAX_PBUFFER_WIDTH:
1859 *value = DisplayWidth(dpy, v->vishandle->screen);
1860 break;
1861 case GLX_MAX_PBUFFER_HEIGHT:
1862 *value = DisplayHeight(dpy, v->vishandle->screen);
1863 break;
1864 case GLX_MAX_PBUFFER_PIXELS:
1865 *value = DisplayWidth(dpy, v->vishandle->screen) *
1866 DisplayHeight(dpy, v->vishandle->screen);
1867 break;
1868 case GLX_VISUAL_ID:
1869 *value = v->vishandle->visualid;
1870 break;
1871 default:
1872 return GLX_BAD_ATTRIBUTE;
1873 }
1874
1875 return Success;
1876 }
1877
1878
1879 static GLXFBConfig *
1880 Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1881 {
1882 (void) dpy;
1883 (void) screen;
1884 (void) nelements;
1885 return 0;
1886 }
1887
1888
1889 static XVisualInfo *
1890 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1891 {
1892 if (dpy && config) {
1893 XMesaVisual v = (XMesaVisual) config;
1894 return v->vishandle;
1895 }
1896 else {
1897 return NULL;
1898 }
1899 }
1900
1901
1902 static GLXWindow
1903 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1904 const int *attribList )
1905 {
1906 (void) dpy;
1907 (void) config;
1908 (void) win;
1909 (void) attribList; /* Ignored in GLX 1.3 */
1910
1911 return win; /* A hack for now */
1912 }
1913
1914
1915 static void
1916 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1917 {
1918 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1919 if (b)
1920 XMesaDestroyBuffer(b);
1921 /* don't destroy X window */
1922 }
1923
1924
1925 /* XXX untested */
1926 static GLXPixmap
1927 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1928 const int *attribList )
1929 {
1930 XMesaVisual v = (XMesaVisual) config;
1931 XVisualInfo *visinfo;
1932 XMesaBuffer b;
1933
1934 (void) dpy;
1935 (void) config;
1936 (void) pixmap;
1937 (void) attribList; /* Ignored in GLX 1.3 */
1938
1939 if (!dpy || !config || !pixmap)
1940 return 0;
1941
1942 visinfo = v->vishandle;
1943
1944 v = find_glx_visual( dpy, visinfo );
1945 if (!v) {
1946 v = create_glx_visual( dpy, visinfo );
1947 if (!v) {
1948 /* unusable visual */
1949 return 0;
1950 }
1951 }
1952
1953 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1954 if (!b) {
1955 return 0;
1956 }
1957
1958 return pixmap;
1959 }
1960
1961
1962 static void
1963 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1964 {
1965 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
1966 if (b)
1967 XMesaDestroyBuffer(b);
1968 /* don't destroy X pixmap */
1969 }
1970
1971
1972 static GLXPbuffer
1973 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1974 const int *attribList )
1975 {
1976 const int *attrib;
1977 int width = 0, height = 0;
1978 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
1979
1980 (void) dpy;
1981 (void) config;
1982
1983 for (attrib = attribList; attrib; attrib++) {
1984 switch (*attrib) {
1985 case GLX_PBUFFER_WIDTH:
1986 width = *(++attrib);
1987 break;
1988 case GLX_PBUFFER_HEIGHT:
1989 height = *(++attrib);
1990 break;
1991 case GLX_PRESERVED_CONTENTS:
1992 preserveContents = GL_TRUE; /* ignored */
1993 break;
1994 case GLX_LARGEST_PBUFFER:
1995 useLargest = GL_TRUE; /* ignored */
1996 break;
1997 default:
1998 return 0;
1999 }
2000 }
2001
2002 if (width == 0 || height == 0)
2003 return 0;
2004
2005
2006 return 0;
2007 }
2008
2009
2010 static void
2011 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2012 {
2013 (void) dpy;
2014 (void) pbuf;
2015 }
2016
2017
2018 static void
2019 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2020 unsigned int *value )
2021 {
2022 (void) dpy;
2023 (void) draw;
2024
2025 switch (attribute) {
2026 case GLX_WIDTH:
2027 case GLX_HEIGHT:
2028 case GLX_PRESERVED_CONTENTS:
2029 case GLX_LARGEST_PBUFFER:
2030 case GLX_FBCONFIG_ID:
2031 *value = 0;
2032 return;
2033 default:
2034 return; /* GLX_BAD_ATTRIBUTE? */
2035 }
2036 }
2037
2038
2039 static GLXContext
2040 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2041 int renderType, GLXContext shareList, Bool direct )
2042 {
2043 XMesaVisual v = (XMesaVisual) config;
2044
2045 if (!dpy || !config ||
2046 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2047 return 0;
2048
2049 return Fake_glXCreateContext(dpy, v->vishandle, shareList, direct);
2050 }
2051
2052
2053 static int
2054 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2055 {
2056 (void) dpy;
2057 (void) ctx;
2058
2059 switch (attribute) {
2060 case GLX_FBCONFIG_ID:
2061 case GLX_RENDER_TYPE:
2062 case GLX_SCREEN:
2063 *value = 0;
2064 return Success;
2065 default:
2066 return GLX_BAD_ATTRIBUTE;
2067 }
2068 }
2069
2070
2071 static void
2072 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2073 {
2074 (void) dpy;
2075 (void) drawable;
2076 (void) mask;
2077 }
2078
2079
2080 static void
2081 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2082 unsigned long *mask )
2083 {
2084 (void) dpy;
2085 (void) drawable;
2086 (void) mask;
2087 }
2088
2089
2090
2091 /*** GLX_SGI_swap_control ***/
2092
2093 static int
2094 Fake_glXSwapIntervalSGI(int interval)
2095 {
2096 (void) interval;
2097 return 0;
2098 }
2099
2100
2101
2102 /*** GLX_SGI_video_sync ***/
2103
2104 static int
2105 Fake_glXGetVideoSyncSGI(unsigned int *count)
2106 {
2107 (void) count;
2108 return 0;
2109 }
2110
2111 static int
2112 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2113 {
2114 (void) divisor;
2115 (void) remainder;
2116 (void) count;
2117 return 0;
2118 }
2119
2120
2121
2122 /*** GLX_SGI_make_current_read ***/
2123
2124 static Bool
2125 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2126 {
2127 (void) dpy;
2128 (void) draw;
2129 (void) read;
2130 (void) ctx;
2131 return False;
2132 }
2133
2134 /* not used
2135 static GLXDrawable
2136 Fake_glXGetCurrentReadDrawableSGI(void)
2137 {
2138 return 0;
2139 }
2140 */
2141
2142
2143 /*** GLX_SGIX_video_source ***/
2144 #if defined(_VL_H)
2145
2146 static GLXVideoSourceSGIX
2147 Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2148 {
2149 (void) dpy;
2150 (void) screen;
2151 (void) server;
2152 (void) path;
2153 (void) nodeClass;
2154 (void) drainNode;
2155 return 0;
2156 }
2157
2158 static void
2159 Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2160 {
2161 (void) dpy;
2162 (void) src;
2163 }
2164
2165 #endif
2166
2167
2168 /*** GLX_EXT_import_context ***/
2169
2170 static void
2171 Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2172 {
2173 (void) dpy;
2174 (void) context;
2175 }
2176
2177 static GLXContextID
2178 Fake_glXGetContextIDEXT(const GLXContext context)
2179 {
2180 (void) context;
2181 return 0;
2182 }
2183
2184 static GLXContext
2185 Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2186 {
2187 (void) dpy;
2188 (void) contextID;
2189 return 0;
2190 }
2191
2192 static int
2193 Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2194 {
2195 (void) dpy;
2196 (void) context;
2197 (void) attribute;
2198 (void) value;
2199 return 0;
2200 }
2201
2202
2203
2204 /*** GLX_SGIX_fbconfig ***/
2205
2206 static int
2207 Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2208 {
2209 (void) dpy;
2210 (void) config;
2211 (void) attribute;
2212 (void) value;
2213 return 0;
2214 }
2215
2216 static GLXFBConfigSGIX *
2217 Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2218 {
2219 (void) dpy;
2220 (void) screen;
2221 (void) attrib_list;
2222 (void) nelements;
2223 return 0;
2224 }
2225
2226 static GLXPixmap
2227 Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2228 {
2229 (void) dpy;
2230 (void) config;
2231 (void) pixmap;
2232 return 0;
2233 }
2234
2235 static GLXContext
2236 Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2237 {
2238 (void) dpy;
2239 (void) config;
2240 (void) render_type;
2241 (void) share_list;
2242 (void) direct;
2243 return 0;
2244 }
2245
2246 static XVisualInfo *
2247 Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2248 {
2249 (void) dpy;
2250 (void) config;
2251 return NULL;
2252 }
2253
2254 static GLXFBConfigSGIX
2255 Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2256 {
2257 (void) dpy;
2258 (void) vis;
2259 return 0;
2260 }
2261
2262
2263
2264 /*** GLX_SGIX_pbuffer ***/
2265
2266 static GLXPbufferSGIX
2267 Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list)
2268 {
2269 (void) dpy;
2270 (void) config;
2271 (void) width;
2272 (void) height;
2273 (void) attrib_list;
2274 return 0;
2275 }
2276
2277 static void
2278 Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2279 {
2280 (void) dpy;
2281 (void) pbuf;
2282 }
2283
2284 static int
2285 Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2286 {
2287 (void) dpy;
2288 (void) pbuf;
2289 (void) attribute;
2290 (void) value;
2291 return 0;
2292 }
2293
2294 static void
2295 Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2296 {
2297 (void) dpy;
2298 (void) drawable;
2299 (void) mask;
2300 }
2301
2302 static void
2303 Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2304 {
2305 (void) dpy;
2306 (void) drawable;
2307 (void) mask;
2308 }
2309
2310
2311
2312 /*** GLX_SGI_cushion ***/
2313
2314 static void
2315 Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2316 {
2317 (void) dpy;
2318 (void) win;
2319 (void) cushion;
2320 }
2321
2322
2323
2324 /*** GLX_SGIX_video_resize ***/
2325
2326 static int
2327 Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2328 {
2329 (void) dpy;
2330 (void) screen;
2331 (void) channel;
2332 (void) window;
2333 return 0;
2334 }
2335
2336 static int
2337 Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2338 {
2339 (void) dpy;
2340 (void) screen;
2341 (void) channel;
2342 (void) x;
2343 (void) y;
2344 (void) w;
2345 (void) h;
2346 return 0;
2347 }
2348
2349 static int
2350 Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2351 {
2352 (void) dpy;
2353 (void) screen;
2354 (void) channel;
2355 (void) x;
2356 (void) y;
2357 (void) w;
2358 (void) h;
2359 return 0;
2360 }
2361
2362 static int
2363 Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2364 {
2365 (void) dpy;
2366 (void) screen;
2367 (void) channel;
2368 (void) dx;
2369 (void) dy;
2370 (void) dw;
2371 (void) dh;
2372 return 0;
2373 }
2374
2375 static int
2376 Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2377 {
2378 (void) dpy;
2379 (void) screen;
2380 (void) channel;
2381 (void) synctype;
2382 return 0;
2383 }
2384
2385
2386
2387 /*** GLX_SGIX_dmbuffer **/
2388
2389 #if defined(_DM_BUFFER_H_)
2390 static Bool
2391 Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2392 {
2393 (void) dpy;
2394 (void) pbuffer;
2395 (void) params;
2396 (void) dmbuffer;
2397 return False;
2398 }
2399 #endif
2400
2401
2402 /*** GLX_SGIX_swap_group ***/
2403
2404 static void
2405 Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2406 {
2407 (void) dpy;
2408 (void) drawable;
2409 (void) member;
2410 }
2411
2412
2413
2414 /*** GLX_SGIX_swap_barrier ***/
2415
2416 static void
2417 Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2418 {
2419 (void) dpy;
2420 (void) drawable;
2421 (void) barrier;
2422 }
2423
2424 static Bool
2425 Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2426 {
2427 (void) dpy;
2428 (void) screen;
2429 (void) max;
2430 return False;
2431 }
2432
2433
2434
2435 /*** GLX_SUN_get_transparent_index ***/
2436
2437 static Status
2438 Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2439 {
2440 (void) dpy;
2441 (void) overlay;
2442 (void) underlay;
2443 (void) pTransparent;
2444 return 0;
2445 }
2446
2447
2448
2449 /*** GLX_MESA_release_buffers ***/
2450
2451 /*
2452 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2453 * (a window or pixmap) prior to destroying the GLXDrawable.
2454 */
2455 static Bool
2456 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2457 {
2458 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2459 if (b) {
2460 XMesaDestroyBuffer(b);
2461 return True;
2462 }
2463 return False;
2464 }
2465
2466
2467
2468 /*** GLX_MESA_set_3dfx_mode ***/
2469
2470 static Bool
2471 Fake_glXSet3DfxModeMESA( int mode )
2472 {
2473 return XMesaSetFXmode( mode );
2474 }
2475
2476
2477
2478
2479 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
2480 struct _glxapi_table *_mesa_GetGLXDispatchTable(void)
2481 {
2482 static struct _glxapi_table glx;
2483
2484 /* be sure our dispatch table size <= libGL's table */
2485 {
2486 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
2487 (void) size;
2488 assert(_glxapi_get_dispatch_table_size() >= size);
2489 }
2490
2491 /* initialize the whole table to no-ops */
2492 _glxapi_set_no_op_table(&glx);
2493
2494 /* now initialize the table with the functions I implement */
2495 glx.ChooseVisual = Fake_glXChooseVisual;
2496 glx.CopyContext = Fake_glXCopyContext;
2497 glx.CreateContext = Fake_glXCreateContext;
2498 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2499 glx.DestroyContext = Fake_glXDestroyContext;
2500 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2501 glx.GetConfig = Fake_glXGetConfig;
2502 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2503 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2504 glx.IsDirect = Fake_glXIsDirect;
2505 glx.MakeCurrent = Fake_glXMakeCurrent;
2506 glx.QueryExtension = Fake_glXQueryExtension;
2507 glx.QueryVersion = Fake_glXQueryVersion;
2508 glx.SwapBuffers = Fake_glXSwapBuffers;
2509 glx.UseXFont = Fake_glXUseXFont;
2510 glx.WaitGL = Fake_glXWaitGL;
2511 glx.WaitX = Fake_glXWaitX;
2512
2513 /*** GLX_VERSION_1_1 ***/
2514 glx.GetClientString = Fake_glXGetClientString;
2515 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2516 glx.QueryServerString = Fake_glXQueryServerString;
2517
2518 /*** GLX_VERSION_1_2 ***/
2519 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2520
2521 /*** GLX_VERSION_1_3 ***/
2522 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2523 glx.CreateNewContext = Fake_glXCreateNewContext;
2524 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2525 glx.CreatePixmap = Fake_glXCreatePixmap;
2526 glx.CreateWindow = Fake_glXCreateWindow;
2527 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2528 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2529 glx.DestroyWindow = Fake_glXDestroyWindow;
2530 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2531 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
2532 glx.GetFBConfigs = Fake_glXGetFBConfigs;
2533 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2534 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2535 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2536 glx.QueryContext = Fake_glXQueryContext;
2537 glx.QueryDrawable = Fake_glXQueryDrawable;
2538 glx.SelectEvent = Fake_glXSelectEvent;
2539
2540 /*** GLX_SGI_swap_control ***/
2541 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
2542
2543 /*** GLX_SGI_video_sync ***/
2544 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2545 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
2546
2547 /*** GLX_SGI_make_current_read ***/
2548 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
2549 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2550
2551 /*** GLX_SGIX_video_source ***/
2552 #if defined(_VL_H)
2553 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2554 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2555 #endif
2556
2557 /*** GLX_EXT_import_context ***/
2558 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2559 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
2560 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2561 glx.ImportContextEXT = Fake_glXImportContextEXT;
2562 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
2563
2564 /*** GLX_SGIX_fbconfig ***/
2565 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2566 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2567 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2568 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2569 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2570 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
2571
2572 /*** GLX_SGIX_pbuffer ***/
2573 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2574 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2575 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2576 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2577 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
2578
2579 /*** GLX_SGI_cushion ***/
2580 glx.CushionSGI = Fake_glXCushionSGI;
2581
2582 /*** GLX_SGIX_video_resize ***/
2583 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2584 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2585 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2586 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2587 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
2588
2589 /*** GLX_SGIX_dmbuffer **/
2590 #if defined(_DM_BUFFER_H_)
2591 glx.AssociateDMPbufferSGIX = NULL;
2592 #endif
2593
2594 /*** GLX_SGIX_swap_group ***/
2595 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
2596
2597 /*** GLX_SGIX_swap_barrier ***/
2598 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2599 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
2600
2601 /*** GLX_SUN_get_transparent_index ***/
2602 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
2603
2604 /*** GLX_MESA_copy_sub_buffer ***/
2605 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
2606
2607 /*** GLX_MESA_release_buffers ***/
2608 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
2609
2610 /*** GLX_MESA_pixmap_colormap ***/
2611 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
2612
2613 /*** GLX_MESA_set_3dfx_mode ***/
2614 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
2615
2616 return &glx;
2617 }