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