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