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